aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2015-10-25 14:24:39 -0400
committerLibravatar netblue30 <netblue30@yahoo.com>2015-10-25 14:24:39 -0400
commitd7c26ece4f78a253d7a6900b8e9ffdce6502f30d (patch)
treec5df49a795e8a16df2c571404cead37dd8627bb5
parentreadme.md (diff)
parentlibtrace: only include fopen64, freopen64 and stat64 if __GLIBC__ is defined (diff)
downloadfirejail-d7c26ece4f78a253d7a6900b8e9ffdce6502f30d.tar.gz
firejail-d7c26ece4f78a253d7a6900b8e9ffdce6502f30d.tar.zst
firejail-d7c26ece4f78a253d7a6900b8e9ffdce6502f30d.zip
Merge pull request #96 from Duncaen/master
fix libtrace for musl libc
-rwxr-xr-xconfigure23
-rw-r--r--configure.ac15
-rw-r--r--src/libtrace/Makefile.in3
-rw-r--r--src/libtrace/libtrace.c22
-rw-r--r--src/libtrace/musl_defs.h52
5 files changed, 14 insertions, 101 deletions
diff --git a/configure b/configure
index e7b573c25..9625cdb61 100755
--- a/configure
+++ b/configure
@@ -628,7 +628,6 @@ HAVE_SECCOMP_H
628EGREP 628EGREP
629GREP 629GREP
630CPP 630CPP
631HAVE_MUSL_LIBC
632HAVE_FATAL_WARNINGS 631HAVE_FATAL_WARNINGS
633HAVE_BIND 632HAVE_BIND
634HAVE_CHROOT 633HAVE_CHROOT
@@ -689,7 +688,6 @@ enable_seccomp
689enable_chroot 688enable_chroot
690enable_bind 689enable_bind
691enable_fatal_warnings 690enable_fatal_warnings
692enable_musl_libc
693' 691'
694 ac_precious_vars='build_alias 692 ac_precious_vars='build_alias
695host_alias 693host_alias
@@ -1309,11 +1307,10 @@ Optional Features:
1309 --disable-option-checking ignore unrecognized --enable/--with options 1307 --disable-option-checking ignore unrecognized --enable/--with options
1310 --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) 1308 --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
1311 --enable-FEATURE[=ARG] include FEATURE [ARG=yes] 1309 --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
1312 --disable-seccomp disable seccomp 1310 --disable-seccomp Disable seccomp
1313 --disable-chroot disable chroot 1311 --disable-chroot Disable chroot
1314 --disable-bind disable bind 1312 --disable-bind Disable bind
1315 --enable-fatal-warnings -W -Wall -Werror 1313 --enable-fatal-warnings -W -Wall -Werror
1316 --enable-musl-libc ugly hack to allow compilation with musl libc
1317 1314
1318Some influential environment variables: 1315Some influential environment variables:
1319 CC C compiler command 1316 CC C compiler command
@@ -3103,19 +3100,6 @@ if test "x$enable_fatal_warnings" = "xyes"; then :
3103 3100
3104fi 3101fi
3105 3102
3106HAVE_MUSL_LIBC=""
3107# Check whether --enable-musl_libc was given.
3108if test "${enable_musl_libc+set}" = set; then :
3109 enableval=$enable_musl_libc;
3110fi
3111
3112if test "x$enable_musl_libc" = "xyes"; then :
3113
3114 HAVE_MUSL_LIBC="-DHAVE_MUSL_LIBC"
3115
3116
3117fi
3118
3119# checking pthread library 3103# checking pthread library
3120 3104
3121{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lpthread" >&5 3105{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lpthread" >&5
@@ -4752,5 +4736,4 @@ echo " <linux/seccomp.h>: $HAVE_SECCOMP_H"
4752echo " chroot: $HAVE_CHROOT" 4736echo " chroot: $HAVE_CHROOT"
4753echo " bind: $HAVE_BIND" 4737echo " bind: $HAVE_BIND"
4754echo " fatal warnings: $HAVE_FATAL_WARNINGS" 4738echo " fatal warnings: $HAVE_FATAL_WARNINGS"
4755echo " musl libc: $HAVE_MUSL_LIBC"
4756echo 4739echo
diff --git a/configure.ac b/configure.ac
index 52048757c..b2fa22fd7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,7 +11,7 @@ AC_PROG_RANLIB
11 11
12HAVE_SECCOMP="" 12HAVE_SECCOMP=""
13AC_ARG_ENABLE([seccomp], 13AC_ARG_ENABLE([seccomp],
14 AS_HELP_STRING([--disable-seccomp], [disable seccomp])) 14 AS_HELP_STRING([--disable-seccomp], [Disable seccomp]))
15AS_IF([test "x$enable_seccomp" != "xno"], [ 15AS_IF([test "x$enable_seccomp" != "xno"], [
16 HAVE_SECCOMP="-DHAVE_SECCOMP" 16 HAVE_SECCOMP="-DHAVE_SECCOMP"
17 AC_SUBST(HAVE_SECCOMP) 17 AC_SUBST(HAVE_SECCOMP)
@@ -19,7 +19,7 @@ AS_IF([test "x$enable_seccomp" != "xno"], [
19 19
20HAVE_CHROOT="" 20HAVE_CHROOT=""
21AC_ARG_ENABLE([chroot], 21AC_ARG_ENABLE([chroot],
22 AS_HELP_STRING([--disable-chroot], [disable chroot])) 22 AS_HELP_STRING([--disable-chroot], [Disable chroot]))
23AS_IF([test "x$enable_chroot" != "xno"], [ 23AS_IF([test "x$enable_chroot" != "xno"], [
24 HAVE_CHROOT="-DHAVE_CHROOT" 24 HAVE_CHROOT="-DHAVE_CHROOT"
25 AC_SUBST(HAVE_CHROOT) 25 AC_SUBST(HAVE_CHROOT)
@@ -27,7 +27,7 @@ AS_IF([test "x$enable_chroot" != "xno"], [
27 27
28HAVE_BIND="" 28HAVE_BIND=""
29AC_ARG_ENABLE([bind], 29AC_ARG_ENABLE([bind],
30 AS_HELP_STRING([--disable-bind], [disable bind])) 30 AS_HELP_STRING([--disable-bind], [Disable bind]))
31AS_IF([test "x$enable_bind" != "xno"], [ 31AS_IF([test "x$enable_bind" != "xno"], [
32 HAVE_BIND="-DHAVE_BIND" 32 HAVE_BIND="-DHAVE_BIND"
33 AC_SUBST(HAVE_BIND) 33 AC_SUBST(HAVE_BIND)
@@ -41,14 +41,6 @@ AS_IF([test "x$enable_fatal_warnings" = "xyes"], [
41 AC_SUBST(HAVE_FATAL_WARNINGS) 41 AC_SUBST(HAVE_FATAL_WARNINGS)
42]) 42])
43 43
44HAVE_MUSL_LIBC=""
45AC_ARG_ENABLE([musl_libc],
46 AS_HELP_STRING([--enable-musl-libc], [ugly hack to allow compilation with musl libc]))
47AS_IF([test "x$enable_musl_libc" = "xyes"], [
48 HAVE_MUSL_LIBC="-DHAVE_MUSL_LIBC"
49 AC_SUBST(HAVE_MUSL_LIBC)
50])
51
52# checking pthread library 44# checking pthread library
53AC_CHECK_LIB([pthread], [main], [], AC_MSG_ERROR([*** POSIX thread support not installed ***])) 45AC_CHECK_LIB([pthread], [main], [], AC_MSG_ERROR([*** POSIX thread support not installed ***]))
54AC_CHECK_HEADER(pthread.h,,AC_MSG_ERROR([*** POSIX thread support not installed ***])) 46AC_CHECK_HEADER(pthread.h,,AC_MSG_ERROR([*** POSIX thread support not installed ***]))
@@ -65,5 +57,4 @@ echo " <linux/seccomp.h>: $HAVE_SECCOMP_H"
65echo " chroot: $HAVE_CHROOT" 57echo " chroot: $HAVE_CHROOT"
66echo " bind: $HAVE_BIND" 58echo " bind: $HAVE_BIND"
67echo " fatal warnings: $HAVE_FATAL_WARNINGS" 59echo " fatal warnings: $HAVE_FATAL_WARNINGS"
68echo " musl libc: $HAVE_MUSL_LIBC"
69echo 60echo
diff --git a/src/libtrace/Makefile.in b/src/libtrace/Makefile.in
index 8bc57cddf..3924bdf3f 100644
--- a/src/libtrace/Makefile.in
+++ b/src/libtrace/Makefile.in
@@ -2,13 +2,12 @@ PREFIX=@prefix@
2VERSION=@PACKAGE_VERSION@ 2VERSION=@PACKAGE_VERSION@
3NAME=@PACKAGE_NAME@ 3NAME=@PACKAGE_NAME@
4HAVE_FATAL_WARNINGS=@HAVE_FATAL_WARNINGS@ 4HAVE_FATAL_WARNINGS=@HAVE_FATAL_WARNINGS@
5HAVE_MUSL_LIBC=@HAVE_MUSL_LIBC@
6 5
7H_FILE_LIST = $(wildcard *.[h]) 6H_FILE_LIST = $(wildcard *.[h])
8C_FILE_LIST = $(wildcard *.c) 7C_FILE_LIST = $(wildcard *.c)
9OBJS = $(C_FILE_LIST:.c=.o) 8OBJS = $(C_FILE_LIST:.c=.o)
10BINOBJS = $(foreach file, $(OBJS), $file) 9BINOBJS = $(foreach file, $(OBJS), $file)
11CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' $(HAVE_MUSL_LIBC) -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security 10CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security
12LDFLAGS += -pie -Wl,-z,relro -Wl,-z,now 11LDFLAGS += -pie -Wl,-z,relro -Wl,-z,now
13 12
14all: libtrace.so 13all: libtrace.so
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}
diff --git a/src/libtrace/musl_defs.h b/src/libtrace/musl_defs.h
deleted file mode 100644
index 02eb65b83..000000000
--- a/src/libtrace/musl_defs.h
+++ /dev/null
@@ -1,52 +0,0 @@
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
48int printf(const char *format, ...);
49int sprintf(char *buffer, const char *format, ...);
50char *fgets(char *buffer, int size, FILE *fp);
51
52#endif