xref: /xnu-10002.61.3/tests/rm/pthread_setugid.c (revision 0f4c859e951fba394238ab619495c4e1d54d0f34)
1 #include <darwintest.h>
2 #include <dispatch/dispatch.h>
3 #include <sys/unistd.h>
4 
5 T_GLOBAL_META(T_META_NAMESPACE("xnu.rm"),
6     T_META_RADAR_COMPONENT_NAME("xnu"),
7     T_META_RADAR_COMPONENT_VERSION("rm"),
8     T_META_OWNER("phabouzit")
9     );
10 
11 T_DECL(pthread_setugid_np_81523076,
12     "Make sure pthread_setugid_np() isn't sticky to workqueue threads",
13     T_META_CHECK_LEAKS(false),
14     T_META_ASROOT(true))
15 {
16 	int rc;
17 
18 	rc = pthread_setugid_np(501, getgid());
19 	T_ASSERT_POSIX_SUCCESS(rc, "pthread_setugid_np(501, getgid())");
20 
21 	dispatch_async(dispatch_get_global_queue(0, 0), ^{
22 		T_ASSERT_EQ(getuid(), 0, "getuid should still be 0");
23 		T_END;
24 	});
25 	pause();
26 }
27