|
3 | 3 | // For the full copyright and license information, please view the LICENSE |
4 | 4 | // file that was distributed with this source code. |
5 | 5 |
|
6 | | -// spell-checker:ignore (vars) cvar exitstatus cmdline kworker getsid getpid |
| 6 | +// spell-checker:ignore (vars) cvar exitstatus cmdline kworker |
7 | 7 | // spell-checker:ignore (sys/unix) WIFSIGNALED ESRCH |
8 | 8 | // spell-checker:ignore pgrep pwait snice getpgrp |
9 | 9 |
|
10 | 10 | use libc::{gid_t, pid_t, uid_t}; |
11 | | -#[cfg(not(target_os = "redox"))] |
12 | | -use nix::errno::Errno; |
13 | 11 | use nix::sys::signal::{self as nix_signal, SigHandler, Signal}; |
14 | 12 | use nix::unistd::Pid; |
15 | 13 | use std::io; |
@@ -46,35 +44,6 @@ pub fn getuid() -> uid_t { |
46 | 44 | nix::unistd::getuid().as_raw() |
47 | 45 | } |
48 | 46 |
|
49 | | -/// `getpid()` returns the pid of the calling process. |
50 | | -pub fn getpid() -> pid_t { |
51 | | - nix::unistd::getpid().as_raw() |
52 | | -} |
53 | | - |
54 | | -/// `getsid()` returns the session ID of the process with process ID pid. |
55 | | -/// |
56 | | -/// If pid is 0, getsid() returns the session ID of the calling process. |
57 | | -/// |
58 | | -/// # Error |
59 | | -/// |
60 | | -/// - [Errno::EPERM] A process with process ID pid exists, but it is not in the same session as the calling process, and the implementation considers this an error. |
61 | | -/// - [Errno::ESRCH] No process with process ID pid was found. |
62 | | -/// |
63 | | -/// |
64 | | -/// # Platform |
65 | | -/// |
66 | | -/// This function only support standard POSIX implementation platform, |
67 | | -/// so some system such as redox doesn't supported. |
68 | | -#[cfg(not(target_os = "redox"))] |
69 | | -pub fn getsid(pid: i32) -> Result<pid_t, Errno> { |
70 | | - let pid = if pid == 0 { |
71 | | - None |
72 | | - } else { |
73 | | - Some(Pid::from_raw(pid)) |
74 | | - }; |
75 | | - nix::unistd::getsid(pid).map(Pid::as_raw) |
76 | | -} |
77 | | - |
78 | 47 | /// Missing methods for Child objects |
79 | 48 | pub trait ChildExt { |
80 | 49 | /// Send a signal to a Child process. |
@@ -166,25 +135,3 @@ impl ChildExt for Child { |
166 | 135 | Ok(None) |
167 | 136 | } |
168 | 137 | } |
169 | | - |
170 | | -#[cfg(test)] |
171 | | -mod tests { |
172 | | - use super::*; |
173 | | - |
174 | | - #[test] |
175 | | - #[cfg(not(target_os = "redox"))] |
176 | | - fn test_getsid() { |
177 | | - assert_eq!( |
178 | | - getsid(getpid()).expect("getsid(getpid)"), |
179 | | - // zero is a special value for SID. |
180 | | - // https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsid.html |
181 | | - getsid(0).expect("getsid(0)") |
182 | | - ); |
183 | | - |
184 | | - // SID never be 0. |
185 | | - assert!(getsid(getpid()).expect("getsid(getpid)") > 0); |
186 | | - |
187 | | - // This might caused tests failure but the probability is low. |
188 | | - assert!(getsid(999_999).is_err()); |
189 | | - } |
190 | | -} |
0 commit comments