Skip to content

Commit ec34122

Browse files
clang-format
1 parent 4b2aff5 commit ec34122

File tree

10 files changed

+373
-503
lines changed

10 files changed

+373
-503
lines changed

example_grate/cages/etest.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#include <unistd.h>
33

44
int main(void) {
5-
int cageid = getpid();
6-
printf("-------ETEST %d ------\n", cageid);
7-
printf("getegid() = %d\n", (int)getegid());
8-
printf("geteuid() = %d\n", (int)geteuid());
9-
printf("----(EXIT) ETEST----\n");
10-
return 0;
5+
int cageid = getpid();
6+
printf("-------ETEST %d ------\n", cageid);
7+
printf("getegid() = %d\n", (int)getegid());
8+
printf("geteuid() = %d\n", (int)geteuid());
9+
printf("----(EXIT) ETEST----\n");
10+
return 0;
1111
}

example_grate/cages/gidtest.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#include <unistd.h>
33

44
int main(void) {
5-
int cageid = getpid();
6-
printf("--- GIDTEST %d ---\n", cageid);
7-
printf("getgid() = %d\n", (int)getgid());
8-
printf("--EXIT GIDTEST-\n");
9-
return 0;
5+
int cageid = getpid();
6+
printf("--- GIDTEST %d ---\n", cageid);
7+
printf("getgid() = %d\n", (int)getgid());
8+
printf("--EXIT GIDTEST-\n");
9+
return 0;
1010
}

example_grate/cages/mash.c

Lines changed: 77 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -10,91 +10,96 @@
1010
#include <dirent.h>
1111

1212
static char *trim(char *s) {
13-
while (isspace(*s)) s++;
14-
if (*s == 0) return s;
15-
char *end = s + strlen(s) - 1;
16-
while (end > s && isspace(*end)) end--;
17-
end[1] = '\0';
18-
return s;
13+
while (isspace(*s))
14+
s++;
15+
if (*s == 0)
16+
return s;
17+
char *end = s + strlen(s) - 1;
18+
while (end > s && isspace(*end))
19+
end--;
20+
end[1] = '\0';
21+
return s;
1922
}
2023

2124
// split a string like "cmd arg1 arg2" into argv[]
2225
static char **make_argv(char *cmd) {
23-
int cap = 8, n = 0;
24-
char **argv = malloc(sizeof(char*) * cap);
25-
char *tok = strtok(cmd, " \t");
26-
while (tok) {
27-
if (n + 1 >= cap) {
28-
cap *= 2;
29-
argv = realloc(argv, sizeof(char*) * cap);
30-
}
31-
argv[n++] = tok;
32-
tok = strtok(NULL, " \t");
33-
}
34-
argv[n] = NULL;
35-
return argv;
26+
int cap = 8, n = 0;
27+
char **argv = malloc(sizeof(char *) * cap);
28+
char *tok = strtok(cmd, " \t");
29+
while (tok) {
30+
if (n + 1 >= cap) {
31+
cap *= 2;
32+
argv = realloc(argv, sizeof(char *) * cap);
33+
}
34+
argv[n++] = tok;
35+
tok = strtok(NULL, " \t");
36+
}
37+
argv[n] = NULL;
38+
return argv;
3639
}
3740

3841
void list_dir(const char *path) {
39-
DIR *d = opendir(path);
40-
struct dirent *entry;
41-
printf("Contents of %s:\n", path);
42-
while ((entry = readdir(d)) != NULL) {
43-
printf(" %s\n", entry->d_name);
44-
}
45-
closedir(d);
46-
printf("\n");
42+
DIR *d = opendir(path);
43+
struct dirent *entry;
44+
printf("Contents of %s:\n", path);
45+
while ((entry = readdir(d)) != NULL) {
46+
printf(" %s\n", entry->d_name);
47+
}
48+
closedir(d);
49+
printf("\n");
4750
}
4851

4952
int main(int argc, char **argv) {
50-
if (argc < 3 || strcmp(argv[1], "-c") != 0) {
51-
fprintf(stderr, "usage: %s -c \"command\"\n", argv[0]);
52-
return 1;
53-
}
53+
if (argc < 3 || strcmp(argv[1], "-c") != 0) {
54+
fprintf(stderr, "usage: %s -c \"command\"\n", argv[0]);
55+
return 1;
56+
}
5457

55-
int fd = open("etest.wasm", O_WRONLY, 0);
56-
printf("FD etest: %d\n", fd);
57-
close(fd);
58+
int fd = open("etest.wasm", O_WRONLY, 0);
59+
printf("FD etest: %d\n", fd);
60+
close(fd);
5861

59-
int nchildren=0;
62+
int nchildren = 0;
6063

61-
char *cmd = strdup(argv[2]); // full string
62-
char *saveptr;
63-
char *segment = strtok_r(cmd, "&", &saveptr);
64+
char *cmd = strdup(argv[2]); // full string
65+
char *saveptr;
66+
char *segment = strtok_r(cmd, "&", &saveptr);
6467

65-
while (segment) {
66-
char *t = trim(segment);
67-
if (*t) {
68-
pid_t pid = fork();
69-
if (pid == 0) {
70-
// child: exec command
71-
char *copy = strdup(t);
72-
char **cmd_argv = make_argv(copy);
73-
74-
execv(cmd_argv[0], cmd_argv);
75-
char errbuf[256];
76-
snprintf(errbuf, sizeof(errbuf), "execv(%s)", cmd_argv[0]);
77-
perror(errbuf);
78-
exit(1);
79-
} else if (pid < 0) {
80-
perror("fork");
81-
}else {
82-
nchildren++;
83-
}
84-
// parent: do not wait (background)
85-
}
86-
segment = strtok_r(NULL, "&", &saveptr);
87-
}
68+
while (segment) {
69+
char *t = trim(segment);
70+
if (*t) {
71+
pid_t pid = fork();
72+
if (pid == 0) {
73+
// child: exec command
74+
char *copy = strdup(t);
75+
char **cmd_argv = make_argv(copy);
8876

89-
// behave like bash when all jobs are background:
90-
// exit immediately, but reap zombies
91-
for (int i = 0; i < nchildren; i++) {
92-
int status;
93-
pid_t w = wait(&status);
94-
if (w > 0) {
95-
printf("[mash] terminated pid %d, status %d\n", w, status);
96-
}
97-
}
98-
99-
return 0;
77+
execv(cmd_argv[0], cmd_argv);
78+
char errbuf[256];
79+
snprintf(errbuf, sizeof(errbuf), "execv(%s)",
80+
cmd_argv[0]);
81+
perror(errbuf);
82+
exit(1);
83+
} else if (pid < 0) {
84+
perror("fork");
85+
} else {
86+
nchildren++;
87+
}
88+
// parent: do not wait (background)
89+
}
90+
segment = strtok_r(NULL, "&", &saveptr);
91+
}
92+
93+
// behave like bash when all jobs are background:
94+
// exit immediately, but reap zombies
95+
for (int i = 0; i < nchildren; i++) {
96+
int status;
97+
pid_t w = wait(&status);
98+
if (w > 0) {
99+
printf("[mash] terminated pid %d, status %d\n", w,
100+
status);
101+
}
102+
}
103+
104+
return 0;
100105
}

example_grate/cages/runopen.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
int main() {
1010
int cageid = getpid();
11-
printf("\n---- RUNOPEN %d ----\n", cageid);
12-
int fd = open("firstfile", O_CREAT | O_WRONLY, 0755);
11+
printf("\n---- RUNOPEN %d ----\n", cageid);
12+
int fd = open("firstfile", O_CREAT | O_WRONLY, 0755);
1313
printf("FD: %d\n", fd);
1414
close(fd);
15-
printf("\n--EXIT RUNOPEN---\n");
15+
printf("\n--EXIT RUNOPEN---\n");
1616
return 0;
1717
}

example_grate/cages/tester.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
int main() {
1010
printf("\n[PROG]: Top\n");
11-
int fd = open("etest.wasm", O_WRONLY, 0755);
12-
printf("\n[PROG]: FD: %d\n", fd);
11+
int fd = open("etest.wasm", O_WRONLY, 0755);
12+
printf("\n[PROG]: FD: %d\n", fd);
1313

1414
close(fd);
1515
return 0;

example_grate/grates/getegid_grate.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,11 @@
66
#include <lind_syscall_num.h>
77
#include "magic.h"
88

9-
109
int grate_syscalls[] = {GETEGID_SYSCALL};
1110
int grate_syscalls_len = 1;
1211

13-
void grate_init() {
14-
printf("EGID init'd\n");
15-
}
16-
17-
void grate_destroy() {
18-
printf("EGID exiting.\n");
19-
}
12+
void grate_init() { printf("EGID init'd\n"); }
2013

21-
int getegid_syscall(int cageid) {
22-
return 556;
23-
}
14+
void grate_destroy() { printf("EGID exiting.\n"); }
2415

16+
int getegid_syscall(int cageid) { return 556; }

example_grate/grates/geteuid_grate.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,8 @@
99
int grate_syscalls[] = {GETEUID_SYSCALL};
1010
int grate_syscalls_len = 1;
1111

12-
void grate_init() {
13-
printf("EUID initing...\n");
14-
}
12+
void grate_init() { printf("EUID initing...\n"); }
1513

16-
void grate_destroy() {
17-
printf("EUID exiting.\n");
18-
}
14+
void grate_destroy() { printf("EUID exiting.\n"); }
1915

20-
int geteuid_syscall(int cageid) {
21-
return 546;
22-
}
16+
int geteuid_syscall(int cageid) { return 546; }

example_grate/grates/getgid_grate.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@
66
#include <lind_syscall_num.h>
77
#include "magic.h"
88

9-
109
int grate_syscalls[] = {GETGID_SYSCALL};
1110
int grate_syscalls_len = 1;
1211

13-
void grate_init() {
14-
printf("GID init'd\n");
15-
}
12+
void grate_init() { printf("GID init'd\n"); }
1613

17-
void grate_destroy() {
18-
printf("GID exiting.\n");
19-
}
14+
void grate_destroy() { printf("GID exiting.\n"); }
2015

21-
int getegid_syscall(int cageid) {
22-
return 999;
23-
}
16+
int getegid_syscall(int cageid) { return 999; }

0 commit comments

Comments
 (0)