diff options
author | netblue30 <netblue30@yahoo.com> | 2015-10-25 09:27:34 -0400 |
---|---|---|
committer | netblue30 <netblue30@yahoo.com> | 2015-10-25 09:27:34 -0400 |
commit | 801164566924c41d18d66bdc9ca8b2305103fb82 (patch) | |
tree | 3384c10df8b38fb4af945f90fecd2c3876941fdf /src/libtrace | |
parent | ignore option testing (diff) | |
download | firejail-801164566924c41d18d66bdc9ca8b2305103fb82.tar.gz firejail-801164566924c41d18d66bdc9ca8b2305103fb82.tar.zst firejail-801164566924c41d18d66bdc9ca8b2305103fb82.zip |
fix struct stat64 problem for musl libc
Diffstat (limited to 'src/libtrace')
-rw-r--r-- | src/libtrace/Makefile.in | 3 | ||||
-rw-r--r-- | src/libtrace/libtrace.c | 14 | ||||
-rw-r--r-- | src/libtrace/musl_defs.h | 52 |
3 files changed, 68 insertions, 1 deletions
diff --git a/src/libtrace/Makefile.in b/src/libtrace/Makefile.in index 3924bdf3f..8bc57cddf 100644 --- a/src/libtrace/Makefile.in +++ b/src/libtrace/Makefile.in | |||
@@ -2,12 +2,13 @@ PREFIX=@prefix@ | |||
2 | VERSION=@PACKAGE_VERSION@ | 2 | VERSION=@PACKAGE_VERSION@ |
3 | NAME=@PACKAGE_NAME@ | 3 | NAME=@PACKAGE_NAME@ |
4 | HAVE_FATAL_WARNINGS=@HAVE_FATAL_WARNINGS@ | 4 | HAVE_FATAL_WARNINGS=@HAVE_FATAL_WARNINGS@ |
5 | HAVE_MUSL_LIBC=@HAVE_MUSL_LIBC@ | ||
5 | 6 | ||
6 | H_FILE_LIST = $(wildcard *.[h]) | 7 | H_FILE_LIST = $(wildcard *.[h]) |
7 | C_FILE_LIST = $(wildcard *.c) | 8 | C_FILE_LIST = $(wildcard *.c) |
8 | OBJS = $(C_FILE_LIST:.c=.o) | 9 | OBJS = $(C_FILE_LIST:.c=.o) |
9 | BINOBJS = $(foreach file, $(OBJS), $file) | 10 | BINOBJS = $(foreach file, $(OBJS), $file) |
10 | CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security | 11 | CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' $(HAVE_MUSL_LIBC) -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security |
11 | LDFLAGS += -pie -Wl,-z,relro -Wl,-z,now | 12 | LDFLAGS += -pie -Wl,-z,relro -Wl,-z,now |
12 | 13 | ||
13 | all: libtrace.so | 14 | all: libtrace.so |
diff --git a/src/libtrace/libtrace.c b/src/libtrace/libtrace.c index 1eb1cf931..2ce74d331 100644 --- a/src/libtrace/libtrace.c +++ b/src/libtrace/libtrace.c | |||
@@ -18,7 +18,11 @@ | |||
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 | ||
21 | #include <stdio.h> | 24 | #include <stdio.h> |
25 | #endif | ||
22 | #include <stdlib.h> | 26 | #include <stdlib.h> |
23 | #include <string.h> | 27 | #include <string.h> |
24 | #include <dlfcn.h> | 28 | #include <dlfcn.h> |
@@ -28,7 +32,9 @@ | |||
28 | #include <netinet/in.h> | 32 | #include <netinet/in.h> |
29 | #include <arpa/inet.h> | 33 | #include <arpa/inet.h> |
30 | #include <sys/un.h> | 34 | #include <sys/un.h> |
35 | #ifndef HAVE_MUSL_LIBC | ||
31 | #include <sys/stat.h> | 36 | #include <sys/stat.h> |
37 | #endif | ||
32 | 38 | ||
33 | // break recursivity on fopen call | 39 | // break recursivity on fopen call |
34 | typedef FILE *(*orig_fopen_t)(const char *pathname, const char *mode); | 40 | typedef FILE *(*orig_fopen_t)(const char *pathname, const char *mode); |
@@ -414,9 +420,17 @@ int stat(const char *pathname, struct stat *buf) { | |||
414 | return rv; | 420 | return rv; |
415 | } | 421 | } |
416 | 422 | ||
423 | #ifdef HAVE_MUSL_LIBC | ||
424 | typedef int (*orig_stat64_t)(const char *pathname, struct stat *buf); | ||
425 | #else | ||
417 | typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *buf); | 426 | typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *buf); |
427 | #endif | ||
418 | static orig_stat64_t orig_stat64 = NULL; | 428 | static orig_stat64_t orig_stat64 = NULL; |
429 | #ifdef HAVE_MUSL_LIBC | ||
430 | int stat64(const char *pathname, struct stat *buf) { | ||
431 | #else | ||
419 | int stat64(const char *pathname, struct stat64 *buf) { | 432 | int stat64(const char *pathname, struct stat64 *buf) { |
433 | #endif | ||
420 | if (!orig_stat) | 434 | if (!orig_stat) |
421 | orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat"); | 435 | orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat"); |
422 | 436 | ||
diff --git a/src/libtrace/musl_defs.h b/src/libtrace/musl_defs.h new file mode 100644 index 000000000..02eb65b83 --- /dev/null +++ b/src/libtrace/musl_defs.h | |||
@@ -0,0 +1,52 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014, 2015 Firejail Authors | ||
3 | * | ||
4 | * This file is part of firejail project | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along | ||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | */ | ||
20 | |||
21 | #ifndef _MUSL_DEFS_H | ||
22 | #define _MUSL_DEFS_H | ||
23 | |||
24 | #include <features.h> | ||
25 | |||
26 | #define __NEED_FILE | ||
27 | #define __NEED_dev_t | ||
28 | #define __NEED_ino_t | ||
29 | #define __NEED_mode_t | ||
30 | #define __NEED_nlink_t | ||
31 | #define __NEED_uid_t | ||
32 | #define __NEED_gid_t | ||
33 | #define __NEED_off_t | ||
34 | #define __NEED_time_t | ||
35 | #define __NEED_blksize_t | ||
36 | #define __NEED_blkcnt_t | ||
37 | #define __NEED_struct_timespec | ||
38 | |||
39 | #include <bits/alltypes.h> | ||
40 | #include <bits/stat.h> | ||
41 | |||
42 | #ifdef __cplusplus | ||
43 | #define NULL 0L | ||
44 | #else | ||
45 | #define NULL ((void*)0) | ||
46 | #endif | ||
47 | |||
48 | int printf(const char *format, ...); | ||
49 | int sprintf(char *buffer, const char *format, ...); | ||
50 | char *fgets(char *buffer, int size, FILE *fp); | ||
51 | |||
52 | #endif | ||