diff options
author | Anas Nashif <anas.nashif@intel.com> | 2012-11-03 20:33:30 -0700 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2012-11-03 20:33:30 -0700 |
commit | c591394f75d0462d9d9a17d66c1bcf800181a294 (patch) | |
tree | 14dded8222a14c5f1f77c27a8c0e1d96ba2ec574 /src/test/thread_test.c | |
download | libcap-ng-c591394f75d0462d9d9a17d66c1bcf800181a294.tar.gz libcap-ng-c591394f75d0462d9d9a17d66c1bcf800181a294.tar.bz2 libcap-ng-c591394f75d0462d9d9a17d66c1bcf800181a294.zip |
Imported Upstream version 0.6.6upstream/0.6.6
Diffstat (limited to 'src/test/thread_test.c')
-rw-r--r-- | src/test/thread_test.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/test/thread_test.c b/src/test/thread_test.c new file mode 100644 index 0000000..c5ba030 --- /dev/null +++ b/src/test/thread_test.c @@ -0,0 +1,53 @@ +#include <stdio.h> +#include <stdlib.h> +#include <cap-ng.h> +#include <pthread.h> + +//#define DEBUG 1 + +pthread_t thread1, thread2; + +void *thread1_main(void *arg) +{ + capng_fill(CAPNG_SELECT_BOTH); +#ifdef DEBUG + printf("thread1 filled capabilities\n"); +#endif + sleep(2); + if (capng_have_capabilities(CAPNG_SELECT_CAPS) < CAPNG_FULL) { + printf("Capabilities missing when there should be some\n"); + exit(1); + } +#ifdef DEBUG + printf("SUCCESS: Full capabilities reported\n"); +#endif + return NULL; +} + +void *thread2_main(void *arg) +{ + sleep(1); +#ifdef DEBUG + printf("thread2 getting capabilities\n"); +#endif + capng_get_caps_process(); + if (capng_have_capabilities(CAPNG_SELECT_CAPS) != CAPNG_NONE) { + printf("Detected capabilities when there should not be any\n"); + exit(1); + } + capng_clear(CAPNG_SELECT_BOTH); +#ifdef DEBUG + printf("SUCCESS: No capabilities reported\n"); +#endif + return NULL; +} + +int main(void) +{ + printf("Testing thread separation of capabilities\n"); + pthread_create(&thread1, NULL, thread1_main, NULL); + pthread_create(&thread2, NULL, thread2_main, NULL); + sleep(3); + return 0; +} + |