Skip to content
Snippets Groups Projects
Verified Commit b64b0ebe authored by Jacob Lorentzon's avatar Jacob Lorentzon
Browse files

Handle kill and killpg EINTR.

parent 78247c85
No related branches found
No related tags found
No related merge requests found
...@@ -3,11 +3,10 @@ use syscall::error::{Result, Error, EINTR}; ...@@ -3,11 +3,10 @@ use syscall::error::{Result, Error, EINTR};
use crate::arch::manually_enter_trampoline; use crate::arch::manually_enter_trampoline;
use crate::signal::tmp_disable_signals; use crate::signal::tmp_disable_signals;
// TODO: uninitialized memory?
#[inline] #[inline]
pub fn posix_read(fd: usize, buf: &mut [u8]) -> Result<usize> { fn wrapper(mut f: impl FnMut() -> Result<usize>) -> Result<usize> {
loop { loop {
let res = syscall::read(fd, buf); let res = f();
if res == Err(Error::new(EINTR)) { if res == Err(Error::new(EINTR)) {
unsafe { unsafe {
...@@ -18,18 +17,27 @@ pub fn posix_read(fd: usize, buf: &mut [u8]) -> Result<usize> { ...@@ -18,18 +17,27 @@ pub fn posix_read(fd: usize, buf: &mut [u8]) -> Result<usize> {
return res; return res;
} }
} }
// TODO: uninitialized memory?
#[inline]
pub fn posix_read(fd: usize, buf: &mut [u8]) -> Result<usize> {
wrapper(|| syscall::read(fd, buf))
}
#[inline] #[inline]
pub fn posix_write(fd: usize, buf: &[u8]) -> Result<usize> { pub fn posix_write(fd: usize, buf: &[u8]) -> Result<usize> {
loop { wrapper(|| syscall::write(fd, buf))
let res = syscall::write(fd, buf); }
#[inline]
if res == Err(Error::new(EINTR)) { pub fn posix_kill(pid: usize, sig: usize) -> Result<()> {
unsafe { match wrapper(|| syscall::kill(pid, sig)) {
manually_enter_trampoline(); Ok(_) | Err(Error { errno: EINTR }) => Ok(()),
} Err(error) => Err(error),
} }
}
return res; #[inline]
pub fn posix_killpg(pgrp: usize, sig: usize) -> Result<()> {
match wrapper(|| syscall::kill(usize::wrapping_neg(pgrp), sig)) {
Ok(_) | Err(Error { errno: EINTR }) => Ok(()),
Err(error) => Err(error),
} }
} }
...@@ -53,11 +53,11 @@ impl PalSignal for Sys { ...@@ -53,11 +53,11 @@ impl PalSignal for Sys {
} }
fn kill(pid: pid_t, sig: c_int) -> c_int { fn kill(pid: pid_t, sig: c_int) -> c_int {
e(syscall::kill(pid as usize, sig as usize)) as c_int e(redox_rt::sys::posix_kill(pid as usize, sig as usize).map(|()| 0)) as c_int
} }
fn killpg(pgrp: pid_t, sig: c_int) -> c_int { fn killpg(pgrp: pid_t, sig: c_int) -> c_int {
e(syscall::kill(-(pgrp as isize) as usize, sig as usize)) as c_int e(redox_rt::sys::posix_killpg(pgrp as usize, sig as usize).map(|()| 0)) as c_int
} }
fn raise(sig: c_int) -> c_int { fn raise(sig: c_int) -> c_int {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment