From 801164566924c41d18d66bdc9ca8b2305103fb82 Mon Sep 17 00:00:00 2001 From: netblue30 Date: Sun, 25 Oct 2015 09:27:34 -0400 Subject: fix struct stat64 problem for musl libc --- configure | 23 ++++++++++++++++++--- configure.ac | 15 +++++++++++--- src/libtrace/Makefile.in | 3 ++- src/libtrace/libtrace.c | 14 +++++++++++++ src/libtrace/musl_defs.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 src/libtrace/musl_defs.h diff --git a/configure b/configure index 9625cdb61..e7b573c25 100755 --- a/configure +++ b/configure @@ -628,6 +628,7 @@ HAVE_SECCOMP_H EGREP GREP CPP +HAVE_MUSL_LIBC HAVE_FATAL_WARNINGS HAVE_BIND HAVE_CHROOT @@ -688,6 +689,7 @@ enable_seccomp enable_chroot enable_bind enable_fatal_warnings +enable_musl_libc ' ac_precious_vars='build_alias host_alias @@ -1307,10 +1309,11 @@ Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --disable-seccomp Disable seccomp - --disable-chroot Disable chroot - --disable-bind Disable bind + --disable-seccomp disable seccomp + --disable-chroot disable chroot + --disable-bind disable bind --enable-fatal-warnings -W -Wall -Werror + --enable-musl-libc ugly hack to allow compilation with musl libc Some influential environment variables: CC C compiler command @@ -3098,6 +3101,19 @@ if test "x$enable_fatal_warnings" = "xyes"; then : HAVE_FATAL_WARNINGS="-W -Wall -Werror" +fi + +HAVE_MUSL_LIBC="" +# Check whether --enable-musl_libc was given. +if test "${enable_musl_libc+set}" = set; then : + enableval=$enable_musl_libc; +fi + +if test "x$enable_musl_libc" = "xyes"; then : + + HAVE_MUSL_LIBC="-DHAVE_MUSL_LIBC" + + fi # checking pthread library @@ -4736,4 +4752,5 @@ echo " : $HAVE_SECCOMP_H" echo " chroot: $HAVE_CHROOT" echo " bind: $HAVE_BIND" echo " fatal warnings: $HAVE_FATAL_WARNINGS" +echo " musl libc: $HAVE_MUSL_LIBC" echo diff --git a/configure.ac b/configure.ac index b2fa22fd7..52048757c 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ AC_PROG_RANLIB HAVE_SECCOMP="" AC_ARG_ENABLE([seccomp], - AS_HELP_STRING([--disable-seccomp], [Disable seccomp])) + AS_HELP_STRING([--disable-seccomp], [disable seccomp])) AS_IF([test "x$enable_seccomp" != "xno"], [ HAVE_SECCOMP="-DHAVE_SECCOMP" AC_SUBST(HAVE_SECCOMP) @@ -19,7 +19,7 @@ AS_IF([test "x$enable_seccomp" != "xno"], [ HAVE_CHROOT="" AC_ARG_ENABLE([chroot], - AS_HELP_STRING([--disable-chroot], [Disable chroot])) + AS_HELP_STRING([--disable-chroot], [disable chroot])) AS_IF([test "x$enable_chroot" != "xno"], [ HAVE_CHROOT="-DHAVE_CHROOT" AC_SUBST(HAVE_CHROOT) @@ -27,7 +27,7 @@ AS_IF([test "x$enable_chroot" != "xno"], [ HAVE_BIND="" AC_ARG_ENABLE([bind], - AS_HELP_STRING([--disable-bind], [Disable bind])) + AS_HELP_STRING([--disable-bind], [disable bind])) AS_IF([test "x$enable_bind" != "xno"], [ HAVE_BIND="-DHAVE_BIND" AC_SUBST(HAVE_BIND) @@ -41,6 +41,14 @@ AS_IF([test "x$enable_fatal_warnings" = "xyes"], [ AC_SUBST(HAVE_FATAL_WARNINGS) ]) +HAVE_MUSL_LIBC="" +AC_ARG_ENABLE([musl_libc], + AS_HELP_STRING([--enable-musl-libc], [ugly hack to allow compilation with musl libc])) +AS_IF([test "x$enable_musl_libc" = "xyes"], [ + HAVE_MUSL_LIBC="-DHAVE_MUSL_LIBC" + AC_SUBST(HAVE_MUSL_LIBC) +]) + # checking pthread library AC_CHECK_LIB([pthread], [main], [], AC_MSG_ERROR([*** POSIX thread support not installed ***])) AC_CHECK_HEADER(pthread.h,,AC_MSG_ERROR([*** POSIX thread support not installed ***])) @@ -57,4 +65,5 @@ echo " : $HAVE_SECCOMP_H" echo " chroot: $HAVE_CHROOT" echo " bind: $HAVE_BIND" echo " fatal warnings: $HAVE_FATAL_WARNINGS" +echo " musl libc: $HAVE_MUSL_LIBC" echo 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@ VERSION=@PACKAGE_VERSION@ NAME=@PACKAGE_NAME@ HAVE_FATAL_WARNINGS=@HAVE_FATAL_WARNINGS@ +HAVE_MUSL_LIBC=@HAVE_MUSL_LIBC@ H_FILE_LIST = $(wildcard *.[h]) C_FILE_LIST = $(wildcard *.c) OBJS = $(C_FILE_LIST:.c=.o) BINOBJS = $(foreach file, $(OBJS), $file) -CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security +CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' $(HAVE_MUSL_LIBC) -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security LDFLAGS += -pie -Wl,-z,relro -Wl,-z,now 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 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #define _GNU_SOURCE +#ifdef HAVE_MUSL_LIBC +#include "musl_defs.h" +#else #include +#endif #include #include #include @@ -28,7 +32,9 @@ #include #include #include +#ifndef HAVE_MUSL_LIBC #include +#endif // break recursivity on fopen call typedef FILE *(*orig_fopen_t)(const char *pathname, const char *mode); @@ -414,9 +420,17 @@ int stat(const char *pathname, struct stat *buf) { return rv; } +#ifdef HAVE_MUSL_LIBC +typedef int (*orig_stat64_t)(const char *pathname, struct stat *buf); +#else typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *buf); +#endif static orig_stat64_t orig_stat64 = NULL; +#ifdef HAVE_MUSL_LIBC +int stat64(const char *pathname, struct stat *buf) { +#else int stat64(const char *pathname, struct stat64 *buf) { +#endif if (!orig_stat) orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat"); 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 @@ +/* + * Copyright (C) 2014, 2015 Firejail Authors + * + * This file is part of firejail project + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef _MUSL_DEFS_H +#define _MUSL_DEFS_H + +#include + +#define __NEED_FILE +#define __NEED_dev_t +#define __NEED_ino_t +#define __NEED_mode_t +#define __NEED_nlink_t +#define __NEED_uid_t +#define __NEED_gid_t +#define __NEED_off_t +#define __NEED_time_t +#define __NEED_blksize_t +#define __NEED_blkcnt_t +#define __NEED_struct_timespec + +#include +#include + +#ifdef __cplusplus +#define NULL 0L +#else +#define NULL ((void*)0) +#endif + +int printf(const char *format, ...); +int sprintf(char *buffer, const char *format, ...); +char *fgets(char *buffer, int size, FILE *fp); + +#endif -- cgit v1.2.3-54-g00ecf