From bca3ae435452b22a08eb66b7d3ab98d840a87b94 Mon Sep 17 00:00:00 2001 From: namilsk Date: Fri, 9 Jan 2026 19:13:16 +0300 Subject: Implemetned kernel modules, locales and timezones settings. --- init/src/host/sethn.rs | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 init/src/host/sethn.rs (limited to 'init/src/host/sethn.rs') diff --git a/init/src/host/sethn.rs b/init/src/host/sethn.rs deleted file mode 100644 index 1857297..0000000 --- a/init/src/host/sethn.rs +++ /dev/null @@ -1,37 +0,0 @@ -use std::{ffi::CString, fs, io}; -use libc::{sethostname, c_char, size_t}; -use crate::log::{log_warning}; - -pub fn try_set_hostname() { - let content = fs::read_to_string("/etc/hostname") - .map(|s| s.trim().to_string()) - .unwrap_or_else(|_| "localhost".to_string()); - - if let Err(e) = perform_set_hostname(&content) { - log_warning(&format!("Failed to set hostname to '{}': {}. Falling back to localhost.", content, e)); - let _ = perform_set_hostname("localhost"); - } -} - -fn perform_set_hostname(name: &str) -> io::Result<()> { - if name.len() > 64 { - return Err(io::Error::new(io::ErrorKind::InvalidInput, "Hostname too long")); - } - - let c_str = CString::new(name).map_err(|_| { - io::Error::new(io::ErrorKind::InvalidInput, "Hostname contains null byte") - })?; - - let res = unsafe { - sethostname( - c_str.as_ptr() as *const c_char, - name.len() as size_t, - ) - }; - - if res != 0 { - return Err(io::Error::last_os_error()); - } - - Ok(()) -} \ No newline at end of file -- cgit v1.2.3