Skip to content

Commit cf2806f

Browse files
committed
uucore: fix getsid error handling
The previous implementation checked if Errno::last() was UnknownErrno to determine success, but this is incorrect because errno is not cleared on success. A previous syscall could have set errno to a value like ENOENT, causing getsid to incorrectly report an error. The correct pattern is to check if the result is -1, which is what getsid returns on error per POSIX.
1 parent 4f4fa08 commit cf2806f

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/uucore/src/lib/features/process.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ pub fn getpid() -> pid_t {
6767
/// so some system such as redox doesn't supported.
6868
#[cfg(not(target_os = "redox"))]
6969
pub fn getsid(pid: i32) -> Result<pid_t, Errno> {
70-
unsafe {
71-
let result = libc::getsid(pid);
72-
if Errno::last() == Errno::UnknownErrno {
73-
Ok(result)
74-
} else {
75-
Err(Errno::last())
76-
}
70+
let result = unsafe { libc::getsid(pid) };
71+
if result == -1 {
72+
Err(Errno::last())
73+
} else {
74+
Ok(result)
7775
}
7876
}
7977

0 commit comments

Comments
 (0)