Add setgroups and fix getgroups#1006
Conversation
|
The CI failure here is unrelated. The Linux setgroups syscall only operates on the current thread, which differs from the POSIX behavior of operating on the entire process, so these functions should go in |
|
@sunfishcode I also considered the same thing as I saw the implementation of other
See the following codes for testing: #include <sys/types.h>
#include <thread>
#include <grp.h>
#include <unistd.h>
#include <stdio.h>
int main() {
std::thread t([]() {
gid_t gids[] = {1000, 27, 109};
setgroups(3, gids);
});
t.join();
gid_t gids[10];
int n = getgroups(10, gids);
for (int i = 0; i < n; i++) {
printf("%d\n", gids[i]);
}
return 0;
} |
|
Ah, I was mistaken about POSIX. Still, the Linux libc function sets the groups for all threads, but it appears the syscall only sets the groups for one thread. That means that in the current PR, the linux_raw backend which uses the syscall behaves differently from the libc backend which uses the libc function. Rustix does not currently have the infrastructure for setting the ids on all threads, and in the absence of such infrastructure, so we should provide the single-thread behahvior, in the |
|
You are right. The syscall itself is done for the thread only. But glibc uses nptl to set for the whole process. int main() {
std::thread t([]() {
gid_t gids[] = {1000, 27, 109};
syscall(SYS_setgroups, 3, gids);
});
t.join();
gid_t gids[10];
int n = syscall(SYS_getgroups, 10, gids);
for (int i = 0; i < n; i++) {
printf("in main %d\n", gids[i]);
}
return 0;
} |
f385b7f to
5cc1ce6
Compare
5cc1ce6 to
a0e93fc
Compare
|
Modified as requested. Also, I fixed
|
69bb2b8 to
b3357af
Compare
|
@sunfishcode Gentle ping. |
|
Looks good, thanks! |
No description provided.