summaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authornamilsk <namilsk@namilsk.tech>2026-03-07 00:14:24 +0300
committernamilsk <namilsk@namilsk.tech>2026-03-07 00:14:24 +0300
commit3b3bcf1306857e0607010d657a1c9cc0b846d977 (patch)
treed0b9e3f9b506dbe9f87c6fb3e7acb533ea69901d /init
parent772093279e1dd162a47e2dfe50d9a9ae0192d750 (diff)
Autofmt, updated `TODO.md`
Diffstat (limited to 'init')
-rw-r--r--init/src/host/locale.rs1
-rw-r--r--init/src/log.rs5
-rw-r--r--init/src/main.rs10
-rw-r--r--init/src/services/units.rs5
-rw-r--r--init/src/signals/sigterm.rs6
5 files changed, 12 insertions, 15 deletions
diff --git a/init/src/host/locale.rs b/init/src/host/locale.rs
index a440792..2af07f4 100644
--- a/init/src/host/locale.rs
+++ b/init/src/host/locale.rs
@@ -2,7 +2,6 @@
// Main logic implemented but how i think it can contain with broken logic or checks
// At least if check failed it set C.UTF8 (fallback locale)
-
use crate::host::timezone::set_timezone;
use crate::log::{log_success, log_warning};
use std::fs;
diff --git a/init/src/log.rs b/init/src/log.rs
index 207394b..c5e2ff2 100644
--- a/init/src/log.rs
+++ b/init/src/log.rs
@@ -6,13 +6,12 @@ const LOG_FILE_PATH: &str = "/var/log/vigil.log";
static LOG_FILE: Mutex<Option<std::fs::File>> = Mutex::new(None);
-/// Инициализирует файл логирования. Должен вызываться один раз при старте.
pub fn init_logging() -> Result<(), Box<dyn std::error::Error>> {
let file = OpenOptions::new()
.create(true)
.append(true)
.open(LOG_FILE_PATH)?;
-
+
let mut guard = LOG_FILE.lock().map_err(|e| e.to_string())?;
*guard = Some(file);
Ok(())
@@ -23,7 +22,7 @@ fn write_to_log(message: &str) {
Ok(g) => g,
Err(poisoned) => poisoned.into_inner(),
};
-
+
if let Some(ref mut file) = *guard {
let _ = writeln!(file, "{}", message);
let _ = file.flush();
diff --git a/init/src/main.rs b/init/src/main.rs
index a3492d1..a783600 100644
--- a/init/src/main.rs
+++ b/init/src/main.rs
@@ -17,7 +17,7 @@ use crate::pid_one::check_pid;
use crate::processes::udev::spawn_udev;
use crate::services::units::{Runlevel, services_mainloop};
use crate::signals::sigchld;
-use crate::signals::sigterm::{self, RELOAD_REQUESTED, DEBUG_DUMP_REQUESTED};
+use crate::signals::sigterm::{self, DEBUG_DUMP_REQUESTED, RELOAD_REQUESTED};
// RULE: I will not use .expect() and .unwrap() in this project. This causes panic,
// which will affect stability.
@@ -88,7 +88,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
thread::spawn(services_mainloop);
log_success("System initialization complete. Entering main loop.");
-
+
loop {
if sigterm::SHUTDOWN_REQUESTED.load(std::sync::atomic::Ordering::SeqCst) {
log_warning("Shutdown signal received.");
@@ -98,17 +98,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
if RELOAD_REQUESTED.swap(false, std::sync::atomic::Ordering::SeqCst) {
log_warning("SIGUSR1 received - config reload requested (not implemented yet).");
- // TODO: Configs reload
+ // TODO: Configs reload
}
// SIGUSR2 (debug dump)
if DEBUG_DUMP_REQUESTED.swap(false, std::sync::atomic::Ordering::SeqCst) {
log_warning("SIGUSR2 received - debug dump requested (not implemented yet).");
- // TODO: debug dump
+ // TODO: debug dump
}
// Sleep to not disturb CPU
- // TODO: io_uring / epolls
+ // TODO: io_uring / epolls
thread::sleep(Duration::from_secs(1));
}
}
diff --git a/init/src/services/units.rs b/init/src/services/units.rs
index 316a15e..2497668 100644
--- a/init/src/services/units.rs
+++ b/init/src/services/units.rs
@@ -10,7 +10,7 @@
// or logs in such init systems are just taking the stdout+stderr
// of service and showing its output? idk 4 now, look into how its supposed to be
-use crate::{log_success, log_warning, RUNLEVEL_STATE};
+use crate::{RUNLEVEL_STATE, log_success, log_warning};
use serde::Deserialize;
use std::{
fs::{read_dir, read_to_string},
@@ -213,11 +213,10 @@ pub fn services_mainloop() -> Result<(), Box<dyn std::error::Error + Send>> {
}
}
} else {
-
false
}
}
- Ok(None) => true,
+ Ok(None) => true,
Err(e) => {
log_warning(&format!("Failed to check status of {}: {}", exec, e));
false
diff --git a/init/src/signals/sigterm.rs b/init/src/signals/sigterm.rs
index 0cf65ee..97a3da7 100644
--- a/init/src/signals/sigterm.rs
+++ b/init/src/signals/sigterm.rs
@@ -1,13 +1,13 @@
use crate::log::log_warning;
use libc::{
- SA_RESTART, SA_SIGINFO, SIGINT, SIGUSR1, SIGUSR2, SIGTERM, WNOHANG, c_int, sigaction, siginfo_t,
- sigset_t, waitpid,
+ SA_RESTART, SA_SIGINFO, SIGINT, SIGTERM, SIGUSR1, SIGUSR2, WNOHANG, c_int, sigaction,
+ siginfo_t, sigset_t, waitpid,
};
use std::os::raw::c_void;
use std::sync::atomic::{AtomicBool, Ordering};
-// Shutdown handler
+// Shutdown handler
pub static SHUTDOWN_REQUESTED: AtomicBool = AtomicBool::new(false);
/// reload config (SIGUSR1)