xref: /linux-tools/bpf/seccomp/helloworld.c (revision 7889a9fe3f6cd23238c94fad4e1c698d5585c3fe)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <fcntl.h>
4 #include <unistd.h>
5 #include <sys/wait.h>
6 
7 
8 char buf[1024*8];
9 int main(int argc, char *argv[]) {
10     int fd = fork();
11     int x, i, status;
12     if (fd==0) {
13         printf("This is the only io I can access\n");
14         int fd = open("/dev/urandom", O_CLOEXEC|O_RDONLY);
15         read(fd, buf, 4096+1); //sizeof(buf));
16         for (x=0, i=0; i<sizeof(buf); i++) x^=buf[i];
17         printf("Done reading.....0x%x\n", x);
18     } else {
19         wait(&status);
20         if (WIFEXITED(status)) printf("third part done, exit status %d\n", WEXITSTATUS(status));
21         else if (WIFSIGNALED(status)||WIFSTOPPED(status)) {
22             printf("third part killed/stopped by signal %d\n", WTERMSIG(status));
23         } else {
24             printf("third part aborted.");
25         }
26     }
27     return 0;
28 }
29