diff options
Diffstat (limited to 'init/src')
| -rw-r--r-- | init/src/processes/getty.rs | 0 | ||||
| -rw-r--r-- | init/src/services/units.rs | 13 | ||||
| -rw-r--r-- | init/src/signals/sigterm.rs | 4 |
3 files changed, 13 insertions, 4 deletions
diff --git a/init/src/processes/getty.rs b/init/src/processes/getty.rs deleted file mode 100644 index e69de29..0000000 --- a/init/src/processes/getty.rs +++ /dev/null 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<dyn std::error::Error + Send>> { 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<dyn std::error::Error + Send>> { *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<dyn std::error::Error>> { 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<dyn std::error::Error>> { pub fn graceful_shutdown() -> Result<(), Box<dyn std::error::Error>> { log_warning("Graceful shutdown initiated..."); + // Stop all services first + let _ = stop_all_services(); + // Reap all remaining children loop { let mut status: c_int = 0; |
