Init: Graceful termination and signal propagation #29
No reviewers
Labels
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
geomind_code/my_hypervisor!29
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "development_signals"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
related issue: #8
Changes implemented:
Re-entrancy guard on
poweroffAdded AtomicBool flag. The first thread to call poweroff() claims it. Any subsequent callers loop on pause() forever, preventing concurrent shutdown races on unmounts and the reboot syscall.
Child process termination before unmounting
Added
terminate_all_children()which runs before sync() and unmounts:This ensures all file handles on mounts are released before umount runs
@ -25,1 +31,4 @@/// Non-blocking reap of all zombie children.fn reap_all_children() {loop {i think this is normal blocking function can u update the comment because it's kinda confusing
it is non-blocking due to the
WNOHANGflag, the loop keeps reaping any exited children and breaks as soon as there are none left to collect, so the function never stalls waiting for a child that's still runningI meant that u should wait for the function to return or to break
@ -26,0 +41,4 @@}Ok(WaitStatus::StillAlive) | Err(_) => break,_ => continue,}why we are breaking on still alive shouldn't we continue?
Still alive means there's no more zombies to collect right now. All living children are still running so we should break(no reaping work to do)
actually this is an infinite loop, so we should break somewhere to avoid running forever
@ -26,0 +59,4 @@while Instant::now() < deadline {reap_all_children();if no_children_left() {return;why we still need this check? already reap all children match on waitpid and returns so the status of children can be known from it i think no_children_left is just redundant
we can adjust reap all children to return bool and remove no_children_left
@ -26,0 +66,4 @@println!("[init] Sending SIGKILL to remaining child processes...");let _ = nix::sys::signal::kill(Pid::from_raw(-1), Signal::SIGKILL);this signal all process does it exclude the calling process itself?
yes, kill with pid -1 is sent to every process for which the calling process has permission to send signals, except for process 1 (init), which is the calling process
see kill(2) man page
man 2 kill@ -26,0 +74,4 @@return;}std::thread::sleep(Duration::from_millis(50));}this part is duplicated we can extract it into helper function with setting delay needed
can u please fix conflicts