1 /* Test that setuid, pthread_create, thread exit do not deadlock (bug 28361).
2 Copyright (C) 2021-2022 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 <support/check.h>
20 #include <support/xthread.h>
23 /* How many threads to launch during each iteration. */
26 /* How many iterations to perform. This value seems to reproduce
27 bug 28361 in a bout one in three runs. */
28 enum { iterations
= 5000 };
30 /* Cache of the real user ID used by setuid_thread. */
33 /* Start routine for the threads. */
35 setuid_thread (void *closure
)
37 TEST_COMPARE (setuid (uid
), 0);
44 /* The setxid machinery is still invoked even if the UID is
45 unchanged. (The kernel might reset other credentials as part of
49 for (int i
= 0; i
< iterations
; ++i
)
51 pthread_t thread_ids
[threads
];
52 for (int j
= 0; j
< threads
; ++j
)
53 thread_ids
[j
] = xpthread_create (NULL
, setuid_thread
, NULL
);
54 for (int j
= 0; j
< threads
; ++j
)
55 xpthread_join (thread_ids
[j
]);
61 #include <support/test-driver.c>