Skip to content

Commit 2c27005

Browse files
authored
Add warning comment to setgroups. (#1037)
Similar to the other `set` functions, this function only changes per-thread state, so add a similar warning that this is different from the libc function.
1 parent 647d6c9 commit 2c27005

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/thread/id.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,25 @@ pub fn set_thread_res_gid(rgid: Gid, egid: Gid, sgid: Gid) -> io::Result<()> {
114114
backend::thread::syscalls::setresgid_thread(rgid, egid, sgid)
115115
}
116116

117-
/// `setgroups(groups)`-Sets the supplementary group IDs for the calling thread.
117+
/// `setgroups(groups)`-Sets the supplementary group IDs for the calling
118+
/// thread.
119+
///
120+
/// # Warning
121+
///
122+
/// This is not the `setgroups` you are looking for… POSIX requires gids to be
123+
/// process granular, but on Linux they are per-thread. Thus, this call only
124+
/// changes the gids for the current *thread*, not the entire process even
125+
/// though that is in violation of the POSIX standard.
126+
///
127+
/// For details on this distinction, see the C library vs. kernel differences
128+
/// in the [manual page][linux_notes]. This call implements the kernel
129+
/// behavior.
118130
///
119131
/// # References
120132
/// - [Linux]
121133
///
122134
/// [Linux]: https://man7.org/linux/man-pages/man2/setgroups.2.html
135+
/// [linux_notes]: https://man7.org/linux/man-pages/man2/setgroups.2.html#NOTES
123136
#[cfg(linux_kernel)]
124137
#[inline]
125138
pub fn set_thread_groups(groups: &[Gid]) -> io::Result<()> {

0 commit comments

Comments
 (0)