diff options
Diffstat (limited to 'src/libtracelog/libtracelog.c')
-rw-r--r-- | src/libtracelog/libtracelog.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/libtracelog/libtracelog.c b/src/libtracelog/libtracelog.c index d89998f61..ba8bdefeb 100644 --- a/src/libtracelog/libtracelog.c +++ b/src/libtracelog/libtracelog.c | |||
@@ -63,6 +63,9 @@ static inline uint32_t hash(const char *str) { | |||
63 | } | 63 | } |
64 | 64 | ||
65 | static void storage_add(const char *str) { | 65 | static void storage_add(const char *str) { |
66 | #ifdef DEBUG | ||
67 | printf("add %s\n", str); | ||
68 | #endif | ||
66 | ListElem *ptr = malloc(sizeof(ListElem)); | 69 | ListElem *ptr = malloc(sizeof(ListElem)); |
67 | if (!ptr) { | 70 | if (!ptr) { |
68 | fprintf(stderr, "Error: cannot allocate memory\n"); | 71 | fprintf(stderr, "Error: cannot allocate memory\n"); |
@@ -82,11 +85,20 @@ static void storage_add(const char *str) { | |||
82 | } | 85 | } |
83 | 86 | ||
84 | static char *storage_find(const char *str) { | 87 | static char *storage_find(const char *str) { |
88 | #ifdef DEBUG | ||
89 | printf("storage find %s\n", str); | ||
90 | #endif | ||
85 | const char *tofind = str; | 91 | const char *tofind = str; |
86 | int allocated = 0; | 92 | int allocated = 0; |
87 | 93 | ||
88 | if (strstr(str, "..") || strstr(str, "/./")) { | 94 | if (strstr(str, "..") || strstr(str, "/./")) { |
89 | tofind = realpath(str, NULL); | 95 | tofind = realpath(str, NULL); |
96 | if (!tofind) { | ||
97 | #ifdef DEBUG | ||
98 | printf("realpath failed\n"); | ||
99 | #endif | ||
100 | return NULL; | ||
101 | } | ||
90 | allocated = 1; | 102 | allocated = 1; |
91 | } | 103 | } |
92 | 104 | ||
@@ -96,6 +108,9 @@ static char *storage_find(const char *str) { | |||
96 | if (strcmp(tofind, ptr->path) == 0) { | 108 | if (strcmp(tofind, ptr->path) == 0) { |
97 | if (allocated) | 109 | if (allocated) |
98 | free((char *) tofind); | 110 | free((char *) tofind); |
111 | #ifdef DEBUG | ||
112 | printf("storage found\n"); | ||
113 | #endif | ||
99 | return ptr->path; | 114 | return ptr->path; |
100 | } | 115 | } |
101 | ptr = ptr->next; | 116 | ptr = ptr->next; |
@@ -103,6 +118,9 @@ static char *storage_find(const char *str) { | |||
103 | 118 | ||
104 | if (allocated) | 119 | if (allocated) |
105 | free((char *) tofind); | 120 | free((char *) tofind); |
121 | #ifdef DEBUG | ||
122 | printf("storage not found\n"); | ||
123 | #endif | ||
106 | return NULL; | 124 | return NULL; |
107 | } | 125 | } |
108 | 126 | ||
@@ -249,6 +267,9 @@ static char *name(void) { | |||
249 | typedef int (*orig_open_t)(const char *pathname, int flags, mode_t mode); | 267 | typedef int (*orig_open_t)(const char *pathname, int flags, mode_t mode); |
250 | static orig_open_t orig_open = NULL; | 268 | static orig_open_t orig_open = NULL; |
251 | int open(const char *pathname, int flags, mode_t mode) { | 269 | int open(const char *pathname, int flags, mode_t mode) { |
270 | #ifdef DEBUG | ||
271 | printf("%s\n", __FUNCTION__); | ||
272 | #endif | ||
252 | if (!orig_open) | 273 | if (!orig_open) |
253 | orig_open = (orig_open_t)dlsym(RTLD_NEXT, "open"); | 274 | orig_open = (orig_open_t)dlsym(RTLD_NEXT, "open"); |
254 | 275 | ||
@@ -261,9 +282,16 @@ int open(const char *pathname, int flags, mode_t mode) { | |||
261 | return rv; | 282 | return rv; |
262 | } | 283 | } |
263 | 284 | ||
285 | |||
286 | |||
287 | |||
288 | //#if 0 - todo: fix problems on google-chrome and opera - seems to be crashing when open64 is called | ||
264 | typedef int (*orig_open64_t)(const char *pathname, int flags, mode_t mode); | 289 | typedef int (*orig_open64_t)(const char *pathname, int flags, mode_t mode); |
265 | static orig_open64_t orig_open64 = NULL; | 290 | static orig_open64_t orig_open64 = NULL; |
266 | int open64(const char *pathname, int flags, mode_t mode) { | 291 | int open64(const char *pathname, int flags, mode_t mode) { |
292 | #ifdef DEBUG | ||
293 | printf("%s %s\n", __FUNCTION__, pathname); | ||
294 | #endif | ||
267 | if (!orig_open64) | 295 | if (!orig_open64) |
268 | orig_open64 = (orig_open64_t)dlsym(RTLD_NEXT, "open64"); | 296 | orig_open64 = (orig_open64_t)dlsym(RTLD_NEXT, "open64"); |
269 | if (!blacklist_loaded) | 297 | if (!blacklist_loaded) |
@@ -274,11 +302,16 @@ int open64(const char *pathname, int flags, mode_t mode) { | |||
274 | sendlog(name(), __FUNCTION__, pathname); | 302 | sendlog(name(), __FUNCTION__, pathname); |
275 | return rv; | 303 | return rv; |
276 | } | 304 | } |
305 | //#endif | ||
306 | |||
277 | 307 | ||
278 | // openat | 308 | // openat |
279 | typedef int (*orig_openat_t)(int dirfd, const char *pathname, int flags, mode_t mode); | 309 | typedef int (*orig_openat_t)(int dirfd, const char *pathname, int flags, mode_t mode); |
280 | static orig_openat_t orig_openat = NULL; | 310 | static orig_openat_t orig_openat = NULL; |
281 | int openat(int dirfd, const char *pathname, int flags, mode_t mode) { | 311 | int openat(int dirfd, const char *pathname, int flags, mode_t mode) { |
312 | #ifdef DEBUG | ||
313 | printf("%s\n", __FUNCTION__); | ||
314 | #endif | ||
282 | if (!orig_openat) | 315 | if (!orig_openat) |
283 | orig_openat = (orig_openat_t)dlsym(RTLD_NEXT, "openat"); | 316 | orig_openat = (orig_openat_t)dlsym(RTLD_NEXT, "openat"); |
284 | if (!blacklist_loaded) | 317 | if (!blacklist_loaded) |
@@ -293,6 +326,9 @@ int openat(int dirfd, const char *pathname, int flags, mode_t mode) { | |||
293 | typedef int (*orig_openat64_t)(int dirfd, const char *pathname, int flags, mode_t mode); | 326 | typedef int (*orig_openat64_t)(int dirfd, const char *pathname, int flags, mode_t mode); |
294 | static orig_openat64_t orig_openat64 = NULL; | 327 | static orig_openat64_t orig_openat64 = NULL; |
295 | int openat64(int dirfd, const char *pathname, int flags, mode_t mode) { | 328 | int openat64(int dirfd, const char *pathname, int flags, mode_t mode) { |
329 | #ifdef DEBUG | ||
330 | printf("%s\n", __FUNCTION__); | ||
331 | #endif | ||
296 | if (!orig_openat64) | 332 | if (!orig_openat64) |
297 | orig_openat64 = (orig_openat64_t)dlsym(RTLD_NEXT, "openat64"); | 333 | orig_openat64 = (orig_openat64_t)dlsym(RTLD_NEXT, "openat64"); |
298 | if (!blacklist_loaded) | 334 | if (!blacklist_loaded) |
@@ -307,6 +343,9 @@ int openat64(int dirfd, const char *pathname, int flags, mode_t mode) { | |||
307 | 343 | ||
308 | // fopen | 344 | // fopen |
309 | FILE *fopen(const char *pathname, const char *mode) { | 345 | FILE *fopen(const char *pathname, const char *mode) { |
346 | #ifdef DEBUG | ||
347 | printf("%s\n", __FUNCTION__); | ||
348 | #endif | ||
310 | if (!orig_fopen) | 349 | if (!orig_fopen) |
311 | orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); | 350 | orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); |
312 | if (!blacklist_loaded) | 351 | if (!blacklist_loaded) |
@@ -320,6 +359,9 @@ FILE *fopen(const char *pathname, const char *mode) { | |||
320 | 359 | ||
321 | #ifdef __GLIBC__ | 360 | #ifdef __GLIBC__ |
322 | FILE *fopen64(const char *pathname, const char *mode) { | 361 | FILE *fopen64(const char *pathname, const char *mode) { |
362 | #ifdef DEBUG | ||
363 | printf("%s\n", __FUNCTION__); | ||
364 | #endif | ||
323 | if (!orig_fopen64) | 365 | if (!orig_fopen64) |
324 | orig_fopen64 = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen64"); | 366 | orig_fopen64 = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen64"); |
325 | if (!blacklist_loaded) | 367 | if (!blacklist_loaded) |
@@ -337,6 +379,9 @@ FILE *fopen64(const char *pathname, const char *mode) { | |||
337 | typedef FILE *(*orig_freopen_t)(const char *pathname, const char *mode, FILE *stream); | 379 | typedef FILE *(*orig_freopen_t)(const char *pathname, const char *mode, FILE *stream); |
338 | static orig_freopen_t orig_freopen = NULL; | 380 | static orig_freopen_t orig_freopen = NULL; |
339 | FILE *freopen(const char *pathname, const char *mode, FILE *stream) { | 381 | FILE *freopen(const char *pathname, const char *mode, FILE *stream) { |
382 | #ifdef DEBUG | ||
383 | printf("%s\n", __FUNCTION__); | ||
384 | #endif | ||
340 | if (!orig_freopen) | 385 | if (!orig_freopen) |
341 | orig_freopen = (orig_freopen_t)dlsym(RTLD_NEXT, "freopen"); | 386 | orig_freopen = (orig_freopen_t)dlsym(RTLD_NEXT, "freopen"); |
342 | if (!blacklist_loaded) | 387 | if (!blacklist_loaded) |
@@ -352,6 +397,9 @@ FILE *freopen(const char *pathname, const char *mode, FILE *stream) { | |||
352 | typedef FILE *(*orig_freopen64_t)(const char *pathname, const char *mode, FILE *stream); | 397 | typedef FILE *(*orig_freopen64_t)(const char *pathname, const char *mode, FILE *stream); |
353 | static orig_freopen64_t orig_freopen64 = NULL; | 398 | static orig_freopen64_t orig_freopen64 = NULL; |
354 | FILE *freopen64(const char *pathname, const char *mode, FILE *stream) { | 399 | FILE *freopen64(const char *pathname, const char *mode, FILE *stream) { |
400 | #ifdef DEBUG | ||
401 | printf("%s\n", __FUNCTION__); | ||
402 | #endif | ||
355 | if (!orig_freopen64) | 403 | if (!orig_freopen64) |
356 | orig_freopen64 = (orig_freopen64_t)dlsym(RTLD_NEXT, "freopen64"); | 404 | orig_freopen64 = (orig_freopen64_t)dlsym(RTLD_NEXT, "freopen64"); |
357 | if (!blacklist_loaded) | 405 | if (!blacklist_loaded) |
@@ -368,6 +416,9 @@ FILE *freopen64(const char *pathname, const char *mode, FILE *stream) { | |||
368 | typedef int (*orig_unlink_t)(const char *pathname); | 416 | typedef int (*orig_unlink_t)(const char *pathname); |
369 | static orig_unlink_t orig_unlink = NULL; | 417 | static orig_unlink_t orig_unlink = NULL; |
370 | int unlink(const char *pathname) { | 418 | int unlink(const char *pathname) { |
419 | #ifdef DEBUG | ||
420 | printf("%s\n", __FUNCTION__); | ||
421 | #endif | ||
371 | if (!orig_unlink) | 422 | if (!orig_unlink) |
372 | orig_unlink = (orig_unlink_t)dlsym(RTLD_NEXT, "unlink"); | 423 | orig_unlink = (orig_unlink_t)dlsym(RTLD_NEXT, "unlink"); |
373 | if (!blacklist_loaded) | 424 | if (!blacklist_loaded) |
@@ -382,6 +433,9 @@ int unlink(const char *pathname) { | |||
382 | typedef int (*orig_unlinkat_t)(int dirfd, const char *pathname, int flags); | 433 | typedef int (*orig_unlinkat_t)(int dirfd, const char *pathname, int flags); |
383 | static orig_unlinkat_t orig_unlinkat = NULL; | 434 | static orig_unlinkat_t orig_unlinkat = NULL; |
384 | int unlinkat(int dirfd, const char *pathname, int flags) { | 435 | int unlinkat(int dirfd, const char *pathname, int flags) { |
436 | #ifdef DEBUG | ||
437 | printf("%s\n", __FUNCTION__); | ||
438 | #endif | ||
385 | if (!orig_unlinkat) | 439 | if (!orig_unlinkat) |
386 | orig_unlinkat = (orig_unlinkat_t)dlsym(RTLD_NEXT, "unlinkat"); | 440 | orig_unlinkat = (orig_unlinkat_t)dlsym(RTLD_NEXT, "unlinkat"); |
387 | if (!blacklist_loaded) | 441 | if (!blacklist_loaded) |
@@ -397,6 +451,9 @@ int unlinkat(int dirfd, const char *pathname, int flags) { | |||
397 | typedef int (*orig_mkdir_t)(const char *pathname, mode_t mode); | 451 | typedef int (*orig_mkdir_t)(const char *pathname, mode_t mode); |
398 | static orig_mkdir_t orig_mkdir = NULL; | 452 | static orig_mkdir_t orig_mkdir = NULL; |
399 | int mkdir(const char *pathname, mode_t mode) { | 453 | int mkdir(const char *pathname, mode_t mode) { |
454 | #ifdef DEBUG | ||
455 | printf("%s\n", __FUNCTION__); | ||
456 | #endif | ||
400 | if (!orig_mkdir) | 457 | if (!orig_mkdir) |
401 | orig_mkdir = (orig_mkdir_t)dlsym(RTLD_NEXT, "mkdir"); | 458 | orig_mkdir = (orig_mkdir_t)dlsym(RTLD_NEXT, "mkdir"); |
402 | if (!blacklist_loaded) | 459 | if (!blacklist_loaded) |
@@ -411,6 +468,9 @@ int mkdir(const char *pathname, mode_t mode) { | |||
411 | typedef int (*orig_mkdirat_t)(int dirfd, const char *pathname, mode_t mode); | 468 | typedef int (*orig_mkdirat_t)(int dirfd, const char *pathname, mode_t mode); |
412 | static orig_mkdirat_t orig_mkdirat = NULL; | 469 | static orig_mkdirat_t orig_mkdirat = NULL; |
413 | int mkdirat(int dirfd, const char *pathname, mode_t mode) { | 470 | int mkdirat(int dirfd, const char *pathname, mode_t mode) { |
471 | #ifdef DEBUG | ||
472 | printf("%s\n", __FUNCTION__); | ||
473 | #endif | ||
414 | if (!orig_mkdirat) | 474 | if (!orig_mkdirat) |
415 | orig_mkdirat = (orig_mkdirat_t)dlsym(RTLD_NEXT, "mkdirat"); | 475 | orig_mkdirat = (orig_mkdirat_t)dlsym(RTLD_NEXT, "mkdirat"); |
416 | if (!blacklist_loaded) | 476 | if (!blacklist_loaded) |
@@ -425,6 +485,9 @@ int mkdirat(int dirfd, const char *pathname, mode_t mode) { | |||
425 | typedef int (*orig_rmdir_t)(const char *pathname); | 485 | typedef int (*orig_rmdir_t)(const char *pathname); |
426 | static orig_rmdir_t orig_rmdir = NULL; | 486 | static orig_rmdir_t orig_rmdir = NULL; |
427 | int rmdir(const char *pathname) { | 487 | int rmdir(const char *pathname) { |
488 | #ifdef DEBUG | ||
489 | printf("%s\n", __FUNCTION__); | ||
490 | #endif | ||
428 | if (!orig_rmdir) | 491 | if (!orig_rmdir) |
429 | orig_rmdir = (orig_rmdir_t)dlsym(RTLD_NEXT, "rmdir"); | 492 | orig_rmdir = (orig_rmdir_t)dlsym(RTLD_NEXT, "rmdir"); |
430 | if (!blacklist_loaded) | 493 | if (!blacklist_loaded) |
@@ -440,6 +503,9 @@ int rmdir(const char *pathname) { | |||
440 | typedef int (*orig_stat_t)(const char *pathname, struct stat *buf); | 503 | typedef int (*orig_stat_t)(const char *pathname, struct stat *buf); |
441 | static orig_stat_t orig_stat = NULL; | 504 | static orig_stat_t orig_stat = NULL; |
442 | int stat(const char *pathname, struct stat *buf) { | 505 | int stat(const char *pathname, struct stat *buf) { |
506 | #ifdef DEBUG | ||
507 | printf("%s\n", __FUNCTION__); | ||
508 | #endif | ||
443 | if (!orig_stat) | 509 | if (!orig_stat) |
444 | orig_stat = (orig_stat_t)dlsym(RTLD_NEXT, "stat"); | 510 | orig_stat = (orig_stat_t)dlsym(RTLD_NEXT, "stat"); |
445 | if (!blacklist_loaded) | 511 | if (!blacklist_loaded) |
@@ -455,6 +521,9 @@ int stat(const char *pathname, struct stat *buf) { | |||
455 | typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *buf); | 521 | typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *buf); |
456 | static orig_stat64_t orig_stat64 = NULL; | 522 | static orig_stat64_t orig_stat64 = NULL; |
457 | int stat64(const char *pathname, struct stat64 *buf) { | 523 | int stat64(const char *pathname, struct stat64 *buf) { |
524 | #ifdef DEBUG | ||
525 | printf("%s\n", __FUNCTION__); | ||
526 | #endif | ||
458 | if (!orig_stat) | 527 | if (!orig_stat) |
459 | orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat64"); | 528 | orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat64"); |
460 | if (!blacklist_loaded) | 529 | if (!blacklist_loaded) |
@@ -470,6 +539,9 @@ int stat64(const char *pathname, struct stat64 *buf) { | |||
470 | typedef int (*orig_lstat_t)(const char *pathname, struct stat *buf); | 539 | typedef int (*orig_lstat_t)(const char *pathname, struct stat *buf); |
471 | static orig_lstat_t orig_lstat = NULL; | 540 | static orig_lstat_t orig_lstat = NULL; |
472 | int lstat(const char *pathname, struct stat *buf) { | 541 | int lstat(const char *pathname, struct stat *buf) { |
542 | #ifdef DEBUG | ||
543 | printf("%s\n", __FUNCTION__); | ||
544 | #endif | ||
473 | if (!orig_lstat) | 545 | if (!orig_lstat) |
474 | orig_lstat = (orig_lstat_t)dlsym(RTLD_NEXT, "lstat"); | 546 | orig_lstat = (orig_lstat_t)dlsym(RTLD_NEXT, "lstat"); |
475 | if (!blacklist_loaded) | 547 | if (!blacklist_loaded) |
@@ -485,6 +557,9 @@ int lstat(const char *pathname, struct stat *buf) { | |||
485 | typedef int (*orig_lstat64_t)(const char *pathname, struct stat64 *buf); | 557 | typedef int (*orig_lstat64_t)(const char *pathname, struct stat64 *buf); |
486 | static orig_lstat64_t orig_lstat64 = NULL; | 558 | static orig_lstat64_t orig_lstat64 = NULL; |
487 | int lstat64(const char *pathname, struct stat64 *buf) { | 559 | int lstat64(const char *pathname, struct stat64 *buf) { |
560 | #ifdef DEBUG | ||
561 | printf("%s\n", __FUNCTION__); | ||
562 | #endif | ||
488 | if (!orig_lstat) | 563 | if (!orig_lstat) |
489 | orig_lstat64 = (orig_lstat64_t)dlsym(RTLD_NEXT, "lstat64"); | 564 | orig_lstat64 = (orig_lstat64_t)dlsym(RTLD_NEXT, "lstat64"); |
490 | if (!blacklist_loaded) | 565 | if (!blacklist_loaded) |
@@ -501,6 +576,9 @@ int lstat64(const char *pathname, struct stat64 *buf) { | |||
501 | typedef int (*orig_access_t)(const char *pathname, int mode); | 576 | typedef int (*orig_access_t)(const char *pathname, int mode); |
502 | static orig_access_t orig_access = NULL; | 577 | static orig_access_t orig_access = NULL; |
503 | int access(const char *pathname, int mode) { | 578 | int access(const char *pathname, int mode) { |
579 | #ifdef DEBUG | ||
580 | printf("%s\n", __FUNCTION__); | ||
581 | #endif | ||
504 | if (!orig_access) | 582 | if (!orig_access) |
505 | orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); | 583 | orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); |
506 | if (!blacklist_loaded) | 584 | if (!blacklist_loaded) |
@@ -516,6 +594,9 @@ int access(const char *pathname, int mode) { | |||
516 | typedef DIR *(*orig_opendir_t)(const char *pathname); | 594 | typedef DIR *(*orig_opendir_t)(const char *pathname); |
517 | static orig_opendir_t orig_opendir = NULL; | 595 | static orig_opendir_t orig_opendir = NULL; |
518 | DIR *opendir(const char *pathname) { | 596 | DIR *opendir(const char *pathname) { |
597 | #ifdef DEBUG | ||
598 | printf("%s\n", __FUNCTION__); | ||
599 | #endif | ||
519 | if (!orig_opendir) | 600 | if (!orig_opendir) |
520 | orig_opendir = (orig_opendir_t)dlsym(RTLD_NEXT, "opendir"); | 601 | orig_opendir = (orig_opendir_t)dlsym(RTLD_NEXT, "opendir"); |
521 | if (!blacklist_loaded) | 602 | if (!blacklist_loaded) |