11 #include <sys/types.h>
15 #ifdef HAVE_SYS_SYSCALL_H
16 #include <sys/syscall.h>
29 pthread_mutex_t msg_mutex = PTHREAD_MUTEX_INITIALIZER;
31 static void *syscall_setreuid(void *arg)
36 (void) arg; /* unused */
38 rc = syscall(SYS_setreuid, -1, 0);
39 assert_int_equal(rc, 0);
42 assert_int_equal(u, 0);
47 static void test_syscall_setreuid(void **state)
49 pthread_attr_t pthread_custom_attr;
50 pthread_t threads[NUM_THREADS];
53 (void) state; /* unused */
55 pthread_attr_init(&pthread_custom_attr);
57 for (i = 0; i < NUM_THREADS; i++) {
58 pthread_create(&threads[i],
64 for (i = 0; i < NUM_THREADS; i++) {
65 pthread_join(threads[i], NULL);
68 pthread_attr_destroy(&pthread_custom_attr);
71 static void *sync_setreuid(void *arg)
73 struct parm *p = (struct parm *)arg;
76 syscall_setreuid(arg);
80 pthread_mutex_lock(&msg_mutex);
83 assert_int_equal(u, 42);
85 pthread_mutex_unlock(&msg_mutex);
90 static void test_sync_setreuid(void **state)
92 pthread_attr_t pthread_custom_attr;
93 pthread_t threads[NUM_THREADS];
98 (void) state; /* unused */
100 pthread_attr_init(&pthread_custom_attr);
102 p = malloc(NUM_THREADS * sizeof(struct parm));
105 pthread_mutex_lock(&msg_mutex);
107 for (i = 0; i < NUM_THREADS; i++) {
111 pthread_create(&threads[i],
112 &pthread_custom_attr,
117 /* wait for the reads to set euid to 0 */
118 for (i = 0; i < NUM_THREADS; i++) {
119 while (p[i].ready != 1) {
124 rc = setreuid(-1, 42);
125 assert_int_equal(rc, 0);
127 pthread_mutex_unlock(&msg_mutex);
129 for (i = 0; i < NUM_THREADS; i++) {
130 pthread_join(threads[i], NULL);
133 pthread_attr_destroy(&pthread_custom_attr);
140 const UnitTest tests[] = {
141 unit_test(test_syscall_setreuid),
142 unit_test(test_sync_setreuid),
145 rc = run_tests(tests);