1 |
#include <sys/types.h> |
2 |
#include <sys/stat.h> |
3 |
#include <fcntl.h> |
4 |
#include <unistd.h> |
5 |
#include <stdio.h> |
6 |
#include <string.h> |
7 |
|
8 |
static void run_gc(void) |
9 |
{ |
10 |
fprintf(stderr, "Running GC.\n"); |
11 |
close(open("/proc/ccs/profile", O_WRONLY)); |
12 |
sleep(3); |
13 |
} |
14 |
|
15 |
static unsigned int read1(const int fd, unsigned int size) |
16 |
{ |
17 |
char c; |
18 |
unsigned int len = 0; |
19 |
while (size-- && read(fd, &c, 1) == 1 && write(1, "{", 1) == 1 && |
20 |
write(1, &c, 1) == 1 && write(1, "}", 1) == 1) |
21 |
len++; |
22 |
return len; |
23 |
} |
24 |
|
25 |
static void write1(const int fd, const char *str) |
26 |
{ |
27 |
write(1, str, strlen(str)); |
28 |
write(fd, str, strlen(str)); |
29 |
} |
30 |
|
31 |
static inline void write2(const int fd, const char *str1, const char *str2) |
32 |
{ |
33 |
write1(fd, str1); |
34 |
write1(fd, str2); |
35 |
} |
36 |
|
37 |
int main(int argc, char *argv[]) |
38 |
{ |
39 |
static const char *path1 = "/path/to/some/file/in/very/very/deep/" |
40 |
"location/which/will/surely/stop/within/this/pathname/" |
41 |
"while/reading/policy\n"; |
42 |
static const char *path2 = "/path/to/other/file/in/very/very/deep/" |
43 |
"location/which/will/surely/stop/within/this/pathname/" |
44 |
"while/reading/policy\n"; |
45 |
int fd1 = open("/proc/ccs/domain_policy", O_RDWR); |
46 |
int fd2 = open("/proc/ccs/domain_policy", O_RDWR); |
47 |
write1(fd1, "<kernel> /foo/bar /foo/bar/buz\n"); |
48 |
write2(fd1, "file read/write/execute ", path1); |
49 |
write2(fd1, "file read/write/execute ", path2); |
50 |
write2(fd2, "select ", "<kernel> /foo/bar /foo/bar/buz\n"); |
51 |
read1(fd2, 128); |
52 |
write1(fd1, "delete "); |
53 |
write2(fd1, "file read/write/execute ", path2); |
54 |
write1(fd1, "delete "); |
55 |
write2(fd1, "file read/write/execute ", path1); |
56 |
run_gc(); |
57 |
write2(fd1, "delete ", "<kernel> /foo/bar /foo/bar/buz\n"); |
58 |
run_gc(); |
59 |
while (read1(fd2, 1) > 0); |
60 |
close(fd1); |
61 |
close(fd2); |
62 |
fd1 = open("/proc/ccs/exception_policy", O_RDWR); |
63 |
fd2 = open("/proc/ccs/exception_policy", O_RDWR); |
64 |
write2(fd1, "path_group VERY_VERY_LONG_PATH ", path1); |
65 |
write2(fd1, "path_group VERY_VERY_LONG_PATH ", path2); |
66 |
read1(fd2, 128); |
67 |
write1(fd1, "delete "); |
68 |
write2(fd1, "path_group VERY_VERY_LONG_PATH ", path1); |
69 |
write1(fd1, "delete "); |
70 |
write2(fd1, "path_group VERY_VERY_LONG_PATH ", path2); |
71 |
run_gc(); |
72 |
while (read1(fd2, 1) > 0); |
73 |
close(fd1); |
74 |
close(fd2); |
75 |
return 0; |
76 |
} |