From 91a7400ad2c3b1edf63116ed9d05619b9bccf9b8 Mon Sep 17 00:00:00 2001 From: namilsk Date: Mon, 23 Mar 2026 23:36:10 +0300 Subject: Fmt & fixed compile error --- init/src/processes/getty.rs | 0 init/src/services/units.rs | 13 +++++++++---- init/src/signals/sigterm.rs | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) delete mode 100644 init/src/processes/getty.rs diff --git a/init/src/processes/getty.rs b/init/src/processes/getty.rs deleted file mode 100644 index e69de29..0000000 diff --git a/init/src/services/units.rs b/init/src/services/units.rs index ec0098b..a4e65ca 100644 --- a/init/src/services/units.rs +++ b/init/src/services/units.rs @@ -11,7 +11,7 @@ // of service and showing its output? idk 4 now, look into how its supposed to be use crate::{RUNLEVEL_STATE, log_success, log_warning}; -use libc::{kill, SIGKILL, SIGTERM}; +use libc::{SIGKILL, SIGTERM, kill}; use serde::Deserialize; use std::{ fs::{read_dir, read_to_string}, @@ -191,7 +191,10 @@ pub fn services_mainloop() -> Result<(), Box> { match child.try_wait() { Ok(Some(status)) => { let pid = child.id(); - log_warning(&format!("Service exited: {} (PID: {}, status: {:?})", exec, pid, status)); + log_warning(&format!( + "Service exited: {} (PID: {}, status: {:?})", + exec, pid, status + )); // Remove from global PID list if let Ok(mut guard) = SERVICE_PIDS.lock() { @@ -220,7 +223,9 @@ pub fn services_mainloop() -> Result<(), Box> { *restart_count += 1; // Update PID in global list if let Ok(mut guard) = SERVICE_PIDS.lock() { - if let Some(pos) = guard.iter().position(|(p, e)| *p == pid && e == exec) { + if let Some(pos) = + guard.iter().position(|(p, e)| *p == pid && e == exec) + { guard[pos] = (new_pid, exec.clone()); } } @@ -349,7 +354,7 @@ pub fn stop_all_services() -> Result<(), Box> { if unsafe { kill(*pid as i32, 0) } == 0 { all_dead = false; break; - ` } + } } if all_dead { break; diff --git a/init/src/signals/sigterm.rs b/init/src/signals/sigterm.rs index 97a3da7..cc59491 100644 --- a/init/src/signals/sigterm.rs +++ b/init/src/signals/sigterm.rs @@ -1,4 +1,5 @@ use crate::log::log_warning; +use crate::services::units::stop_all_services; use libc::{ SA_RESTART, SA_SIGINFO, SIGINT, SIGTERM, SIGUSR1, SIGUSR2, WNOHANG, c_int, sigaction, @@ -89,6 +90,9 @@ pub fn setup_signal_handlers() -> Result<(), Box> { pub fn graceful_shutdown() -> Result<(), Box> { log_warning("Graceful shutdown initiated..."); + // Stop all services first + let _ = stop_all_services(); + // Reap all remaining children loop { let mut status: c_int = 0; -- cgit v1.2.3