From 9ad6c954cbe80c295100d2ed4672697cedbb3a3b Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Thu, 22 Feb 2024 09:57:52 +0100 Subject: [PATCH] virtme-ng-init: handle command line option nr_open Handle kernel boot option `nr_open`, used to set the maximum amount of open files (/proc/sys/fs/nr_open) in the virtme-ng guest. Signed-off-by: Andrea Righi --- src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.rs b/src/main.rs index 0942178..9bb6b63 100644 --- a/src/main.rs +++ b/src/main.rs @@ -265,6 +265,14 @@ fn get_active_console() -> Option { } } +fn configure_limits() { + if let Ok(nr_open) = env::var("nr_open") { + if let Ok(mut file) = OpenOptions::new().write(true).open("/proc/sys/fs/nr_open") { + file.write_all(nr_open.as_bytes()).expect("Failed to write nr_open"); + } + } +} + fn configure_hostname() { if let Ok(hostname) = env::var("virtme_hostname") { if let Err(err) = sethostname(hostname) { @@ -966,6 +974,7 @@ fn main() { // Basic system initialization (order is important here). configure_environment(); + configure_limits(); configure_hostname(); mount_kernel_filesystems(); mount_virtme_overlays();