Skip to content

Commit 6725fd6

Browse files
committed
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.
1 parent ecea23a commit 6725fd6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

libc-test/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ fn main() {
287287
cfg.header("sys/ipc.h");
288288
cfg.header("sys/msg.h");
289289
cfg.header("sys/shm.h");
290+
cfg.header("sys/procdesc.h");
290291
}
291292

292293
if netbsd {

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,11 @@ pub const _SC_CPUSET_SIZE: ::c_int = 122;
841841
pub const XU_NGROUPS: ::c_int = 16;
842842
pub const XUCRED_VERSION: ::c_uint = 0;
843843

844+
// Flags which can be passed to pdfork(2)
845+
pub const PD_DAEMON: ::c_int = 0x00000001;
846+
pub const PD_CLOEXEC: ::c_int = 0x00000002;
847+
pub const PD_ALLOWED_AT_FORK: ::c_int = PD_DAEMON | PD_CLOEXEC;
848+
844849
extern {
845850
pub fn __error() -> *mut ::c_int;
846851

@@ -896,6 +901,10 @@ extern {
896901
pub fn fexecve(fd: ::c_int, argv: *const *const ::c_char,
897902
envp: *const *const ::c_char)
898903
-> ::c_int;
904+
905+
pub fn pdfork(fdp: *mut ::c_int, flags: ::c_int) -> ::pid_t;
906+
pub fn pdgetpid(fd: ::c_int, pidp: *mut ::pid_t) -> ::c_int;
907+
pub fn pdkill(fd: ::c_int, signum: ::c_int) -> ::c_int;
899908
}
900909

901910
cfg_if! {

0 commit comments

Comments
 (0)