aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libtrace/libtrace.c237
1 files changed, 51 insertions, 186 deletions
diff --git a/src/libtrace/libtrace.c b/src/libtrace/libtrace.c
index 71a1234cc..745dd2260 100644
--- a/src/libtrace/libtrace.c
+++ b/src/libtrace/libtrace.c
@@ -34,6 +34,13 @@
34#include <dirent.h> 34#include <dirent.h>
35#include <limits.h> 35#include <limits.h>
36 36
37#define tprintf(fp, args...) \
38 do { \
39 if (!fp)\
40 init(); \
41 fprintf(fp, args); \
42 } while(0)
43
37// break recursivity on fopen call 44// break recursivity on fopen call
38typedef FILE *(*orig_fopen_t)(const char *pathname, const char *mode); 45typedef FILE *(*orig_fopen_t)(const char *pathname, const char *mode);
39static orig_fopen_t orig_fopen = NULL; 46static orig_fopen_t orig_fopen = NULL;
@@ -43,29 +50,29 @@ static orig_fopen64_t orig_fopen64 = NULL;
43// 50//
44// library constructor/destructor 51// library constructor/destructor
45// 52//
46//#define PRINTF_DEVTTY
47#ifdef PRINTF_DEVTTY
48// Replacing printf with fprintf to /dev/tty in order to fix #561 53// Replacing printf with fprintf to /dev/tty in order to fix #561
49// In some cases this crashes the program running in the sandbox. 54// If you really want to turn it off, comment the following line, but its a
50// Example: 55// really bad idea.
51// $ firejail --trace mkdir ttt 56#define PRINTF_DEVTTY
52// logs the following error in syslog:
53// debian kernel: [18521.399073] mkdir[12206]: segfault at 0 ip 00007f77ebf41f6b sp 00007ffe1a0161e0 error 4 in libc-2.24.so[7f77ebe4b000+195000]
54static FILE *ftty = NULL; 57static FILE *ftty = NULL;
55#endif
56static pid_t mypid = 0; 58static pid_t mypid = 0;
57#define MAXNAME 16 59#define MAXNAME 16
58static char myname[MAXNAME] = {'\0', }; 60static char myname[MAXNAME] = {'\0', };
59 61
60static void init(void) __attribute__((constructor)); 62static void init(void) __attribute__((constructor));
61void init(void) { 63void init(void) {
64 if (ftty)
65 return;
66
62 orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); 67 orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen");
63 68
64 // tty 69 // tty
65#ifdef PRINTF_DEVTTY 70#ifdef PRINTF_DEVTTY
66 ftty = orig_fopen("/dev/tty", "w"); 71 ftty = orig_fopen("/dev/tty", "w");
67printf("*** ftty %p ***\n", ftty); 72#else
73 ftty = stderr;
68#endif 74#endif
75 tprintf(ftty, "=== tracelib init() === \n");
69 76
70 // pid 77 // pid
71 mypid = getpid(); 78 mypid = getpid();
@@ -91,9 +98,7 @@ printf("*** ftty %p ***\n", ftty);
91 98
92static void fini(void) __attribute__((destructor)); 99static void fini(void) __attribute__((destructor));
93void fini(void) { 100void fini(void) {
94#ifdef PRINTF_DEVTTY
95 fclose(ftty); 101 fclose(ftty);
96#endif
97} 102}
98 103
99// 104//
@@ -240,43 +245,23 @@ static char *translate(XTable *table, int val) {
240static void print_sockaddr(int sockfd, const char *call, const struct sockaddr *addr, int rv) { 245static void print_sockaddr(int sockfd, const char *call, const struct sockaddr *addr, int rv) {
241 if (addr->sa_family == AF_INET) { 246 if (addr->sa_family == AF_INET) {
242 struct sockaddr_in *a = (struct sockaddr_in *) addr; 247 struct sockaddr_in *a = (struct sockaddr_in *) addr;
243#ifdef PRINTF_DEVTTY 248 tprintf(ftty, "%u:%s:%s %d %s port %u:%d\n", mypid, myname, call, sockfd, inet_ntoa(a->sin_addr), ntohs(a->sin_port), rv);
244 fprintf(ftty, "%u:%s:%s %d %s port %u:%d\n", mypid, myname, call, sockfd, inet_ntoa(a->sin_addr), ntohs(a->sin_port), rv);
245#else
246 printf("%u:%s:%s %d %s port %u:%d\n", mypid, myname, call, sockfd, inet_ntoa(a->sin_addr), ntohs(a->sin_port), rv);
247#endif
248 } 249 }
249 else if (addr->sa_family == AF_INET6) { 250 else if (addr->sa_family == AF_INET6) {
250 struct sockaddr_in6 *a = (struct sockaddr_in6 *) addr; 251 struct sockaddr_in6 *a = (struct sockaddr_in6 *) addr;
251 char str[INET6_ADDRSTRLEN]; 252 char str[INET6_ADDRSTRLEN];
252 inet_ntop(AF_INET6, &(a->sin6_addr), str, INET6_ADDRSTRLEN); 253 inet_ntop(AF_INET6, &(a->sin6_addr), str, INET6_ADDRSTRLEN);
253#ifdef PRINTF_DEVTTY 254 tprintf(ftty, "%u:%s:%s %d %s:%d\n", mypid, myname, call, sockfd, str, rv);
254 fprintf(ftty, "%u:%s:%s %d %s:%d\n", mypid, myname, call, sockfd, str, rv);
255#else
256 printf("%u:%s:%s %d %s:%d\n", mypid, myname, call, sockfd, str, rv);
257#endif
258 } 255 }
259 else if (addr->sa_family == AF_UNIX) { 256 else if (addr->sa_family == AF_UNIX) {
260 struct sockaddr_un *a = (struct sockaddr_un *) addr; 257 struct sockaddr_un *a = (struct sockaddr_un *) addr;
261 if (a->sun_path[0]) 258 if (a->sun_path[0])
262#ifdef PRINTF_DEVTTY 259 tprintf(ftty, "%u:%s:%s %d %s:%d\n", mypid, myname, call, sockfd, a->sun_path, rv);
263 fprintf(ftty, "%u:%s:%s %d %s:%d\n", mypid, myname, call, sockfd, a->sun_path, rv);
264#else
265 printf("%u:%s:%s %d %s:%d\n", mypid, myname, call, sockfd, a->sun_path, rv);
266#endif
267 else 260 else
268#ifdef PRINTF_DEVTTY 261 tprintf(ftty, "%u:%s:%s %d @%s:%d\n", mypid, myname, call, sockfd, a->sun_path + 1, rv);
269 fprintf(ftty, "%u:%s:%s %d @%s:%d\n", mypid, myname, call, sockfd, a->sun_path + 1, rv);
270#else
271 printf("%u:%s:%s %d @%s:%d\n", mypid, myname, call, sockfd, a->sun_path + 1, rv);
272#endif
273 } 262 }
274 else { 263 else {
275#ifdef PRINTF_DEVTTY 264 tprintf(ftty, "%u:%s:%s %d family %d:%d\n", mypid, myname, call, sockfd, addr->sa_family, rv);
276 fprintf(ftty, "%u:%s:%s %d family %d:%d\n", mypid, myname, call, sockfd, addr->sa_family, rv);
277#else
278 printf("%u:%s:%s %d family %d:%d\n", mypid, myname, call, sockfd, addr->sa_family, rv);
279#endif
280 } 265 }
281} 266}
282 267
@@ -292,11 +277,7 @@ int open(const char *pathname, int flags, mode_t mode) {
292 orig_open = (orig_open_t)dlsym(RTLD_NEXT, "open"); 277 orig_open = (orig_open_t)dlsym(RTLD_NEXT, "open");
293 278
294 int rv = orig_open(pathname, flags, mode); 279 int rv = orig_open(pathname, flags, mode);
295#ifdef PRINTF_DEVTTY 280 tprintf(ftty, "%u:%s:open %s:%d\n", mypid, myname, pathname, rv);
296 fprintf(ftty, "%u:%s:open %s:%d\n", mypid, myname, pathname, rv);
297#else
298 printf("%u:%s:open %s:%d\n", mypid, myname, pathname, rv);
299#endif
300 return rv; 281 return rv;
301} 282}
302 283
@@ -307,11 +288,7 @@ int open64(const char *pathname, int flags, mode_t mode) {
307 orig_open64 = (orig_open64_t)dlsym(RTLD_NEXT, "open64"); 288 orig_open64 = (orig_open64_t)dlsym(RTLD_NEXT, "open64");
308 289
309 int rv = orig_open64(pathname, flags, mode); 290 int rv = orig_open64(pathname, flags, mode);
310#ifdef PRINTF_DEVTTY 291 tprintf(ftty, "%u:%s:open64 %s:%d\n", mypid, myname, pathname, rv);
311 fprintf(ftty, "%u:%s:open64 %s:%d\n", mypid, myname, pathname, rv);
312#else
313 printf("%u:%s:open64 %s:%d\n", mypid, myname, pathname, rv);
314#endif
315 return rv; 292 return rv;
316} 293}
317 294
@@ -323,11 +300,7 @@ int openat(int dirfd, const char *pathname, int flags, mode_t mode) {
323 orig_openat = (orig_openat_t)dlsym(RTLD_NEXT, "openat"); 300 orig_openat = (orig_openat_t)dlsym(RTLD_NEXT, "openat");
324 301
325 int rv = orig_openat(dirfd, pathname, flags, mode); 302 int rv = orig_openat(dirfd, pathname, flags, mode);
326#ifdef PRINTF_DEVTTY 303 tprintf(ftty, "%u:%s:openat %s:%d\n", mypid, myname, pathname, rv);
327 fprintf(ftty, "%u:%s:openat %s:%d\n", mypid, myname, pathname, rv);
328#else
329 printf("%u:%s:openat %s:%d\n", mypid, myname, pathname, rv);
330#endif
331 return rv; 304 return rv;
332} 305}
333 306
@@ -338,11 +311,7 @@ int openat64(int dirfd, const char *pathname, int flags, mode_t mode) {
338 orig_openat64 = (orig_openat64_t)dlsym(RTLD_NEXT, "openat64"); 311 orig_openat64 = (orig_openat64_t)dlsym(RTLD_NEXT, "openat64");
339 312
340 int rv = orig_openat64(dirfd, pathname, flags, mode); 313 int rv = orig_openat64(dirfd, pathname, flags, mode);
341#ifdef PRINTF_DEVTTY 314 tprintf(ftty, "%u:%s:openat64 %s:%d\n", mypid, myname, pathname, rv);
342 fprintf(ftty, "%u:%s:openat64 %s:%d\n", mypid, myname, pathname, rv);
343#else
344 printf("%u:%s:openat64 %s:%d\n", mypid, myname, pathname, rv);
345#endif
346 return rv; 315 return rv;
347} 316}
348 317
@@ -353,11 +322,7 @@ FILE *fopen(const char *pathname, const char *mode) {
353 orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); 322 orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen");
354 323
355 FILE *rv = orig_fopen(pathname, mode); 324 FILE *rv = orig_fopen(pathname, mode);
356#ifdef PRINTF_DEVTTY 325 tprintf(ftty, "%u:%s:fopen %s:%p\n", mypid, myname, pathname, rv);
357 fprintf(ftty, "%u:%s:fopen %s:%p\n", mypid, myname, pathname, rv);
358#else
359 printf("%u:%s:fopen %s:%p\n", mypid, myname, pathname, rv);
360#endif
361 return rv; 326 return rv;
362} 327}
363 328
@@ -367,11 +332,7 @@ FILE *fopen64(const char *pathname, const char *mode) {
367 orig_fopen64 = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen64"); 332 orig_fopen64 = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen64");
368 333
369 FILE *rv = orig_fopen64(pathname, mode); 334 FILE *rv = orig_fopen64(pathname, mode);
370#ifdef PRINTF_DEVTTY 335 tprintf(ftty, "%u:%s:fopen64 %s:%p\n", mypid, myname, pathname, rv);
371 fprintf(ftty, "%u:%s:fopen64 %s:%p\n", mypid, myname, pathname, rv);
372#else
373 printf("%u:%s:fopen64 %s:%p\n", mypid, myname, pathname, rv);
374#endif
375 return rv; 336 return rv;
376} 337}
377#endif /* __GLIBC__ */ 338#endif /* __GLIBC__ */
@@ -385,11 +346,7 @@ FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
385 orig_freopen = (orig_freopen_t)dlsym(RTLD_NEXT, "freopen"); 346 orig_freopen = (orig_freopen_t)dlsym(RTLD_NEXT, "freopen");
386 347
387 FILE *rv = orig_freopen(pathname, mode, stream); 348 FILE *rv = orig_freopen(pathname, mode, stream);
388#ifdef PRINTF_DEVTTY 349 tprintf(ftty, "%u:%s:freopen %s:%p\n", mypid, myname, pathname, rv);
389 fprintf(ftty, "%u:%s:freopen %s:%p\n", mypid, myname, pathname, rv);
390#else
391 printf("%u:%s:freopen %s:%p\n", mypid, myname, pathname, rv);
392#endif
393 return rv; 350 return rv;
394} 351}
395 352
@@ -401,11 +358,7 @@ FILE *freopen64(const char *pathname, const char *mode, FILE *stream) {
401 orig_freopen64 = (orig_freopen64_t)dlsym(RTLD_NEXT, "freopen64"); 358 orig_freopen64 = (orig_freopen64_t)dlsym(RTLD_NEXT, "freopen64");
402 359
403 FILE *rv = orig_freopen64(pathname, mode, stream); 360 FILE *rv = orig_freopen64(pathname, mode, stream);
404#ifdef PRINTF_DEVTTY 361 tprintf(ftty, "%u:%s:freopen64 %s:%p\n", mypid, myname, pathname, rv);
405 fprintf(ftty, "%u:%s:freopen64 %s:%p\n", mypid, myname, pathname, rv);
406#else
407 printf("%u:%s:freopen64 %s:%p\n", mypid, myname, pathname, rv);
408#endif
409 return rv; 362 return rv;
410} 363}
411#endif /* __GLIBC__ */ 364#endif /* __GLIBC__ */
@@ -418,11 +371,7 @@ int unlink(const char *pathname) {
418 orig_unlink = (orig_unlink_t)dlsym(RTLD_NEXT, "unlink"); 371 orig_unlink = (orig_unlink_t)dlsym(RTLD_NEXT, "unlink");
419 372
420 int rv = orig_unlink(pathname); 373 int rv = orig_unlink(pathname);
421#ifdef PRINTF_DEVTTY 374 tprintf(ftty, "%u:%s:unlink %s:%d\n", mypid, myname, pathname, rv);
422 fprintf(ftty, "%u:%s:unlink %s:%d\n", mypid, myname, pathname, rv);
423#else
424 printf("%u:%s:unlink %s:%d\n", mypid, myname, pathname, rv);
425#endif
426 return rv; 375 return rv;
427} 376}
428 377
@@ -433,11 +382,7 @@ int unlinkat(int dirfd, const char *pathname, int flags) {
433 orig_unlinkat = (orig_unlinkat_t)dlsym(RTLD_NEXT, "unlinkat"); 382 orig_unlinkat = (orig_unlinkat_t)dlsym(RTLD_NEXT, "unlinkat");
434 383
435 int rv = orig_unlinkat(dirfd, pathname, flags); 384 int rv = orig_unlinkat(dirfd, pathname, flags);
436#ifdef PRINTF_DEVTTY 385 tprintf(ftty, "%u:%s:unlinkat %s:%d\n", mypid, myname, pathname, rv);
437 fprintf(ftty, "%u:%s:unlinkat %s:%d\n", mypid, myname, pathname, rv);
438#else
439 printf("%u:%s:unlinkat %s:%d\n", mypid, myname, pathname, rv);
440#endif
441 return rv; 386 return rv;
442} 387}
443 388
@@ -449,11 +394,7 @@ int mkdir(const char *pathname, mode_t mode) {
449 orig_mkdir = (orig_mkdir_t)dlsym(RTLD_NEXT, "mkdir"); 394 orig_mkdir = (orig_mkdir_t)dlsym(RTLD_NEXT, "mkdir");
450 395
451 int rv = orig_mkdir(pathname, mode); 396 int rv = orig_mkdir(pathname, mode);
452#ifdef PRINTF_DEVTTY 397 tprintf(ftty, "%u:%s:mkdir %s:%d\n", mypid, myname, pathname, rv);
453 fprintf(ftty, "%u:%s:mkdir %s:%d\n", mypid, myname, pathname, rv);
454#else
455 printf("%u:%s:mkdir %s:%d\n", mypid, myname, pathname, rv);
456#endif
457 return rv; 398 return rv;
458} 399}
459 400
@@ -464,11 +405,7 @@ int mkdirat(int dirfd, const char *pathname, mode_t mode) {
464 orig_mkdirat = (orig_mkdirat_t)dlsym(RTLD_NEXT, "mkdirat"); 405 orig_mkdirat = (orig_mkdirat_t)dlsym(RTLD_NEXT, "mkdirat");
465 406
466 int rv = orig_mkdirat(dirfd, pathname, mode); 407 int rv = orig_mkdirat(dirfd, pathname, mode);
467#ifdef PRINTF_DEVTTY 408 tprintf(ftty, "%u:%s:mkdirat %s:%d\n", mypid, myname, pathname, rv);
468 fprintf(ftty, "%u:%s:mkdirat %s:%d\n", mypid, myname, pathname, rv);
469#else
470 printf("%u:%s:mkdirat %s:%d\n", mypid, myname, pathname, rv);
471#endif
472 return rv; 409 return rv;
473} 410}
474 411
@@ -479,11 +416,7 @@ int rmdir(const char *pathname) {
479 orig_rmdir = (orig_rmdir_t)dlsym(RTLD_NEXT, "rmdir"); 416 orig_rmdir = (orig_rmdir_t)dlsym(RTLD_NEXT, "rmdir");
480 417
481 int rv = orig_rmdir(pathname); 418 int rv = orig_rmdir(pathname);
482#ifdef PRINTF_DEVTTY 419 tprintf(ftty, "%u:%s:rmdir %s:%d\n", mypid, myname, pathname, rv);
483 fprintf(ftty, "%u:%s:rmdir %s:%d\n", mypid, myname, pathname, rv);
484#else
485 printf("%u:%s:rmdir %s:%d\n", mypid, myname, pathname, rv);
486#endif
487 return rv; 420 return rv;
488} 421}
489 422
@@ -495,11 +428,7 @@ int stat(const char *pathname, struct stat *statbuf) {
495 orig_stat = (orig_stat_t)dlsym(RTLD_NEXT, "stat"); 428 orig_stat = (orig_stat_t)dlsym(RTLD_NEXT, "stat");
496 429
497 int rv = orig_stat(pathname, statbuf); 430 int rv = orig_stat(pathname, statbuf);
498#ifdef PRINTF_DEVTTY 431 tprintf(ftty, "%u:%s:stat %s:%d\n", mypid, myname, pathname, rv);
499 fprintf(ftty, "%u:%s:stat %s:%d\n", mypid, myname, pathname, rv);
500#else
501 printf("%u:%s:stat %s:%d\n", mypid, myname, pathname, rv);
502#endif
503 return rv; 432 return rv;
504} 433}
505 434
@@ -511,11 +440,7 @@ int stat64(const char *pathname, struct stat64 *statbuf) {
511 orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat64"); 440 orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat64");
512 441
513 int rv = orig_stat64(pathname, statbuf); 442 int rv = orig_stat64(pathname, statbuf);
514#ifdef PRINTF_DEVTTY 443 tprintf(ftty, "%u:%s:stat64 %s:%d\n", mypid, myname, pathname, rv);
515 fprintf(ftty, "%u:%s:stat64 %s:%d\n", mypid, myname, pathname, rv);
516#else
517 printf("%u:%s:stat64 %s:%d\n", mypid, myname, pathname, rv);
518#endif
519 return rv; 444 return rv;
520} 445}
521#endif /* __GLIBC__ */ 446#endif /* __GLIBC__ */
@@ -528,11 +453,7 @@ int lstat(const char *pathname, struct stat *statbuf) {
528 orig_lstat = (orig_lstat_t)dlsym(RTLD_NEXT, "lstat"); 453 orig_lstat = (orig_lstat_t)dlsym(RTLD_NEXT, "lstat");
529 454
530 int rv = orig_lstat(pathname, statbuf); 455 int rv = orig_lstat(pathname, statbuf);
531#ifdef PRINTF_DEVTTY 456 tprintf(ftty, "%u:%s:lstat %s:%d\n", mypid, myname, pathname, rv);
532 fprintf(ftty, "%u:%s:lstat %s:%d\n", mypid, myname, pathname, rv);
533#else
534 printf("%u:%s:lstat %s:%d\n", mypid, myname, pathname, rv);
535#endif
536 return rv; 457 return rv;
537} 458}
538 459
@@ -544,11 +465,7 @@ int lstat64(const char *pathname, struct stat64 *statbuf) {
544 orig_lstat64 = (orig_lstat64_t)dlsym(RTLD_NEXT, "lstat64"); 465 orig_lstat64 = (orig_lstat64_t)dlsym(RTLD_NEXT, "lstat64");
545 466
546 int rv = orig_lstat64(pathname, statbuf); 467 int rv = orig_lstat64(pathname, statbuf);
547#ifdef PRINTF_DEVTTY 468 tprintf(ftty, "%u:%s:lstat64 %s:%d\n", mypid, myname, pathname, rv);
548 fprintf(ftty, "%u:%s:lstat64 %s:%d\n", mypid, myname, pathname, rv);
549#else
550 printf("%u:%s:lstat64 %s:%d\n", mypid, myname, pathname, rv);
551#endif
552 return rv; 469 return rv;
553} 470}
554#endif /* __GLIBC__ */ 471#endif /* __GLIBC__ */
@@ -561,11 +478,7 @@ DIR *opendir(const char *pathname) {
561 orig_opendir = (orig_opendir_t)dlsym(RTLD_NEXT, "opendir"); 478 orig_opendir = (orig_opendir_t)dlsym(RTLD_NEXT, "opendir");
562 479
563 DIR *rv = orig_opendir(pathname); 480 DIR *rv = orig_opendir(pathname);
564#ifdef PRINTF_DEVTTY 481 tprintf(ftty, "%u:%s:opendir %s:%p\n", mypid, myname, pathname, rv);
565 fprintf(ftty, "%u:%s:opendir %s:%p\n", mypid, myname, pathname, rv);
566#else
567 printf("%u:%s:opendir %s:%p\n", mypid, myname, pathname, rv);
568#endif
569 return rv; 482 return rv;
570} 483}
571 484
@@ -577,11 +490,7 @@ int access(const char *pathname, int mode) {
577 orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); 490 orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access");
578 491
579 int rv = orig_access(pathname, mode); 492 int rv = orig_access(pathname, mode);
580#ifdef PRINTF_DEVTTY 493 tprintf(ftty, "%u:%s:access %s:%d\n", mypid, myname, pathname, rv);
581 fprintf(ftty, "%u:%s:access %s:%d\n", mypid, myname, pathname, rv);
582#else
583 printf("%u:%s:access %s:%d\n", mypid, myname, pathname, rv);
584#endif
585 return rv; 494 return rv;
586} 495}
587 496
@@ -639,11 +548,7 @@ int socket(int domain, int type, int protocol) {
639 sprintf(ptr, "%s", str); 548 sprintf(ptr, "%s", str);
640 } 549 }
641 550
642#ifdef PRINTF_DEVTTY 551 tprintf(ftty, "%s:%d\n", socketbuf, rv);
643 fprintf(ftty, "%s:%d\n", socketbuf, rv);
644#else
645 printf("%s:%d\n", socketbuf, rv);
646#endif
647 return rv; 552 return rv;
648} 553}
649 554
@@ -681,11 +586,7 @@ int system(const char *command) {
681 orig_system = (orig_system_t)dlsym(RTLD_NEXT, "system"); 586 orig_system = (orig_system_t)dlsym(RTLD_NEXT, "system");
682 587
683 int rv = orig_system(command); 588 int rv = orig_system(command);
684#ifdef PRINTF_DEVTTY 589 tprintf(ftty, "%u:%s:system %s:%d\n", mypid, myname, command, rv);
685 fprintf(ftty, "%u:%s:system %s:%d\n", mypid, myname, command, rv);
686#else
687 printf("%u:%s:system %s:%d\n", mypid, myname, command, rv);
688#endif
689 590
690 return rv; 591 return rv;
691} 592}
@@ -697,11 +598,7 @@ int setuid(uid_t uid) {
697 orig_setuid = (orig_setuid_t)dlsym(RTLD_NEXT, "setuid"); 598 orig_setuid = (orig_setuid_t)dlsym(RTLD_NEXT, "setuid");
698 599
699 int rv = orig_setuid(uid); 600 int rv = orig_setuid(uid);
700#ifdef PRINTF_DEVTTY 601 tprintf(ftty, "%u:%s:setuid %d:%d\n", mypid, myname, uid, rv);
701 fprintf(ftty, "%u:%s:setuid %d:%d\n", mypid, myname, uid, rv);
702#else
703 printf("%u:%s:setuid %d:%d\n", mypid, myname, uid, rv);
704#endif
705 602
706 return rv; 603 return rv;
707} 604}
@@ -713,11 +610,7 @@ int setgid(gid_t gid) {
713 orig_setgid = (orig_setgid_t)dlsym(RTLD_NEXT, "setgid"); 610 orig_setgid = (orig_setgid_t)dlsym(RTLD_NEXT, "setgid");
714 611
715 int rv = orig_setgid(gid); 612 int rv = orig_setgid(gid);
716#ifdef PRINTF_DEVTTY 613 tprintf(ftty, "%u:%s:setgid %d:%d\n", mypid, myname, gid, rv);
717 fprintf(ftty, "%u:%s:setgid %d:%d\n", mypid, myname, gid, rv);
718#else
719 printf("%u:%s:setgid %d:%d\n", mypid, myname, gid, rv);
720#endif
721 614
722 return rv; 615 return rv;
723} 616}
@@ -729,11 +622,7 @@ int setfsuid(uid_t uid) {
729 orig_setfsuid = (orig_setfsuid_t)dlsym(RTLD_NEXT, "setfsuid"); 622 orig_setfsuid = (orig_setfsuid_t)dlsym(RTLD_NEXT, "setfsuid");
730 623
731 int rv = orig_setfsuid(uid); 624 int rv = orig_setfsuid(uid);
732#ifdef PRINTF_DEVTTY 625 tprintf(ftty, "%u:%s:setfsuid %d:%d\n", mypid, myname, uid, rv);
733 fprintf(ftty, "%u:%s:setfsuid %d:%d\n", mypid, myname, uid, rv);
734#else
735 printf("%u:%s:setfsuid %d:%d\n", mypid, myname, uid, rv);
736#endif
737 626
738 return rv; 627 return rv;
739} 628}
@@ -745,11 +634,7 @@ int setfsgid(gid_t gid) {
745 orig_setfsgid = (orig_setfsgid_t)dlsym(RTLD_NEXT, "setfsgid"); 634 orig_setfsgid = (orig_setfsgid_t)dlsym(RTLD_NEXT, "setfsgid");
746 635
747 int rv = orig_setfsgid(gid); 636 int rv = orig_setfsgid(gid);
748#ifdef PRINTF_DEVTTY 637 tprintf(ftty, "%u:%s:setfsgid %d:%d\n", mypid, myname, gid, rv);
749 fprintf(ftty, "%u:%s:setfsgid %d:%d\n", mypid, myname, gid, rv);
750#else
751 printf("%u:%s:setfsgid %d:%d\n", mypid, myname, gid, rv);
752#endif
753 638
754 return rv; 639 return rv;
755} 640}
@@ -761,11 +646,7 @@ int setreuid(uid_t ruid, uid_t euid) {
761 orig_setreuid = (orig_setreuid_t)dlsym(RTLD_NEXT, "setreuid"); 646 orig_setreuid = (orig_setreuid_t)dlsym(RTLD_NEXT, "setreuid");
762 647
763 int rv = orig_setreuid(ruid, euid); 648 int rv = orig_setreuid(ruid, euid);
764#ifdef PRINTF_DEVTTY 649 tprintf(ftty, "%u:%s:setreuid %d %d:%d\n", mypid, myname, ruid, euid, rv);
765 fprintf(ftty, "%u:%s:setreuid %d %d:%d\n", mypid, myname, ruid, euid, rv);
766#else
767 printf("%u:%s:setreuid %d %d:%d\n", mypid, myname, ruid, euid, rv);
768#endif
769 650
770 return rv; 651 return rv;
771} 652}
@@ -777,11 +658,7 @@ int setregid(gid_t rgid, gid_t egid) {
777 orig_setregid = (orig_setregid_t)dlsym(RTLD_NEXT, "setregid"); 658 orig_setregid = (orig_setregid_t)dlsym(RTLD_NEXT, "setregid");
778 659
779 int rv = orig_setregid(rgid, egid); 660 int rv = orig_setregid(rgid, egid);
780#ifdef PRINTF_DEVTTY 661 tprintf(ftty, "%u:%s:setregid %d %d:%d\n", mypid, myname, rgid, egid, rv);
781 fprintf(ftty, "%u:%s:setregid %d %d:%d\n", mypid, myname, rgid, egid, rv);
782#else
783 printf("%u:%s:setregid %d %d:%d\n", mypid, myname, rgid, egid, rv);
784#endif
785 662
786 return rv; 663 return rv;
787} 664}
@@ -793,11 +670,7 @@ int setresuid(uid_t ruid, uid_t euid, uid_t suid) {
793 orig_setresuid = (orig_setresuid_t)dlsym(RTLD_NEXT, "setresuid"); 670 orig_setresuid = (orig_setresuid_t)dlsym(RTLD_NEXT, "setresuid");
794 671
795 int rv = orig_setresuid(ruid, euid, suid); 672 int rv = orig_setresuid(ruid, euid, suid);
796#ifdef PRINTF_DEVTTY 673 tprintf(ftty, "%u:%s:setresuid %d %d %d:%d\n", mypid, myname, ruid, euid, suid, rv);
797 fprintf(ftty, "%u:%s:setresuid %d %d %d:%d\n", mypid, myname, ruid, euid, suid, rv);
798#else
799 printf("%u:%s:setresuid %d %d %d:%d\n", mypid, myname, ruid, euid, suid, rv);
800#endif
801 674
802 return rv; 675 return rv;
803} 676}
@@ -809,11 +682,7 @@ int setresgid(gid_t rgid, gid_t egid, gid_t sgid) {
809 orig_setresgid = (orig_setresgid_t)dlsym(RTLD_NEXT, "setresgid"); 682 orig_setresgid = (orig_setresgid_t)dlsym(RTLD_NEXT, "setresgid");
810 683
811 int rv = orig_setresgid(rgid, egid, sgid); 684 int rv = orig_setresgid(rgid, egid, sgid);
812#ifdef PRINTF_DEVTTY 685 tprintf(ftty, "%u:%s:setresgid %d %d %d:%d\n", mypid, myname, rgid, egid, sgid, rv);
813 fprintf(ftty, "%u:%s:setresgid %d %d %d:%d\n", mypid, myname, rgid, egid, sgid, rv);
814#else
815 printf("%u:%s:setresgid %d %d %d:%d\n", mypid, myname, rgid, egid, sgid, rv);
816#endif
817 686
818 return rv; 687 return rv;
819} 688}
@@ -828,10 +697,6 @@ static void log_exec(int argc, char** argv) {
828 int rv = readlink("/proc/self/exe", buf, PATH_MAX); 697 int rv = readlink("/proc/self/exe", buf, PATH_MAX);
829 if (rv != -1) { 698 if (rv != -1) {
830 buf[rv] = '\0'; // readlink does not add a '\0' at the end 699 buf[rv] = '\0'; // readlink does not add a '\0' at the end
831#ifdef PRINTF_DEVTTY 700 tprintf(ftty, "%u:%s:exec %s:0\n", mypid, myname, buf);
832 fprintf(ftty, "%u:%s:exec %s:0\n", mypid, myname, buf);
833#else
834 printf("%u:%s:exec %s:0\n", mypid, myname, buf);
835#endif
836 } 701 }
837} 702}