Fix sigchld test.

This commit is contained in:
4lDO2
2024-07-18 19:38:47 +02:00
parent 05bde858f9
commit 29170ccbc7
3 changed files with 24 additions and 15 deletions
+6 -3
View File
@@ -213,6 +213,11 @@ impl KernelScheme for PipeScheme {
loop {
let mut vec = pipe.queue.lock();
if !pipe.reader_is_alive.load(Ordering::Relaxed) {
return Err(Error::new(EPIPE));
}
let bytes_left = MAX_QUEUE_SIZE.saturating_sub(vec.len());
let bytes_to_write = core::cmp::min(bytes_left, user_buf.len());
let src_buf = user_buf
@@ -244,9 +249,7 @@ impl KernelScheme for PipeScheme {
return Ok(0);
}
if !pipe.reader_is_alive.load(Ordering::SeqCst) {
return Err(Error::new(EPIPE));
} else if fcntl_flags & O_NONBLOCK as u32 != 0 {
if fcntl_flags & O_NONBLOCK as u32 != 0 {
return Err(Error::new(EAGAIN));
} else if !pipe.write_condition.wait(vec, "PipeWrite::write") {
return Err(Error::new(EINTR));
+16 -12
View File
@@ -91,7 +91,9 @@ pub fn exit(status: usize) -> ! {
let process = current_process.read();
(process.pgid, process.ppid)
};
let _ = kill(ppid, SIGCHLD);
if let Some(parent) = process::PROCESSES.read().get(&ppid).map(Arc::clone) {
let _ = send_signal(KillTarget::Process(parent), SIGCHLD, true, &mut false);
}
// Transfer child processes to parent (TODO: to init)
{
@@ -365,19 +367,21 @@ pub fn send_signal(
send_signal(KillTarget::Process(parent), SIGCHLD, true, killed_self)?;
}
Sent::SucceededSigcont { ppid, pgid } => {
process::PROCESSES
let parent = process::PROCESSES
.read()
.get(&ppid)
.ok_or(Error::new(ESRCH))?
.read()
.waitpid
.send(
WaitpidKey {
pid: Some(proc_info.pid),
pgid: Some(pgid),
},
(proc_info.pid, 0xffff),
);
.map(Arc::clone)
.ok_or(Error::new(ESRCH))?;
let waitpid = Arc::clone(&parent.read().waitpid);
waitpid.send(
WaitpidKey {
pid: Some(proc_info.pid),
pgid: Some(pgid),
},
(proc_info.pid, 0xffff),
);
// POSIX XSI allows but does not require SIGCONT to send signals to the parent.
//send_signal(KillTarget::Process(parent), SIGCHLD, true, killed_self)?;
}
}
+2
View File
@@ -74,5 +74,7 @@ pub fn nanosleep(req_buf: UserSliceRo, rem_buf_opt: Option<UserSliceWo>) -> Resu
pub fn sched_yield() -> Result<()> {
context::switch();
// TODO: Do this check in userspace
context::signal::signal_handler();
Ok(())
}