platform.texi: Move LAM after LAHF64_SAHF64
[glibc.git] / nptl / tst-setgroups.c
blob8555ab9224485d0525f3a4c27836713e051e7013
1 /* Test setgroups as root and in the presence of threads (Bug 26248)
2 Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <stdlib.h>
20 #include <limits.h>
21 #include <grp.h>
22 #include <errno.h>
23 #include <error.h>
24 #include <support/xthread.h>
25 #include <support/support.h>
26 #include <support/test-driver.h>
27 #include <support/xunistd.h>
29 /* The purpose of this test is to test the setgroups API as root and in
30 the presence of threads. Once we create a thread the setgroups
31 implementation must ensure that all threads are set to the same
32 group and this operation should not fail. Lastly we test setgroups
33 with a zero sized group and a bad address and verify we get EPERM. */
35 static void *
36 start_routine (void *args)
38 return NULL;
41 static int
42 do_test (void)
44 int size;
45 /* NB: Stack address can be at 0xfffXXXXX on 32-bit OSes. */
46 gid_t list[NGROUPS_MAX];
47 int status = EXIT_SUCCESS;
49 pthread_t thread = xpthread_create (NULL, start_routine, NULL);
51 size = getgroups (sizeof (list) / sizeof (list[0]), list);
52 if (size < 0)
54 status = EXIT_FAILURE;
55 error (0, errno, "getgroups failed");
57 if (setgroups (size, list) < 0)
59 if (errno == EPERM)
60 status = EXIT_UNSUPPORTED;
61 else
63 status = EXIT_FAILURE;
64 error (0, errno, "setgroups failed");
68 if (status == EXIT_SUCCESS && setgroups (0, list) < 0)
70 status = EXIT_FAILURE;
71 error (0, errno, "setgroups failed");
74 xpthread_join (thread);
76 return status;
79 #include <support/test-driver.c>