~ubuntu-branches/ubuntu/wily/libcap-ng/wily-proposed

« back to all changes in this revision

Viewing changes to src/test/thread_test.c

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Chifflier
  • Date: 2010-07-20 10:03:49 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100720100349-dzex7pirrlq8v7g7
Tags: 0.6.4-1
* Imported Upstream version 0.6.4
* Bump Standards version to 3.9.0

Show diffs side-by-side

added added

removed removed

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