aboutsummaryrefslogtreecommitdiffstats
path: root/src/libtrace/libtrace.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libtrace/libtrace.c')
-rw-r--r--src/libtrace/libtrace.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/libtrace/libtrace.c b/src/libtrace/libtrace.c
index 2ce74d331..12a8c7f4a 100644
--- a/src/libtrace/libtrace.c
+++ b/src/libtrace/libtrace.c
@@ -18,11 +18,7 @@
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/ 19*/
20#define _GNU_SOURCE 20#define _GNU_SOURCE
21#ifdef HAVE_MUSL_LIBC
22#include "musl_defs.h"
23#else
24#include <stdio.h> 21#include <stdio.h>
25#endif
26#include <stdlib.h> 22#include <stdlib.h>
27#include <string.h> 23#include <string.h>
28#include <dlfcn.h> 24#include <dlfcn.h>
@@ -32,9 +28,7 @@
32#include <netinet/in.h> 28#include <netinet/in.h>
33#include <arpa/inet.h> 29#include <arpa/inet.h>
34#include <sys/un.h> 30#include <sys/un.h>
35#ifndef HAVE_MUSL_LIBC
36#include <sys/stat.h> 31#include <sys/stat.h>
37#endif
38 32
39// break recursivity on fopen call 33// break recursivity on fopen call
40typedef FILE *(*orig_fopen_t)(const char *pathname, const char *mode); 34typedef FILE *(*orig_fopen_t)(const char *pathname, const char *mode);
@@ -318,6 +312,7 @@ FILE *fopen(const char *pathname, const char *mode) {
318 return rv; 312 return rv;
319} 313}
320 314
315#ifdef __GLIBC__
321FILE *fopen64(const char *pathname, const char *mode) { 316FILE *fopen64(const char *pathname, const char *mode) {
322 if (!orig_fopen64) 317 if (!orig_fopen64)
323 orig_fopen64 = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen64"); 318 orig_fopen64 = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen64");
@@ -326,6 +321,7 @@ FILE *fopen64(const char *pathname, const char *mode) {
326 printf("%u:%s:fopen64 %s\n", pid(), name(), pathname); 321 printf("%u:%s:fopen64 %s\n", pid(), name(), pathname);
327 return rv; 322 return rv;
328} 323}
324#endif /* __GLIBC__ */
329 325
330 326
331// freopen 327// freopen
@@ -340,6 +336,7 @@ FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
340 return rv; 336 return rv;
341} 337}
342 338
339#ifdef __GLIBC__
343typedef FILE *(*orig_freopen64_t)(const char *pathname, const char *mode, FILE *stream); 340typedef FILE *(*orig_freopen64_t)(const char *pathname, const char *mode, FILE *stream);
344static orig_freopen64_t orig_freopen64 = NULL; 341static orig_freopen64_t orig_freopen64 = NULL;
345FILE *freopen64(const char *pathname, const char *mode, FILE *stream) { 342FILE *freopen64(const char *pathname, const char *mode, FILE *stream) {
@@ -350,6 +347,7 @@ FILE *freopen64(const char *pathname, const char *mode, FILE *stream) {
350 printf("%u:%s:freopen64 %s\n", pid(), name(), pathname); 347 printf("%u:%s:freopen64 %s\n", pid(), name(), pathname);
351 return rv; 348 return rv;
352} 349}
350#endif /* __GLIBC__ */
353 351
354// unlink 352// unlink
355typedef int (*orig_unlink_t)(const char *pathname); 353typedef int (*orig_unlink_t)(const char *pathname);
@@ -420,17 +418,10 @@ int stat(const char *pathname, struct stat *buf) {
420 return rv; 418 return rv;
421} 419}
422 420
423#ifdef HAVE_MUSL_LIBC 421#ifdef __GLIBC__
424typedef int (*orig_stat64_t)(const char *pathname, struct stat *buf);
425#else
426typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *buf); 422typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *buf);
427#endif
428static orig_stat64_t orig_stat64 = NULL; 423static orig_stat64_t orig_stat64 = NULL;
429#ifdef HAVE_MUSL_LIBC
430int stat64(const char *pathname, struct stat *buf) {
431#else
432int stat64(const char *pathname, struct stat64 *buf) { 424int stat64(const char *pathname, struct stat64 *buf) {
433#endif
434 if (!orig_stat) 425 if (!orig_stat)
435 orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat"); 426 orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat");
436 427
@@ -438,6 +429,7 @@ int stat64(const char *pathname, struct stat64 *buf) {
438 printf("%u:%s:stat %s\n", pid(), name(), pathname); 429 printf("%u:%s:stat %s\n", pid(), name(), pathname);
439 return rv; 430 return rv;
440} 431}
432#endif /* __GLIBC__ */
441 433
442 434
443// access 435// access
@@ -639,4 +631,4 @@ int setresgid(gid_t rgid, gid_t egid, gid_t sgid) {
639 printf("%u:%s:setresgid %d %d %d\n", pid(), name(), rgid, egid, sgid); 631 printf("%u:%s:setresgid %d %d %d\n", pid(), name(), rgid, egid, sgid);
640 632
641 return rv; 633 return rv;
642} \ No newline at end of file 634}