summaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
Diffstat (limited to 'init')
-rw-r--r--init/Cargo.toml1
-rw-r--r--init/src/main.rs5
-rw-r--r--init/src/processes/getty.rs0
-rw-r--r--init/src/signals/mod.rs1
-rw-r--r--init/src/signals/sigchld.rs24
5 files changed, 29 insertions, 2 deletions
diff --git a/init/Cargo.toml b/init/Cargo.toml
index 9ff5782..d68c550 100644
--- a/init/Cargo.toml
+++ b/init/Cargo.toml
@@ -7,3 +7,4 @@ description = "Lightweight and stable init system for Anthrill distro based on u
[dependencies]
libc = "0.2.178"
liblmod = "0.2.0"
+toml = { version = "0.9.11", features = ["display", "std"], default-features = false }
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(())
+ }
+ }
+}