From a5749a5d8d38b0db2ce5548473f8a61b674578a6 Mon Sep 17 00:00:00 2001 From: namilsk Date: Sat, 31 Jan 2026 21:26:26 +0300 Subject: Started writing service-utils and adding docstrings --- init/src/signals/sigchld.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'init/src/signals') diff --git a/init/src/signals/sigchld.rs b/init/src/signals/sigchld.rs index a02b82f..79a40c9 100644 --- a/init/src/signals/sigchld.rs +++ b/init/src/signals/sigchld.rs @@ -1,14 +1,12 @@ -use libc::{c_int, sigaction, siginfo_t, sigset_t, waitpid, SA_RESTART, SA_SIGINFO, SIGCHLD, WNOHANG}; +use libc::{ + SA_RESTART, SA_SIGINFO, SIGCHLD, WNOHANG, c_int, sigaction, siginfo_t, sigset_t, waitpid, +}; use std::os::raw::c_void; -// extern "C" because: +// extern "C" because: // https://doc.rust-lang.org/reference/items/external-blocks.html?spm=a2ty_o01.29997173.0.0.63e251718NCvPc#abi // Doc comments needed... -extern "C" fn sigchld_handler( - _signal: c_int, - _info: *mut siginfo_t, - _context: *mut c_void, -) { +extern "C" fn sigchld_handler(_signal: c_int, _info: *mut siginfo_t, _context: *mut c_void) { let saved_errno = unsafe { *libc::__errno_location() }; loop { @@ -16,16 +14,14 @@ extern "C" fn sigchld_handler( let pid = unsafe { waitpid(-1, &mut status as *mut c_int, WNOHANG) }; match pid { - 0 => break, + 0 => break, -1 => { let errno = unsafe { *libc::__errno_location() }; if errno == libc::ECHILD { break; } } - _ => { - /* If it doesnt work, ill add the logging here */ - } + _ => { /* If it doesnt work, ill add the logging here */ } } } @@ -35,10 +31,10 @@ extern "C" fn sigchld_handler( pub fn setup_sigchld_handler() -> Result<(), Box> { unsafe { let mut sigact: sigaction = std::mem::zeroed(); - + sigact.sa_sigaction = sigchld_handler as usize; sigact.sa_flags = SA_RESTART | SA_SIGINFO; - + libc::sigemptyset(&mut sigact.sa_mask as *mut sigset_t); libc::sigaddset(&mut sigact.sa_mask as *mut sigset_t, SIGCHLD); -- cgit v1.2.3