diff options
| author | namilsk <namilsk@namilsk.tech> | 2026-01-11 14:56:17 +0300 |
|---|---|---|
| committer | namilsk <namilsk@namilsk.tech> | 2026-01-11 14:56:17 +0300 |
| commit | 19e63dfa191279d3e1bd99bcc2adca781ad9451d (patch) | |
| tree | 559fef20998fa7058d6aa02bddc3ee79cbb58708 /init/src | |
| parent | 821380613075ac91410644cb9fed900ab6a1df61 (diff) | |
Implemented `SIGCHLD` & again fixed naming
Diffstat (limited to 'init/src')
| -rw-r--r-- | init/src/main.rs | 5 | ||||
| -rw-r--r-- | init/src/processes/getty.rs | 0 | ||||
| -rw-r--r-- | init/src/signals/mod.rs | 1 | ||||
| -rw-r--r-- | init/src/signals/sigchld.rs | 24 |
4 files changed, 28 insertions, 2 deletions
diff --git a/init/src/main.rs b/init/src/main.rs index 7a77e31..630787e 100644 --- a/init/src/main.rs +++ b/init/src/main.rs @@ -4,6 +4,7 @@ mod log; mod mounts; mod pid_one; mod processes; +mod signals; use crate::host::locale; use crate::host::set::set_hostname; @@ -13,6 +14,7 @@ use crate::mounts::fstab::FstabEntry; use crate::mounts::rescue; use crate::pid_one::check_pid; use crate::processes::udev::spawn_udev; +use crate::signals::sigchld; // RULE: I will not use .expect() and .unwrap() in this project. This causes panic, // which will affect stability. @@ -60,10 +62,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { Err(e) => log_critical_error(&format!("Something went wrong while spawning udev: {}", e)), } + // TODO: Locale & tz parsing match locale::set_system_localization(None, None) { Ok(_) => log_success("Localization (timezone and locale) set successfully."), Err(e) => log_warning(&format!("Failed to set localization: {}", e)), } + sigchld::setup_sigchild_handler(); + Ok(()) } diff --git a/init/src/processes/getty.rs b/init/src/processes/getty.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/init/src/processes/getty.rs diff --git a/init/src/signals/mod.rs b/init/src/signals/mod.rs new file mode 100644 index 0000000..0e86476 --- /dev/null +++ b/init/src/signals/mod.rs @@ -0,0 +1 @@ +pub mod sigchld; diff --git a/init/src/signals/sigchld.rs b/init/src/signals/sigchld.rs index 78b72d4..185e56e 100644 --- a/init/src/signals/sigchld.rs +++ b/init/src/signals/sigchld.rs @@ -1,10 +1,17 @@ -use libc::{signal, sighandler_t, SIGCHILD, SIG_DFL, SIG_IGN}; +use libc::{pid_t, + SIGCHLD, + waitpid, + WNOHANG, + sigaction, + sigemptyset, + SA_RESTART}; + use std::ffi::c_int; fn sigchild_handler(_signal: c_int) { loop { let mut status: c_int = 0; - ket pid: pid_t = unsafe { + let pid: pid_t = unsafe { waitpid(-1 , &mut status, WNOHANG) }; @@ -15,4 +22,17 @@ fn sigchild_handler(_signal: c_int) { } +pub fn sigchild_handler() -> Result<(), Box<dyn std::error::Error>> { + unsafe { + let mut sigact: sigaction = std::mem::zeroed(); + sigact.sa_sigaction = sigchild_handler as usize; + sigemptyset(&mut sigact.sa_mask); + sigact.sa_flags = SA_RESTART; + if sigaction(SIGCHLD, &sigact, std::ptr::null_mut()) == -1 { + Err("Sigaction check returned -1".into()) + } else { + Ok(()) + } + } +} |
