@@ -2898,6 +2898,54 @@ mod getres {
28982898 }
28992899}
29002900
2901+ #[ cfg( feature = "process" ) ]
2902+ #[ cfg( target_os = "freebsd" ) ]
2903+ libc_bitflags ! {
2904+ /// Flags for [`rfork`]
2905+ ///
2906+ /// subset of flags supported by FreeBSD 12.x and onwards
2907+ /// with a safe outcome, thus as `RFMEM` can possibly lead to undefined behavior,
2908+ /// it is not in the list. And `rfork_thread` is deprecated.
2909+ pub struct RforkFlags : libc:: c_int {
2910+ /// creates a new process.
2911+ RFPROC ;
2912+ /// the child process will detach from the parent.
2913+ /// however, no status will be emitted at child's exit.
2914+ RFNOWAIT ;
2915+ /// the file descriptor's table will be copied
2916+ RFFDG ;
2917+ /// a new file descriptor's table will be created
2918+ RFCFDG ;
2919+ /// force sharing the sigacts structure between
2920+ /// the child and the parent.
2921+ RFSIGSHARE ;
2922+ /// enables kernel thread support.
2923+ RFTHREAD ;
2924+ /// sets a status to emit at child's exit.
2925+ RFTSIGZMB ;
2926+ /// linux's behavior compatibility setting.
2927+ /// emits SIGUSR1 as opposed to SIGCHLD upon child's exit.
2928+ RFLINUXTHPN ;
2929+ }
2930+ }
2931+
2932+ feature ! {
2933+ #![ feature = "process" ]
2934+ #[ cfg( target_os = "freebsd" ) ]
2935+ /// rfork can be used to have a tigher control about which resources child
2936+ /// and parent process will be sharing, file descriptors, address spaces
2937+ /// and child exit's behavior.
2938+ pub unsafe fn rfork( flags: RforkFlags ) -> Result <ForkResult > {
2939+ use ForkResult :: * ;
2940+ let res = unsafe { libc:: rfork( flags. bits( ) ) } ;
2941+
2942+ Errno :: result( res) . map( |res| match res {
2943+ 0 => Child ,
2944+ res => Parent { child: Pid ( res) } ,
2945+ } )
2946+ }
2947+ }
2948+
29012949#[ cfg( feature = "fs" ) ]
29022950libc_bitflags ! {
29032951 /// Options for access()
0 commit comments