diff options
author | 2015-10-27 08:20:01 -0400 | |
---|---|---|
committer | 2015-10-27 08:20:01 -0400 | |
commit | 8ddce5762da4fb6008b45cedce7b38a82a178c73 (patch) | |
tree | 488312bbf5f4100c359af4b2e3f2f6bb0707c422 /src/tools/syscall_test.c | |
parent | admin (diff) | |
download | firejail-8ddce5762da4fb6008b45cedce7b38a82a178c73.tar.gz firejail-8ddce5762da4fb6008b45cedce7b38a82a178c73.tar.zst firejail-8ddce5762da4fb6008b45cedce7b38a82a178c73.zip |
syscall testing
Diffstat (limited to 'src/tools/syscall_test.c')
-rw-r--r-- | src/tools/syscall_test.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/tools/syscall_test.c b/src/tools/syscall_test.c new file mode 100644 index 000000000..47c27978b --- /dev/null +++ b/src/tools/syscall_test.c | |||
@@ -0,0 +1,70 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <stdio.h> | ||
3 | #include <unistd.h> | ||
4 | #include <sys/types.h> | ||
5 | #include <sys/socket.h> | ||
6 | #include <linux/netlink.h> | ||
7 | #include <net/ethernet.h> | ||
8 | |||
9 | int main(int argc, char **argv) { | ||
10 | if (argc != 2) { | ||
11 | printf("Usage: test [sleep|socket|mkdir]\n"); | ||
12 | return 1; | ||
13 | } | ||
14 | |||
15 | if (strcmp(argv[1], "sleep") == 0) { | ||
16 | printf("before sleep\n"); | ||
17 | sleep(1); | ||
18 | printf("after sleep\n"); | ||
19 | } | ||
20 | else if (strcmp(argv[1], "socket") == 0) { | ||
21 | int sock; | ||
22 | |||
23 | printf("testing socket AF_INET\n"); | ||
24 | if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { | ||
25 | perror("socket"); | ||
26 | } | ||
27 | else | ||
28 | close(sock); | ||
29 | |||
30 | printf("testing socket AF_INET6\n"); | ||
31 | if ((sock = socket(AF_INET6, SOCK_STREAM, 0)) < 0) { | ||
32 | perror("socket"); | ||
33 | } | ||
34 | else | ||
35 | close(sock); | ||
36 | |||
37 | printf("testing socket AF_NETLINK\n"); | ||
38 | if ((sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) { | ||
39 | perror("socket"); | ||
40 | } | ||
41 | else | ||
42 | close(sock); | ||
43 | |||
44 | printf("testing socket AF_UNIX\n"); | ||
45 | if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { | ||
46 | perror("socket"); | ||
47 | } | ||
48 | else | ||
49 | close(sock); | ||
50 | |||
51 | // root needed to be able to handle this | ||
52 | printf("testing socket AF_PACKETX\n"); | ||
53 | if ((sock = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_ARP))) < 0) { | ||
54 | perror("socket"); | ||
55 | } | ||
56 | else | ||
57 | close(sock); | ||
58 | printf("after socket\n"); | ||
59 | } | ||
60 | else if (strcmp(argv[1], "mkdir") == 0) { | ||
61 | printf("before mkdir\n"); | ||
62 | mkdir("tmp", 0777); | ||
63 | printf("after mkdir\n"); | ||
64 | } | ||
65 | else { | ||
66 | fprintf(stderr, "Error: invalid argument\n"); | ||
67 | return 1; | ||
68 | } | ||
69 | return 0; | ||
70 | } | ||