summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2014-09-11 14:06:12 -0700
committerYehuda Katz <wycats@gmail.com>2014-09-11 14:10:53 -0700
commit1fac0eeb3d63e29139493ab76a2857a8ea710348 (patch)
tree2ab88871610376ad35670065860c38ed6a6b5aba
parentfce5767bf1f03e4666a77457e481bbf07a3d646d (diff)
downloadnix-1fac0eeb3d63e29139493ab76a2857a8ea710348.zip
Bind daemon(3)
-rw-r--r--src/unistd.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index c418b1e9..25dcff34 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -1,6 +1,6 @@
use std::ptr;
use std::c_str::{CString, ToCStr};
-use libc::{c_char, c_void, size_t};
+use libc::{c_char, c_void, c_int, size_t};
use fcntl::{Fd, OFlag};
use errno::{SysResult, SysError, from_ffi};
@@ -25,6 +25,10 @@ mod ffi {
// execute program
// doc: http://man7.org/linux/man-pages/man2/execve.2.html
pub fn execve(filename: *const c_char, argv: *const *const c_char, envp: *const *const c_char) -> c_int;
+
+ // run the current process in the background
+ // doc: http://man7.org/linux/man-pages/man3/daemon.3.html
+ pub fn daemon(nochdir: c_int, noclose: c_int) -> c_int;
}
}
@@ -93,6 +97,11 @@ pub fn execve(filename: CString, args: &[CString], env: &[CString]) -> SysResult
Ok(())
}
+pub fn daemon(nochdir: bool, noclose: bool) -> SysResult<()> {
+ let res = unsafe { ffi::daemon(nochdir as c_int, noclose as c_int) };
+ from_ffi(res)
+}
+
pub fn close(fd: Fd) -> SysResult<()> {
let res = unsafe { ffi::close(fd) };
from_ffi(res)