Skip to content

Commit ecb18ff

Browse files
droundycarllerche
authored andcommitted
add an implementation of setpgid
1 parent a58ff1f commit ecb18ff

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/unistd.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use self::linux::*;
1414

1515
mod ffi {
1616
use libc::{c_char, c_int, size_t};
17-
pub use libc::{close, read, write, pipe, ftruncate, unlink};
17+
pub use libc::{close, read, write, pipe, ftruncate, unlink, setpgid};
1818
pub use libc::funcs::posix88::unistd::{fork, getpid, getppid};
1919

2020
extern {
@@ -112,6 +112,14 @@ pub fn getpid() -> pid_t {
112112
pub fn getppid() -> pid_t {
113113
unsafe { ffi::getppid() } // no error handling, according to man page: "These functions are always successful."
114114
}
115+
#[inline]
116+
pub fn setpgid(pid: pid_t, pgid: pid_t) -> Result<()> {
117+
let res = unsafe { ffi::setpgid(pid, pgid) };
118+
if res < 0 {
119+
return Err(Error::Sys(Errno::last()));
120+
}
121+
Ok(())
122+
}
115123

116124
#[inline]
117125
pub fn dup(oldfd: RawFd) -> Result<RawFd> {

0 commit comments

Comments
 (0)