• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _DEFAULT_SOURCE
2 #define _DEFAULT_SOURCE
3 #endif
4 
5 #include <errno.h>
6 #include <pthread.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/capability.h>
10 #include <sys/psx_syscall.h>
11 #include <sys/types.h>
12 #include <sys/wait.h>
13 #include <unistd.h>
14 
thread_fork_exit(void * data)15 static void *thread_fork_exit(void *data) {
16     usleep(1234);
17     pid_t pid = fork();
18     cap_t start = cap_get_proc();
19     if (pid == 0) {
20 	cap_set_proc(start);
21 	exit(0);
22     }
23     int res;
24     if (waitpid(pid, &res, 0) != pid || res != 0) {
25 	printf("FAILED: pid=%d wait returned %d and/or error: %d\n",
26 	       pid, res, errno);
27 	exit(1);
28     }
29     cap_set_proc(start);
30     return NULL;
31 }
32 
main(int argc,char ** argv)33 int main(int argc, char **argv) {
34     int i;
35     printf("hello libcap and libpsx ");
36     fflush(stdout);
37     cap_t start = cap_get_proc();
38     pthread_t ignored[10];
39     for (i = 0; i < 10; i++) {
40 	pthread_create(&ignored[i], NULL, thread_fork_exit, NULL);
41     }
42     for (i = 0; i < 10; i++) {
43 	printf(".");     /* because of fork, this may print double */
44 	fflush(stdout);  /* try to limit the above effect */
45 	cap_set_proc(start);
46 	usleep(1000);
47     }
48     printf(" PASSED\n");
49     exit(0);
50 }
51