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 --- src/libtrace/Makefile.in | 3 ++- src/libtrace/libtrace.c | 14 +++++++++++++ src/libtrace/musl_defs.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/libtrace/musl_defs.h (limited to 'src') 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-70-g09d2