equal
deleted
inserted
replaced
42 pub fn set_blocking_fd(fd: RawFd) -> io::Result<()> { |
42 pub fn set_blocking_fd(fd: RawFd) -> io::Result<()> { |
43 let flags = unsafe { libc::fcntl(fd, libc::F_GETFL) }; |
43 let flags = unsafe { libc::fcntl(fd, libc::F_GETFL) }; |
44 if flags < 0 { |
44 if flags < 0 { |
45 return Err(io::Error::last_os_error()); |
45 return Err(io::Error::last_os_error()); |
46 } |
46 } |
47 let r = unsafe { libc::fcntl(fd, libc::F_SETFL, flags & !libc::O_NONBLOCK) }; |
47 let r = |
|
48 unsafe { libc::fcntl(fd, libc::F_SETFL, flags & !libc::O_NONBLOCK) }; |
48 if r < 0 { |
49 if r < 0 { |
49 return Err(io::Error::last_os_error()); |
50 return Err(io::Error::last_os_error()); |
50 } |
51 } |
51 Ok(()) |
52 Ok(()) |
52 } |
53 } |
67 /// |
68 /// |
68 /// # Safety |
69 /// # Safety |
69 /// |
70 /// |
70 /// This touches global states, and thus synchronized as a one-time |
71 /// This touches global states, and thus synchronized as a one-time |
71 /// initialization function. |
72 /// initialization function. |
72 pub fn setup_signal_handler_once(pid: u32, pgid: Option<u32>) -> io::Result<()> { |
73 pub fn setup_signal_handler_once( |
|
74 pid: u32, |
|
75 pgid: Option<u32>, |
|
76 ) -> io::Result<()> { |
73 let pid_signed = pid as i32; |
77 let pid_signed = pid as i32; |
74 let pgid_signed = pgid.map(|n| n as i32).unwrap_or(0); |
78 let pgid_signed = pgid.map(|n| n as i32).unwrap_or(0); |
75 let mut r = 0; |
79 let mut r = 0; |
76 SETUP_SIGNAL_HANDLER.call_once(|| { |
80 SETUP_SIGNAL_HANDLER.call_once(|| { |
77 r = unsafe { setupsignalhandler(pid_signed, pgid_signed) }; |
81 r = unsafe { setupsignalhandler(pid_signed, pgid_signed) }; |