From 6725fd6aef0465fd96e0de0a4d073bfc8b528f40 Mon Sep 17 00:00:00 2001 From: Greg V <greg@unrelenting.technology> Date: Thu, 4 Jan 2018 02:40:12 +0300 Subject: [PATCH] Add FreeBSD process descriptors API Available since FreeBSD 9.0, this API allows using local descriptors instead of global PIDs. It works in Capsicum sandboxes. --- libc-test/build.rs | 1 + src/unix/bsd/freebsdlike/freebsd/mod.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 26df46f9..885ae868 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -287,6 +287,7 @@ fn main() { cfg.header("sys/ipc.h"); cfg.header("sys/msg.h"); cfg.header("sys/shm.h"); + cfg.header("sys/procdesc.h"); } if netbsd { diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 6c6935d5..5afb42aa 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -841,6 +841,11 @@ pub const _SC_CPUSET_SIZE: ::c_int = 122; pub const XU_NGROUPS: ::c_int = 16; pub const XUCRED_VERSION: ::c_uint = 0; +// Flags which can be passed to pdfork(2) +pub const PD_DAEMON: ::c_int = 0x00000001; +pub const PD_CLOEXEC: ::c_int = 0x00000002; +pub const PD_ALLOWED_AT_FORK: ::c_int = PD_DAEMON | PD_CLOEXEC; + extern { pub fn __error() -> *mut ::c_int; @@ -896,6 +901,10 @@ extern { pub fn fexecve(fd: ::c_int, argv: *const *const ::c_char, envp: *const *const ::c_char) -> ::c_int; + + pub fn pdfork(fdp: *mut ::c_int, flags: ::c_int) -> ::pid_t; + pub fn pdgetpid(fd: ::c_int, pidp: *mut ::pid_t) -> ::c_int; + pub fn pdkill(fd: ::c_int, signum: ::c_int) -> ::c_int; } cfg_if! { -- GitLab