File tree 2 files changed +16
-4
lines changed
2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -77,10 +77,7 @@ pub fn run_command(
77
77
78
78
let ( pty_leader, pty_follower) = openpty ( ) ?;
79
79
let ( rx, tx) = pipe ( ) ?;
80
- // SAFETY: we don't call any function that is not `async-signal-safe` inside this `fork` as all
81
- // the signal handling is done by `signal_hook` which protects us from it.
82
- #[ allow( unsafe_code) ]
83
- let monitor_pid = unsafe { fork ( ) } ?;
80
+ let monitor_pid = fork ( ) ?;
84
81
// Monitor logic. Based on `exec_monitor`.
85
82
if monitor_pid == 0 {
86
83
match monitor:: MonitorRelay :: new ( command, pty_follower, tx) ?. run ( ) ? { }
Original file line number Diff line number Diff line change @@ -40,6 +40,21 @@ pub fn pipe() -> io::Result<(OwnedFd, OwnedFd)> {
40
40
Ok ( unsafe { ( OwnedFd :: from_raw_fd ( fds[ 0 ] ) , OwnedFd :: from_raw_fd ( fds[ 1 ] ) ) } )
41
41
}
42
42
43
+ #[ cfg( target_os = "linux" ) ]
44
+ /// Create a new process.
45
+ pub fn fork ( ) -> io:: Result < ProcessId > {
46
+ // SAFETY: `fork` is implemented using `clone` in linux so we don't need to worry about signal
47
+ // safety.
48
+ cerr ( unsafe { libc:: fork ( ) } )
49
+ }
50
+
51
+ #[ cfg( not( target_os = "linux" ) ) ]
52
+ /// Create a new process.
53
+ ///
54
+ /// # Safety
55
+ ///
56
+ /// In a multithreaded program, only async-signal-safe functions are guaranteed to work in the
57
+ /// child process until a call to `execve` or a similar function is done.
43
58
pub unsafe fn fork ( ) -> io:: Result < ProcessId > {
44
59
cerr ( unsafe { libc:: fork ( ) } )
45
60
}
You can’t perform that action at this time.
0 commit comments