Skip to content

Commit 1fac0ee

Browse files
committed
Bind daemon(3)
1 parent fce5767 commit 1fac0ee

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/unistd.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ptr;
22
use std::c_str::{CString, ToCStr};
3-
use libc::{c_char, c_void, size_t};
3+
use libc::{c_char, c_void, c_int, size_t};
44
use fcntl::{Fd, OFlag};
55
use errno::{SysResult, SysError, from_ffi};
66

@@ -25,6 +25,10 @@ mod ffi {
2525
// execute program
2626
// doc: http://man7.org/linux/man-pages/man2/execve.2.html
2727
pub fn execve(filename: *const c_char, argv: *const *const c_char, envp: *const *const c_char) -> c_int;
28+
29+
// run the current process in the background
30+
// doc: http://man7.org/linux/man-pages/man3/daemon.3.html
31+
pub fn daemon(nochdir: c_int, noclose: c_int) -> c_int;
2832
}
2933
}
3034

@@ -93,6 +97,11 @@ pub fn execve(filename: CString, args: &[CString], env: &[CString]) -> SysResult
9397
Ok(())
9498
}
9599

100+
pub fn daemon(nochdir: bool, noclose: bool) -> SysResult<()> {
101+
let res = unsafe { ffi::daemon(nochdir as c_int, noclose as c_int) };
102+
from_ffi(res)
103+
}
104+
96105
pub fn close(fd: Fd) -> SysResult<()> {
97106
let res = unsafe { ffi::close(fd) };
98107
from_ffi(res)

0 commit comments

Comments
 (0)