aboutsummaryrefslogtreecommitdiffstats
path: root/src/firemon/procevent.c
diff options
context:
space:
mode:
authorLibravatar Fred Barclay <Fred-Barclay@users.noreply.github.com>2017-05-24 14:13:52 -0500
committerLibravatar Fred Barclay <Fred-Barclay@users.noreply.github.com>2017-05-24 14:13:52 -0500
commit96c920e166b40bbe50f216e294f2efac154a1cb2 (patch)
treefa80a34e81863ab897f2f2b8ec4124b10d023516 /src/firemon/procevent.c
parentremove trailing whitespace from etc/ (diff)
downloadfirejail-96c920e166b40bbe50f216e294f2efac154a1cb2.tar.gz
firejail-96c920e166b40bbe50f216e294f2efac154a1cb2.tar.zst
firejail-96c920e166b40bbe50f216e294f2efac154a1cb2.zip
Remove trailing whitespace from src/
Diffstat (limited to 'src/firemon/procevent.c')
-rw-r--r--src/firemon/procevent.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/firemon/procevent.c b/src/firemon/procevent.c
index 378bdefe9..d6afed93a 100644
--- a/src/firemon/procevent.c
+++ b/src/firemon/procevent.c
@@ -40,12 +40,12 @@ static int pid_is_firejail(pid_t pid) {
40 printf("%s: %d, pid %d\n", __FUNCTION__, __LINE__, pid); 40 printf("%s: %d, pid %d\n", __FUNCTION__, __LINE__, pid);
41#endif 41#endif
42 uid_t rv = 0; 42 uid_t rv = 0;
43 43
44 // open /proc/self/comm 44 // open /proc/self/comm
45 char *file; 45 char *file;
46 if (asprintf(&file, "/proc/%u/comm", pid) == -1) 46 if (asprintf(&file, "/proc/%u/comm", pid) == -1)
47 errExit("asprintf"); 47 errExit("asprintf");
48 48
49 FILE *fp = fopen(file, "r"); 49 FILE *fp = fopen(file, "r");
50 if (!fp) { 50 if (!fp) {
51 free(file); 51 free(file);
@@ -58,7 +58,7 @@ static int pid_is_firejail(pid_t pid) {
58 if (strncmp(buf, "firejail", 8) == 0) 58 if (strncmp(buf, "firejail", 8) == 0)
59 rv = 1; 59 rv = 1;
60 } 60 }
61 61
62#ifdef DEBUG_PRCTL 62#ifdef DEBUG_PRCTL
63 printf("%s: %d, comm %s, rv %d\n", __FUNCTION__, __LINE__, buf, rv); 63 printf("%s: %d, comm %s, rv %d\n", __FUNCTION__, __LINE__, buf, rv);
64#endif 64#endif
@@ -76,7 +76,7 @@ static int pid_is_firejail(pid_t pid) {
76 goto doexit; 76 goto doexit;
77 } 77 }
78 free(fname); 78 free(fname);
79 79
80 // read file 80 // read file
81#define BUFLEN 4096 81#define BUFLEN 4096
82 unsigned char buffer[BUFLEN]; 82 unsigned char buffer[BUFLEN];
@@ -90,16 +90,16 @@ static int pid_is_firejail(pid_t pid) {
90 } 90 }
91 buffer[len] = '\0'; 91 buffer[len] = '\0';
92 close(fd); 92 close(fd);
93 93
94 // list of firejail arguments that don't trigger sandbox creation 94 // list of firejail arguments that don't trigger sandbox creation
95 // the initial -- is not included 95 // the initial -- is not included
96 char *exclude_args[] = { 96 char *exclude_args[] = {
97 "ls", "list", "tree", "x11", "help", "version", "top", "netstats", "debug-syscalls", 97 "ls", "list", "tree", "x11", "help", "version", "top", "netstats", "debug-syscalls",
98 "debug-errnos", "debug-protocols", "protocol.print", "debug.caps", 98 "debug-errnos", "debug-protocols", "protocol.print", "debug.caps",
99 "shutdown", "bandwidth", "caps.print", "cpu.print", "debug-caps", 99 "shutdown", "bandwidth", "caps.print", "cpu.print", "debug-caps",
100 "fs.print", "get", "overlay-clean", NULL 100 "fs.print", "get", "overlay-clean", NULL
101 }; 101 };
102 102
103 int i; 103 int i;
104 char *start; 104 char *start;
105 int first = 1; 105 int first = 1;
@@ -114,30 +114,30 @@ static int pid_is_firejail(pid_t pid) {
114 if (strncmp(start, "--", 2) != 0) 114 if (strncmp(start, "--", 2) != 0)
115 break; 115 break;
116 start += 2; 116 start += 2;
117 117
118 // clan starting with = 118 // clan starting with =
119 char *ptr = strchr(start, '='); 119 char *ptr = strchr(start, '=');
120 if (ptr) 120 if (ptr)
121 *ptr = '\0'; 121 *ptr = '\0';
122 122
123 // look into exclude list 123 // look into exclude list
124 int j = 0; 124 int j = 0;
125 while (exclude_args[j] != NULL) { 125 while (exclude_args[j] != NULL) {
126 if (strcmp(start, exclude_args[j]) == 0) { 126 if (strcmp(start, exclude_args[j]) == 0) {
127 rv = 0; 127 rv = 0;
128#ifdef DEBUG_PRCTL 128#ifdef DEBUG_PRCTL
129printf("start=#%s#, ptr=#%s#, flip rv %d\n", start, ptr, rv); 129printf("start=#%s#, ptr=#%s#, flip rv %d\n", start, ptr, rv);
130#endif 130#endif
131 break; 131 break;
132 } 132 }
133 j++; 133 j++;
134 } 134 }
135 135
136 start = (char *) buffer + i + 1; 136 start = (char *) buffer + i + 1;
137 } 137 }
138 } 138 }
139 139
140doexit: 140doexit:
141 fclose(fp); 141 fclose(fp);
142 free(file); 142 free(file);
143#ifdef DEBUG_PRCTL 143#ifdef DEBUG_PRCTL
@@ -187,7 +187,7 @@ static int procevent_netlink_setup(void) {
187 187
188 if (writev(sock, iov, 3) == -1) 188 if (writev(sock, iov, 3) == -1)
189 goto errexit; 189 goto errexit;
190 190
191 return sock; 191 return sock;
192errexit: 192errexit:
193 fprintf(stderr, "Error: netlink socket problem\n"); 193 fprintf(stderr, "Error: netlink socket problem\n");
@@ -209,29 +209,29 @@ static int procevent_monitor(const int sock, pid_t mypid) {
209 __gcov_flush(); 209 __gcov_flush();
210#endif 210#endif
211 211
212#define BUFFSIZE 4096 212#define BUFFSIZE 4096
213 char __attribute__ ((aligned(NLMSG_ALIGNTO)))buf[BUFFSIZE]; 213 char __attribute__ ((aligned(NLMSG_ALIGNTO)))buf[BUFFSIZE];
214 214
215 fd_set readfds; 215 fd_set readfds;
216 int max; 216 int max;
217 FD_ZERO(&readfds); 217 FD_ZERO(&readfds);
218 FD_SET(sock, &readfds); 218 FD_SET(sock, &readfds);
219 max = sock; 219 max = sock;
220 max++; 220 max++;
221 221
222 int rv = select(max, &readfds, NULL, NULL, &tv); 222 int rv = select(max, &readfds, NULL, NULL, &tv);
223 if (rv == -1) { 223 if (rv == -1) {
224 fprintf(stderr, "recv: %s\n", strerror(errno)); 224 fprintf(stderr, "recv: %s\n", strerror(errno));
225 return -1; 225 return -1;
226 } 226 }
227 227
228 // timeout 228 // timeout
229 if (rv == 0) { 229 if (rv == 0) {
230 tv.tv_sec = 30; 230 tv.tv_sec = 30;
231 tv.tv_usec = 0; 231 tv.tv_usec = 0;
232 continue; 232 continue;
233 } 233 }
234 234
235 235
236 if ((len = recv(sock, buf, sizeof(buf), 0)) == 0) { 236 if ((len = recv(sock, buf, sizeof(buf), 0)) == 0) {
237 return 0; 237 return 0;
@@ -304,7 +304,7 @@ static int procevent_monitor(const int sock, pid_t mypid) {
304 } 304 }
305 sprintf(lineptr, " exec"); 305 sprintf(lineptr, " exec");
306 break; 306 break;
307 307
308 case PROC_EVENT_EXIT: 308 case PROC_EVENT_EXIT:
309 if (proc_ev->event_data.exit.process_pid != 309 if (proc_ev->event_data.exit.process_pid !=
310 proc_ev->event_data.exit.process_tgid) 310 proc_ev->event_data.exit.process_tgid)
@@ -317,7 +317,7 @@ static int procevent_monitor(const int sock, pid_t mypid) {
317 remove_pid = 1; 317 remove_pid = 1;
318 sprintf(lineptr, " exit"); 318 sprintf(lineptr, " exit");
319 break; 319 break;
320 320
321 case PROC_EVENT_UID: 321 case PROC_EVENT_UID:
322 pid = proc_ev->event_data.id.process_tgid; 322 pid = proc_ev->event_data.id.process_tgid;
323#ifdef DEBUG_PRCTL 323#ifdef DEBUG_PRCTL
@@ -363,11 +363,11 @@ static int procevent_monitor(const int sock, pid_t mypid) {
363 continue; 363 continue;
364 } 364 }
365 } 365 }
366 366
367 lineptr += strlen(lineptr); 367 lineptr += strlen(lineptr);
368 sprintf(lineptr, " %u", pid); 368 sprintf(lineptr, " %u", pid);
369 lineptr += strlen(lineptr); 369 lineptr += strlen(lineptr);
370 370
371 char *user = pids[pid].user; 371 char *user = pids[pid].user;
372 if (!user) 372 if (!user)
373 user = pid_get_user_name(pids[pid].uid); 373 user = pid_get_user_name(pids[pid].uid);
@@ -376,7 +376,7 @@ static int procevent_monitor(const int sock, pid_t mypid) {
376 sprintf(lineptr, " (%s)", user); 376 sprintf(lineptr, " (%s)", user);
377 lineptr += strlen(lineptr); 377 lineptr += strlen(lineptr);
378 } 378 }
379 379
380 380
381 int sandbox_closed = 0; // exit sandbox flag 381 int sandbox_closed = 0; // exit sandbox flag
382 char *cmd = pids[pid].cmd; 382 char *cmd = pids[pid].cmd;
@@ -409,11 +409,11 @@ static int procevent_monitor(const int sock, pid_t mypid) {
409 lineptr += strlen(lineptr); 409 lineptr += strlen(lineptr);
410 } 410 }
411 (void) lineptr; 411 (void) lineptr;
412 412
413 // print the event 413 // print the event
414 printf("%s", line); 414 printf("%s", line);
415 fflush(0); 415 fflush(0);
416 416
417 // unflag pid for exit events 417 // unflag pid for exit events
418 if (remove_pid) { 418 if (remove_pid) {
419 if (pids[pid].user) 419 if (pids[pid].user)
@@ -433,15 +433,15 @@ static int procevent_monitor(const int sock, pid_t mypid) {
433 else 433 else
434 printf("\tchild %u\n", child); 434 printf("\tchild %u\n", child);
435 } 435 }
436 436
437 // on uid events the uid is changing 437 // on uid events the uid is changing
438 if (proc_ev->what == PROC_EVENT_UID) { 438 if (proc_ev->what == PROC_EVENT_UID) {
439 if (pids[pid].user) 439 if (pids[pid].user)
440 free(pids[pid].user); 440 free(pids[pid].user);
441 pids[pid].user = 0; 441 pids[pid].user = 0;
442 pids[pid].uid = pid_get_uid(pid); 442 pids[pid].uid = pid_get_uid(pid);
443 } 443 }
444 444
445 if (sandbox_closed) 445 if (sandbox_closed)
446 exit(0); 446 exit(0);
447 } 447 }