thread_test.c revision 1d1011a3c5049a7f9eef99d22f3704e4367579cc
1#include "config.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include <cap-ng.h>
5#include <pthread.h>
6
7//#define DEBUG 1
8
9pthread_t thread1, thread2;
10
11void *thread1_main(void *arg)
12{
13	capng_fill(CAPNG_SELECT_BOTH);
14#ifdef DEBUG
15	printf("thread1 filled capabilities\n");
16#endif
17	sleep(2);
18	if (capng_have_capabilities(CAPNG_SELECT_CAPS) < CAPNG_FULL) {
19		printf("Capabilities missing when there should be some\n");
20		exit(1);
21	}
22#ifdef DEBUG
23		printf("SUCCESS: Full capabilities reported\n");
24#endif
25	return NULL;
26}
27
28void *thread2_main(void *arg)
29{
30	sleep(1);
31#ifdef DEBUG
32	printf("thread2 getting capabilities\n");
33#endif
34	capng_get_caps_process();
35	if (capng_have_capabilities(CAPNG_SELECT_CAPS) != CAPNG_NONE) {
36		printf("Detected capabilities when there should not be any\n");
37		exit(1);
38	}
39	capng_clear(CAPNG_SELECT_BOTH);
40#ifdef DEBUG
41	printf("SUCCESS: No capabilities reported\n");
42#endif
43	return NULL;
44}
45
46int main(void)
47{
48	printf("Testing thread separation of capabilities\n");
49	pthread_create(&thread1, NULL, thread1_main, NULL);
50	pthread_create(&thread2, NULL, thread2_main, NULL);
51	sleep(3);
52	return 0;
53}
54
55