From 92d50c9c79e7038db097344d8f00e774277ee519 Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Mon, 26 Feb 2018 16:36:13 -0800 Subject: [PATCH] Add posix_spawn bindings for FreeBSD --- libc-test/build.rs | 1 + src/unix/bsd/freebsdlike/freebsd/mod.rs | 76 +++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 10505db9..7cb9317c 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -294,6 +294,7 @@ fn main() { cfg.header("sys/shm.h"); cfg.header("sys/procdesc.h"); cfg.header("sys/rtprio.h"); + cfg.header("spawn.h"); } if netbsd { diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 1e5f4f03..34d34d89 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -15,6 +15,9 @@ pub type key_t = ::c_long; pub type msglen_t = ::c_ulong; pub type msgqnum_t = ::c_ulong; +pub type posix_spawnattr_t = *mut ::c_void; +pub type posix_spawn_file_actions_t = *mut ::c_void; + s! { pub struct utmpx { pub ut_type: ::c_short, @@ -851,6 +854,13 @@ pub const RTP_PRIO_REALTIME: ::c_ushort = 2; pub const RTP_PRIO_NORMAL: ::c_ushort = 3; pub const RTP_PRIO_IDLE: ::c_ushort = 4; +pub const POSIX_SPAWN_RESETIDS: ::c_int = 0x01; +pub const POSIX_SPAWN_SETPGROUP: ::c_int = 0x02; +pub const POSIX_SPAWN_SETSCHEDPARAM: ::c_int = 0x04; +pub const POSIX_SPAWN_SETSCHEDULER: ::c_int = 0x08; +pub const POSIX_SPAWN_SETSIGDEF: ::c_int = 0x10; +pub const POSIX_SPAWN_SETSIGMASK: ::c_int = 0x20; + extern { pub fn __error() -> *mut ::c_int; @@ -913,6 +923,72 @@ extern { pub fn rtprio_thread(function: ::c_int, lwpid: ::lwpid_t, rtp: *mut super::rtprio) -> ::c_int; + + pub fn posix_spawn(pid: *mut ::pid_t, + path: *const ::c_char, + file_actions: *const ::posix_spawn_file_actions_t, + attrp: *const ::posix_spawnattr_t, + argv: *const *mut ::c_char, + envp: *const *mut ::c_char) -> ::c_int; + pub fn posix_spawnp(pid: *mut ::pid_t, + file: *const ::c_char, + file_actions: *const ::posix_spawn_file_actions_t, + attrp: *const ::posix_spawnattr_t, + argv: *const *mut ::c_char, + envp: *const *mut ::c_char) -> ::c_int; + pub fn posix_spawnattr_init(attr: *mut posix_spawnattr_t) -> ::c_int; + pub fn posix_spawnattr_destroy(attr: *mut posix_spawnattr_t) -> ::c_int; + pub fn posix_spawnattr_getsigdefault(attr: *const posix_spawnattr_t, + default: *mut ::sigset_t) -> ::c_int; + pub fn posix_spawnattr_setsigdefault(attr: *mut posix_spawnattr_t, + default: *const ::sigset_t) -> ::c_int; + pub fn posix_spawnattr_getsigmask(attr: *const posix_spawnattr_t, + default: *mut ::sigset_t) -> ::c_int; + pub fn posix_spawnattr_setsigmask(attr: *mut posix_spawnattr_t, + default: *const ::sigset_t) -> ::c_int; + pub fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, + flags: *mut ::c_short) -> ::c_int; + pub fn posix_spawnattr_setflags(attr: *mut posix_spawnattr_t, + flags: ::c_short) -> ::c_int; + pub fn posix_spawnattr_getpgroup(attr: *const posix_spawnattr_t, + flags: *mut ::pid_t) -> ::c_int; + pub fn posix_spawnattr_setpgroup(attr: *mut posix_spawnattr_t, + flags: ::pid_t) -> ::c_int; + pub fn posix_spawnattr_getschedpolicy(attr: *const posix_spawnattr_t, + flags: *mut ::c_int) -> ::c_int; + pub fn posix_spawnattr_setschedpolicy(attr: *mut posix_spawnattr_t, + flags: ::c_int) -> ::c_int; + pub fn posix_spawnattr_getschedparam( + attr: *const posix_spawnattr_t, + param: *mut ::sched_param, + ) -> ::c_int; + pub fn posix_spawnattr_setschedparam( + attr: *mut posix_spawnattr_t, + param: *const ::sched_param, + ) -> ::c_int; + + pub fn posix_spawn_file_actions_init( + actions: *mut posix_spawn_file_actions_t, + ) -> ::c_int; + pub fn posix_spawn_file_actions_destroy( + actions: *mut posix_spawn_file_actions_t, + ) -> ::c_int; + pub fn posix_spawn_file_actions_addopen( + actions: *mut posix_spawn_file_actions_t, + fd: ::c_int, + path: *const ::c_char, + oflag: ::c_int, + mode: ::mode_t, + ) -> ::c_int; + pub fn posix_spawn_file_actions_addclose( + actions: *mut posix_spawn_file_actions_t, + fd: ::c_int, + ) -> ::c_int; + pub fn posix_spawn_file_actions_adddup2( + actions: *mut posix_spawn_file_actions_t, + fd: ::c_int, + newfd: ::c_int, + ) -> ::c_int; } cfg_if! {