diff options
Diffstat (limited to 'src/libtrace/libtrace.c')
-rw-r--r-- | src/libtrace/libtrace.c | 179 |
1 files changed, 85 insertions, 94 deletions
diff --git a/src/libtrace/libtrace.c b/src/libtrace/libtrace.c index 397761c74..60fdb5470 100644 --- a/src/libtrace/libtrace.c +++ b/src/libtrace/libtrace.c | |||
@@ -41,54 +41,45 @@ typedef FILE *(*orig_fopen64_t)(const char *pathname, const char *mode); | |||
41 | static orig_fopen64_t orig_fopen64 = NULL; | 41 | static orig_fopen64_t orig_fopen64 = NULL; |
42 | 42 | ||
43 | // | 43 | // |
44 | // pid | 44 | // library constructor/destructor |
45 | // | 45 | // |
46 | static FILE *ftty = NULL; | ||
46 | static pid_t mypid = 0; | 47 | static pid_t mypid = 0; |
47 | static inline pid_t pid(void) { | ||
48 | if (!mypid) | ||
49 | mypid = getpid(); | ||
50 | return mypid; | ||
51 | } | ||
52 | |||
53 | // | ||
54 | // process name | ||
55 | // | ||
56 | #define MAXNAME 16 | 48 | #define MAXNAME 16 |
57 | static char myname[MAXNAME]; | 49 | static char myname[MAXNAME] = {'\0', }; |
58 | static int nameinit = 0; | 50 | |
59 | static char *name(void) { | 51 | static void init(void) __attribute__((constructor)); |
60 | if (!nameinit) { | 52 | void init(void) { |
61 | // initialize the name of the process based on /proc/PID/comm | 53 | orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); |
62 | memset(myname, 0, MAXNAME); | 54 | |
63 | 55 | // tty | |
64 | pid_t p = pid(); | 56 | ftty = orig_fopen("/dev/tty", "w"); |
65 | char *fname; | 57 | |
66 | if (asprintf(&fname, "/proc/%u/comm", p) == -1) | 58 | // pid |
67 | return "unknown"; | 59 | mypid = getpid(); |
68 | 60 | ||
69 | // read file | 61 | // process name |
70 | if (!orig_fopen) | 62 | char *fname; |
71 | orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); | 63 | if (asprintf(&fname, "/proc/%u/comm", mypid) == -1) |
72 | FILE *fp = orig_fopen(fname, "r"); | 64 | strncpy(myname, "unknown", MAXNAME-1); |
73 | if (!fp) | 65 | |
74 | return "unknown"; | 66 | // read file |
75 | if (fgets(myname, MAXNAME, fp) == NULL) { | 67 | FILE *fp = orig_fopen(fname, "r"); |
76 | fclose(fp); | 68 | if (!fp || fgets(myname, MAXNAME, fp) == NULL) |
77 | free(fname); | 69 | strncpy(myname, "unknown", MAXNAME-1); |
78 | return "unknown"; | 70 | |
79 | } | 71 | // clean '\n' |
80 | 72 | char *ptr = strchr(myname, '\n'); | |
81 | // clean '\n' | 73 | if (ptr) |
82 | char *ptr = strchr(myname, '\n'); | 74 | *ptr = '\0'; |
83 | if (ptr) | 75 | |
84 | *ptr = '\0'; | 76 | fclose(fp); |
85 | 77 | free(fname); | |
86 | fclose(fp); | 78 | } |
87 | free(fname); | ||
88 | nameinit = 1; | ||
89 | } | ||
90 | 79 | ||
91 | return myname; | 80 | static void fini(void) __attribute__((destructor)); |
81 | void fini(void) { | ||
82 | fclose(ftty); | ||
92 | } | 83 | } |
93 | 84 | ||
94 | // | 85 | // |
@@ -235,23 +226,23 @@ static char *translate(XTable *table, int val) { | |||
235 | static void print_sockaddr(int sockfd, const char *call, const struct sockaddr *addr, int rv) { | 226 | static void print_sockaddr(int sockfd, const char *call, const struct sockaddr *addr, int rv) { |
236 | if (addr->sa_family == AF_INET) { | 227 | if (addr->sa_family == AF_INET) { |
237 | struct sockaddr_in *a = (struct sockaddr_in *) addr; | 228 | struct sockaddr_in *a = (struct sockaddr_in *) addr; |
238 | printf("%u:%s:%s %d %s port %u:%d\n", pid(), name(), call, sockfd, inet_ntoa(a->sin_addr), ntohs(a->sin_port), rv); | 229 | 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); |
239 | } | 230 | } |
240 | else if (addr->sa_family == AF_INET6) { | 231 | else if (addr->sa_family == AF_INET6) { |
241 | struct sockaddr_in6 *a = (struct sockaddr_in6 *) addr; | 232 | struct sockaddr_in6 *a = (struct sockaddr_in6 *) addr; |
242 | char str[INET6_ADDRSTRLEN]; | 233 | char str[INET6_ADDRSTRLEN]; |
243 | inet_ntop(AF_INET6, &(a->sin6_addr), str, INET6_ADDRSTRLEN); | 234 | inet_ntop(AF_INET6, &(a->sin6_addr), str, INET6_ADDRSTRLEN); |
244 | printf("%u:%s:%s %d %s:%d\n", pid(), name(), call, sockfd, str, rv); | 235 | fprintf(ftty, "%u:%s:%s %d %s:%d\n", mypid, myname, call, sockfd, str, rv); |
245 | } | 236 | } |
246 | else if (addr->sa_family == AF_UNIX) { | 237 | else if (addr->sa_family == AF_UNIX) { |
247 | struct sockaddr_un *a = (struct sockaddr_un *) addr; | 238 | struct sockaddr_un *a = (struct sockaddr_un *) addr; |
248 | if (a->sun_path[0]) | 239 | if (a->sun_path[0]) |
249 | printf("%u:%s:%s %d %s:%d\n", pid(), name(), call, sockfd, a->sun_path, rv); | 240 | fprintf(ftty, "%u:%s:%s %d %s:%d\n", mypid, myname, call, sockfd, a->sun_path, rv); |
250 | else | 241 | else |
251 | printf("%u:%s:%s %d @%s:%d\n", pid(), name(), call, sockfd, a->sun_path + 1, rv); | 242 | fprintf(ftty, "%u:%s:%s %d @%s:%d\n", mypid, myname, call, sockfd, a->sun_path + 1, rv); |
252 | } | 243 | } |
253 | else { | 244 | else { |
254 | printf("%u:%s:%s %d family %d:%d\n", pid(), name(), call, sockfd, addr->sa_family, rv); | 245 | fprintf(ftty, "%u:%s:%s %d family %d:%d\n", mypid, myname, call, sockfd, addr->sa_family, rv); |
255 | } | 246 | } |
256 | } | 247 | } |
257 | 248 | ||
@@ -267,7 +258,7 @@ int open(const char *pathname, int flags, mode_t mode) { | |||
267 | orig_open = (orig_open_t)dlsym(RTLD_NEXT, "open"); | 258 | orig_open = (orig_open_t)dlsym(RTLD_NEXT, "open"); |
268 | 259 | ||
269 | int rv = orig_open(pathname, flags, mode); | 260 | int rv = orig_open(pathname, flags, mode); |
270 | printf("%u:%s:open %s:%d\n", pid(), name(), pathname, rv); | 261 | fprintf(ftty, "%u:%s:open %s:%d\n", mypid, myname, pathname, rv); |
271 | return rv; | 262 | return rv; |
272 | } | 263 | } |
273 | 264 | ||
@@ -278,7 +269,7 @@ int open64(const char *pathname, int flags, mode_t mode) { | |||
278 | orig_open64 = (orig_open64_t)dlsym(RTLD_NEXT, "open64"); | 269 | orig_open64 = (orig_open64_t)dlsym(RTLD_NEXT, "open64"); |
279 | 270 | ||
280 | int rv = orig_open64(pathname, flags, mode); | 271 | int rv = orig_open64(pathname, flags, mode); |
281 | printf("%u:%s:open64 %s:%d\n", pid(), name(), pathname, rv); | 272 | fprintf(ftty, "%u:%s:open64 %s:%d\n", mypid, myname, pathname, rv); |
282 | return rv; | 273 | return rv; |
283 | } | 274 | } |
284 | 275 | ||
@@ -290,7 +281,7 @@ int openat(int dirfd, const char *pathname, int flags, mode_t mode) { | |||
290 | orig_openat = (orig_openat_t)dlsym(RTLD_NEXT, "openat"); | 281 | orig_openat = (orig_openat_t)dlsym(RTLD_NEXT, "openat"); |
291 | 282 | ||
292 | int rv = orig_openat(dirfd, pathname, flags, mode); | 283 | int rv = orig_openat(dirfd, pathname, flags, mode); |
293 | printf("%u:%s:openat %s:%d\n", pid(), name(), pathname, rv); | 284 | fprintf(ftty, "%u:%s:openat %s:%d\n", mypid, myname, pathname, rv); |
294 | return rv; | 285 | return rv; |
295 | } | 286 | } |
296 | 287 | ||
@@ -301,7 +292,7 @@ int openat64(int dirfd, const char *pathname, int flags, mode_t mode) { | |||
301 | orig_openat64 = (orig_openat64_t)dlsym(RTLD_NEXT, "openat64"); | 292 | orig_openat64 = (orig_openat64_t)dlsym(RTLD_NEXT, "openat64"); |
302 | 293 | ||
303 | int rv = orig_openat64(dirfd, pathname, flags, mode); | 294 | int rv = orig_openat64(dirfd, pathname, flags, mode); |
304 | printf("%u:%s:openat64 %s:%d\n", pid(), name(), pathname, rv); | 295 | fprintf(ftty, "%u:%s:openat64 %s:%d\n", mypid, myname, pathname, rv); |
305 | return rv; | 296 | return rv; |
306 | } | 297 | } |
307 | 298 | ||
@@ -312,7 +303,7 @@ FILE *fopen(const char *pathname, const char *mode) { | |||
312 | orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); | 303 | orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); |
313 | 304 | ||
314 | FILE *rv = orig_fopen(pathname, mode); | 305 | FILE *rv = orig_fopen(pathname, mode); |
315 | printf("%u:%s:fopen %s:%p\n", pid(), name(), pathname, rv); | 306 | fprintf(ftty, "%u:%s:fopen %s:%p\n", mypid, myname, pathname, rv); |
316 | return rv; | 307 | return rv; |
317 | } | 308 | } |
318 | 309 | ||
@@ -322,7 +313,7 @@ FILE *fopen64(const char *pathname, const char *mode) { | |||
322 | orig_fopen64 = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen64"); | 313 | orig_fopen64 = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen64"); |
323 | 314 | ||
324 | FILE *rv = orig_fopen64(pathname, mode); | 315 | FILE *rv = orig_fopen64(pathname, mode); |
325 | printf("%u:%s:fopen64 %s:%p\n", pid(), name(), pathname, rv); | 316 | fprintf(ftty, "%u:%s:fopen64 %s:%p\n", mypid, myname, pathname, rv); |
326 | return rv; | 317 | return rv; |
327 | } | 318 | } |
328 | #endif /* __GLIBC__ */ | 319 | #endif /* __GLIBC__ */ |
@@ -336,7 +327,7 @@ FILE *freopen(const char *pathname, const char *mode, FILE *stream) { | |||
336 | orig_freopen = (orig_freopen_t)dlsym(RTLD_NEXT, "freopen"); | 327 | orig_freopen = (orig_freopen_t)dlsym(RTLD_NEXT, "freopen"); |
337 | 328 | ||
338 | FILE *rv = orig_freopen(pathname, mode, stream); | 329 | FILE *rv = orig_freopen(pathname, mode, stream); |
339 | printf("%u:%s:freopen %s:%p\n", pid(), name(), pathname, rv); | 330 | fprintf(ftty, "%u:%s:freopen %s:%p\n", mypid, myname, pathname, rv); |
340 | return rv; | 331 | return rv; |
341 | } | 332 | } |
342 | 333 | ||
@@ -348,7 +339,7 @@ FILE *freopen64(const char *pathname, const char *mode, FILE *stream) { | |||
348 | orig_freopen64 = (orig_freopen64_t)dlsym(RTLD_NEXT, "freopen64"); | 339 | orig_freopen64 = (orig_freopen64_t)dlsym(RTLD_NEXT, "freopen64"); |
349 | 340 | ||
350 | FILE *rv = orig_freopen64(pathname, mode, stream); | 341 | FILE *rv = orig_freopen64(pathname, mode, stream); |
351 | printf("%u:%s:freopen64 %s:%p\n", pid(), name(), pathname, rv); | 342 | fprintf(ftty, "%u:%s:freopen64 %s:%p\n", mypid, myname, pathname, rv); |
352 | return rv; | 343 | return rv; |
353 | } | 344 | } |
354 | #endif /* __GLIBC__ */ | 345 | #endif /* __GLIBC__ */ |
@@ -361,7 +352,7 @@ int unlink(const char *pathname) { | |||
361 | orig_unlink = (orig_unlink_t)dlsym(RTLD_NEXT, "unlink"); | 352 | orig_unlink = (orig_unlink_t)dlsym(RTLD_NEXT, "unlink"); |
362 | 353 | ||
363 | int rv = orig_unlink(pathname); | 354 | int rv = orig_unlink(pathname); |
364 | printf("%u:%s:unlink %s:%d\n", pid(), name(), pathname, rv); | 355 | fprintf(ftty, "%u:%s:unlink %s:%d\n", mypid, myname, pathname, rv); |
365 | return rv; | 356 | return rv; |
366 | } | 357 | } |
367 | 358 | ||
@@ -372,7 +363,7 @@ int unlinkat(int dirfd, const char *pathname, int flags) { | |||
372 | orig_unlinkat = (orig_unlinkat_t)dlsym(RTLD_NEXT, "unlinkat"); | 363 | orig_unlinkat = (orig_unlinkat_t)dlsym(RTLD_NEXT, "unlinkat"); |
373 | 364 | ||
374 | int rv = orig_unlinkat(dirfd, pathname, flags); | 365 | int rv = orig_unlinkat(dirfd, pathname, flags); |
375 | printf("%u:%s:unlinkat %s:%d\n", pid(), name(), pathname, rv); | 366 | fprintf(ftty, "%u:%s:unlinkat %s:%d\n", mypid, myname, pathname, rv); |
376 | return rv; | 367 | return rv; |
377 | } | 368 | } |
378 | 369 | ||
@@ -384,7 +375,7 @@ int mkdir(const char *pathname, mode_t mode) { | |||
384 | orig_mkdir = (orig_mkdir_t)dlsym(RTLD_NEXT, "mkdir"); | 375 | orig_mkdir = (orig_mkdir_t)dlsym(RTLD_NEXT, "mkdir"); |
385 | 376 | ||
386 | int rv = orig_mkdir(pathname, mode); | 377 | int rv = orig_mkdir(pathname, mode); |
387 | printf("%u:%s:mkdir %s:%d\n", pid(), name(), pathname, rv); | 378 | fprintf(ftty, "%u:%s:mkdir %s:%d\n", mypid, myname, pathname, rv); |
388 | return rv; | 379 | return rv; |
389 | } | 380 | } |
390 | 381 | ||
@@ -395,7 +386,7 @@ int mkdirat(int dirfd, const char *pathname, mode_t mode) { | |||
395 | orig_mkdirat = (orig_mkdirat_t)dlsym(RTLD_NEXT, "mkdirat"); | 386 | orig_mkdirat = (orig_mkdirat_t)dlsym(RTLD_NEXT, "mkdirat"); |
396 | 387 | ||
397 | int rv = orig_mkdirat(dirfd, pathname, mode); | 388 | int rv = orig_mkdirat(dirfd, pathname, mode); |
398 | printf("%u:%s:mkdirat %s:%d\n", pid(), name(), pathname, rv); | 389 | fprintf(ftty, "%u:%s:mkdirat %s:%d\n", mypid, myname, pathname, rv); |
399 | return rv; | 390 | return rv; |
400 | } | 391 | } |
401 | 392 | ||
@@ -406,56 +397,56 @@ int rmdir(const char *pathname) { | |||
406 | orig_rmdir = (orig_rmdir_t)dlsym(RTLD_NEXT, "rmdir"); | 397 | orig_rmdir = (orig_rmdir_t)dlsym(RTLD_NEXT, "rmdir"); |
407 | 398 | ||
408 | int rv = orig_rmdir(pathname); | 399 | int rv = orig_rmdir(pathname); |
409 | printf("%u:%s:rmdir %s:%d\n", pid(), name(), pathname, rv); | 400 | fprintf(ftty, "%u:%s:rmdir %s:%d\n", mypid, myname, pathname, rv); |
410 | return rv; | 401 | return rv; |
411 | } | 402 | } |
412 | 403 | ||
413 | // stat | 404 | // stat |
414 | typedef int (*orig_stat_t)(const char *pathname, struct stat *buf); | 405 | typedef int (*orig_stat_t)(const char *pathname, struct stat *statbuf); |
415 | static orig_stat_t orig_stat = NULL; | 406 | static orig_stat_t orig_stat = NULL; |
416 | int stat(const char *pathname, struct stat *buf) { | 407 | int stat(const char *pathname, struct stat *statbuf) { |
417 | if (!orig_stat) | 408 | if (!orig_stat) |
418 | orig_stat = (orig_stat_t)dlsym(RTLD_NEXT, "stat"); | 409 | orig_stat = (orig_stat_t)dlsym(RTLD_NEXT, "stat"); |
419 | 410 | ||
420 | int rv = orig_stat(pathname, buf); | 411 | int rv = orig_stat(pathname, statbuf); |
421 | printf("%u:%s:stat %s:%d\n", pid(), name(), pathname, rv); | 412 | fprintf(ftty, "%u:%s:stat %s:%d\n", mypid, myname, pathname, rv); |
422 | return rv; | 413 | return rv; |
423 | } | 414 | } |
424 | 415 | ||
425 | #ifdef __GLIBC__ | 416 | #ifdef __GLIBC__ |
426 | typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *buf); | 417 | typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *statbuf); |
427 | static orig_stat64_t orig_stat64 = NULL; | 418 | static orig_stat64_t orig_stat64 = NULL; |
428 | int stat64(const char *pathname, struct stat64 *buf) { | 419 | int stat64(const char *pathname, struct stat64 *statbuf) { |
429 | if (!orig_stat64) | 420 | if (!orig_stat64) |
430 | orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat64"); | 421 | orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat64"); |
431 | 422 | ||
432 | int rv = orig_stat64(pathname, buf); | 423 | int rv = orig_stat64(pathname, statbuf); |
433 | printf("%u:%s:stat64 %s:%d\n", pid(), name(), pathname, rv); | 424 | fprintf(ftty, "%u:%s:stat64 %s:%d\n", mypid, myname, pathname, rv); |
434 | return rv; | 425 | return rv; |
435 | } | 426 | } |
436 | #endif /* __GLIBC__ */ | 427 | #endif /* __GLIBC__ */ |
437 | 428 | ||
438 | // lstat | 429 | // lstat |
439 | typedef int (*orig_lstat_t)(const char *pathname, struct stat *buf); | 430 | typedef int (*orig_lstat_t)(const char *pathname, struct stat *statbuf); |
440 | static orig_lstat_t orig_lstat = NULL; | 431 | static orig_lstat_t orig_lstat = NULL; |
441 | int lstat(const char *pathname, struct stat *buf) { | 432 | int lstat(const char *pathname, struct stat *statbuf) { |
442 | if (!orig_lstat) | 433 | if (!orig_lstat) |
443 | orig_lstat = (orig_lstat_t)dlsym(RTLD_NEXT, "lstat"); | 434 | orig_lstat = (orig_lstat_t)dlsym(RTLD_NEXT, "lstat"); |
444 | 435 | ||
445 | int rv = orig_lstat(pathname, buf); | 436 | int rv = orig_lstat(pathname, statbuf); |
446 | printf("%u:%s:lstat %s:%d\n", pid(), name(), pathname, rv); | 437 | fprintf(ftty, "%u:%s:lstat %s:%d\n", mypid, myname, pathname, rv); |
447 | return rv; | 438 | return rv; |
448 | } | 439 | } |
449 | 440 | ||
450 | #ifdef __GLIBC__ | 441 | #ifdef __GLIBC__ |
451 | typedef int (*orig_lstat64_t)(const char *pathname, struct stat64 *buf); | 442 | typedef int (*orig_lstat64_t)(const char *pathname, struct stat64 *statbuf); |
452 | static orig_lstat64_t orig_lstat64 = NULL; | 443 | static orig_lstat64_t orig_lstat64 = NULL; |
453 | int lstat64(const char *pathname, struct stat64 *buf) { | 444 | int lstat64(const char *pathname, struct stat64 *statbuf) { |
454 | if (!orig_lstat64) | 445 | if (!orig_lstat64) |
455 | orig_lstat64 = (orig_lstat64_t)dlsym(RTLD_NEXT, "lstat64"); | 446 | orig_lstat64 = (orig_lstat64_t)dlsym(RTLD_NEXT, "lstat64"); |
456 | 447 | ||
457 | int rv = orig_lstat64(pathname, buf); | 448 | int rv = orig_lstat64(pathname, statbuf); |
458 | printf("%u:%s:lstat64 %s:%d\n", pid(), name(), pathname, rv); | 449 | fprintf(ftty, "%u:%s:lstat64 %s:%d\n", mypid, myname, pathname, rv); |
459 | return rv; | 450 | return rv; |
460 | } | 451 | } |
461 | #endif /* __GLIBC__ */ | 452 | #endif /* __GLIBC__ */ |
@@ -468,7 +459,7 @@ DIR *opendir(const char *pathname) { | |||
468 | orig_opendir = (orig_opendir_t)dlsym(RTLD_NEXT, "opendir"); | 459 | orig_opendir = (orig_opendir_t)dlsym(RTLD_NEXT, "opendir"); |
469 | 460 | ||
470 | DIR *rv = orig_opendir(pathname); | 461 | DIR *rv = orig_opendir(pathname); |
471 | printf("%u:%s:opendir %s:%p\n", pid(), name(), pathname, rv); | 462 | fprintf(ftty, "%u:%s:opendir %s:%p\n", mypid, myname, pathname, rv); |
472 | return rv; | 463 | return rv; |
473 | } | 464 | } |
474 | 465 | ||
@@ -480,7 +471,7 @@ int access(const char *pathname, int mode) { | |||
480 | orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); | 471 | orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); |
481 | 472 | ||
482 | int rv = orig_access(pathname, mode); | 473 | int rv = orig_access(pathname, mode); |
483 | printf("%u:%s:access %s:%d\n", pid(), name(), pathname, rv); | 474 | fprintf(ftty, "%u:%s:access %s:%d\n", mypid, myname, pathname, rv); |
484 | return rv; | 475 | return rv; |
485 | } | 476 | } |
486 | 477 | ||
@@ -501,14 +492,14 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { | |||
501 | // socket | 492 | // socket |
502 | typedef int (*orig_socket_t)(int domain, int type, int protocol); | 493 | typedef int (*orig_socket_t)(int domain, int type, int protocol); |
503 | static orig_socket_t orig_socket = NULL; | 494 | static orig_socket_t orig_socket = NULL; |
504 | static char buf[1024]; | 495 | static char socketbuf[1024]; |
505 | int socket(int domain, int type, int protocol) { | 496 | int socket(int domain, int type, int protocol) { |
506 | if (!orig_socket) | 497 | if (!orig_socket) |
507 | orig_socket = (orig_socket_t)dlsym(RTLD_NEXT, "socket"); | 498 | orig_socket = (orig_socket_t)dlsym(RTLD_NEXT, "socket"); |
508 | 499 | ||
509 | int rv = orig_socket(domain, type, protocol); | 500 | int rv = orig_socket(domain, type, protocol); |
510 | char *ptr = buf; | 501 | char *ptr = socketbuf; |
511 | ptr += sprintf(ptr, "%u:%s:socket ", pid(), name()); | 502 | ptr += sprintf(ptr, "%u:%s:socket ", mypid, myname); |
512 | char *str = translate(socket_domain, domain); | 503 | char *str = translate(socket_domain, domain); |
513 | if (str == NULL) | 504 | if (str == NULL) |
514 | ptr += sprintf(ptr, "%d ", domain); | 505 | ptr += sprintf(ptr, "%d ", domain); |
@@ -538,7 +529,7 @@ int socket(int domain, int type, int protocol) { | |||
538 | sprintf(ptr, "%s", str); | 529 | sprintf(ptr, "%s", str); |
539 | } | 530 | } |
540 | 531 | ||
541 | printf("%s:%d\n", buf, rv); | 532 | fprintf(ftty, "%s:%d\n", socketbuf, rv); |
542 | return rv; | 533 | return rv; |
543 | } | 534 | } |
544 | 535 | ||
@@ -576,7 +567,7 @@ int system(const char *command) { | |||
576 | orig_system = (orig_system_t)dlsym(RTLD_NEXT, "system"); | 567 | orig_system = (orig_system_t)dlsym(RTLD_NEXT, "system"); |
577 | 568 | ||
578 | int rv = orig_system(command); | 569 | int rv = orig_system(command); |
579 | printf("%u:%s:system %s:%d\n", pid(), name(), command, rv); | 570 | fprintf(ftty, "%u:%s:system %s:%d\n", mypid, myname, command, rv); |
580 | 571 | ||
581 | return rv; | 572 | return rv; |
582 | } | 573 | } |
@@ -588,7 +579,7 @@ int setuid(uid_t uid) { | |||
588 | orig_setuid = (orig_setuid_t)dlsym(RTLD_NEXT, "setuid"); | 579 | orig_setuid = (orig_setuid_t)dlsym(RTLD_NEXT, "setuid"); |
589 | 580 | ||
590 | int rv = orig_setuid(uid); | 581 | int rv = orig_setuid(uid); |
591 | printf("%u:%s:setuid %d:%d\n", pid(), name(), uid, rv); | 582 | fprintf(ftty, "%u:%s:setuid %d:%d\n", mypid, myname, uid, rv); |
592 | 583 | ||
593 | return rv; | 584 | return rv; |
594 | } | 585 | } |
@@ -600,7 +591,7 @@ int setgid(gid_t gid) { | |||
600 | orig_setgid = (orig_setgid_t)dlsym(RTLD_NEXT, "setgid"); | 591 | orig_setgid = (orig_setgid_t)dlsym(RTLD_NEXT, "setgid"); |
601 | 592 | ||
602 | int rv = orig_setgid(gid); | 593 | int rv = orig_setgid(gid); |
603 | printf("%u:%s:setgid %d:%d\n", pid(), name(), gid, rv); | 594 | fprintf(ftty, "%u:%s:setgid %d:%d\n", mypid, myname, gid, rv); |
604 | 595 | ||
605 | return rv; | 596 | return rv; |
606 | } | 597 | } |
@@ -612,7 +603,7 @@ int setfsuid(uid_t uid) { | |||
612 | orig_setfsuid = (orig_setfsuid_t)dlsym(RTLD_NEXT, "setfsuid"); | 603 | orig_setfsuid = (orig_setfsuid_t)dlsym(RTLD_NEXT, "setfsuid"); |
613 | 604 | ||
614 | int rv = orig_setfsuid(uid); | 605 | int rv = orig_setfsuid(uid); |
615 | printf("%u:%s:setfsuid %d:%d\n", pid(), name(), uid, rv); | 606 | fprintf(ftty, "%u:%s:setfsuid %d:%d\n", mypid, myname, uid, rv); |
616 | 607 | ||
617 | return rv; | 608 | return rv; |
618 | } | 609 | } |
@@ -624,7 +615,7 @@ int setfsgid(gid_t gid) { | |||
624 | orig_setfsgid = (orig_setfsgid_t)dlsym(RTLD_NEXT, "setfsgid"); | 615 | orig_setfsgid = (orig_setfsgid_t)dlsym(RTLD_NEXT, "setfsgid"); |
625 | 616 | ||
626 | int rv = orig_setfsgid(gid); | 617 | int rv = orig_setfsgid(gid); |
627 | printf("%u:%s:setfsgid %d:%d\n", pid(), name(), gid, rv); | 618 | fprintf(ftty, "%u:%s:setfsgid %d:%d\n", mypid, myname, gid, rv); |
628 | 619 | ||
629 | return rv; | 620 | return rv; |
630 | } | 621 | } |
@@ -636,7 +627,7 @@ int setreuid(uid_t ruid, uid_t euid) { | |||
636 | orig_setreuid = (orig_setreuid_t)dlsym(RTLD_NEXT, "setreuid"); | 627 | orig_setreuid = (orig_setreuid_t)dlsym(RTLD_NEXT, "setreuid"); |
637 | 628 | ||
638 | int rv = orig_setreuid(ruid, euid); | 629 | int rv = orig_setreuid(ruid, euid); |
639 | printf("%u:%s:setreuid %d %d:%d\n", pid(), name(), ruid, euid, rv); | 630 | fprintf(ftty, "%u:%s:setreuid %d %d:%d\n", mypid, myname, ruid, euid, rv); |
640 | 631 | ||
641 | return rv; | 632 | return rv; |
642 | } | 633 | } |
@@ -648,7 +639,7 @@ int setregid(gid_t rgid, gid_t egid) { | |||
648 | orig_setregid = (orig_setregid_t)dlsym(RTLD_NEXT, "setregid"); | 639 | orig_setregid = (orig_setregid_t)dlsym(RTLD_NEXT, "setregid"); |
649 | 640 | ||
650 | int rv = orig_setregid(rgid, egid); | 641 | int rv = orig_setregid(rgid, egid); |
651 | printf("%u:%s:setregid %d %d:%d\n", pid(), name(), rgid, egid, rv); | 642 | fprintf(ftty, "%u:%s:setregid %d %d:%d\n", mypid, myname, rgid, egid, rv); |
652 | 643 | ||
653 | return rv; | 644 | return rv; |
654 | } | 645 | } |
@@ -660,7 +651,7 @@ int setresuid(uid_t ruid, uid_t euid, uid_t suid) { | |||
660 | orig_setresuid = (orig_setresuid_t)dlsym(RTLD_NEXT, "setresuid"); | 651 | orig_setresuid = (orig_setresuid_t)dlsym(RTLD_NEXT, "setresuid"); |
661 | 652 | ||
662 | int rv = orig_setresuid(ruid, euid, suid); | 653 | int rv = orig_setresuid(ruid, euid, suid); |
663 | printf("%u:%s:setresuid %d %d %d:%d\n", pid(), name(), ruid, euid, suid, rv); | 654 | fprintf(ftty, "%u:%s:setresuid %d %d %d:%d\n", mypid, myname, ruid, euid, suid, rv); |
664 | 655 | ||
665 | return rv; | 656 | return rv; |
666 | } | 657 | } |
@@ -672,7 +663,7 @@ int setresgid(gid_t rgid, gid_t egid, gid_t sgid) { | |||
672 | orig_setresgid = (orig_setresgid_t)dlsym(RTLD_NEXT, "setresgid"); | 663 | orig_setresgid = (orig_setresgid_t)dlsym(RTLD_NEXT, "setresgid"); |
673 | 664 | ||
674 | int rv = orig_setresgid(rgid, egid, sgid); | 665 | int rv = orig_setresgid(rgid, egid, sgid); |
675 | printf("%u:%s:setresgid %d %d %d:%d\n", pid(), name(), rgid, egid, sgid, rv); | 666 | fprintf(ftty, "%u:%s:setresgid %d %d %d:%d\n", mypid, myname, rgid, egid, sgid, rv); |
676 | 667 | ||
677 | return rv; | 668 | return rv; |
678 | } | 669 | } |
@@ -687,6 +678,6 @@ static void log_exec(int argc, char** argv) { | |||
687 | int rv = readlink("/proc/self/exe", buf, PATH_MAX); | 678 | int rv = readlink("/proc/self/exe", buf, PATH_MAX); |
688 | if (rv != -1) { | 679 | if (rv != -1) { |
689 | buf[rv] = '\0'; // readlink does not add a '\0' at the end | 680 | buf[rv] = '\0'; // readlink does not add a '\0' at the end |
690 | printf("%u:%s:exec %s:0\n", pid(), name(), buf); | 681 | fprintf(ftty, "%u:%s:exec %s:0\n", mypid, myname, buf); |
691 | } | 682 | } |
692 | } | 683 | } |