From 32c8e7522fa3ad7975dfaf3a163b0270b7581ba7 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 1 Dec 2017 17:38:57 +0800 Subject: [PATCH] More precise logging configuration --- jni/Android.mk | 5 ++--- jni/include/logging.h | 31 +++++++++++++++++++++++++++++-- jni/utils/file.c | 12 ++++++------ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/jni/Android.mk b/jni/Android.mk index 852993d46..e690f6647 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -50,7 +50,7 @@ LOCAL_SRC_FILES := \ su/su_daemon.c \ su/su_socket.c -LOCAL_CFLAGS := -DIS_DAEMON +LOCAL_CFLAGS := -DIS_DAEMON -DSELINUX LOCAL_LDLIBS := -llog include $(BUILD_EXECUTABLE) @@ -80,7 +80,6 @@ LOCAL_SRC_FILES := \ magiskpolicy/rules.c \ magiskpolicy/sepolicy.c -LOCAL_CFLAGS := -DNO_SELINUX LOCAL_LDFLAGS := -static include $(BUILD_EXECUTABLE) @@ -109,7 +108,7 @@ LOCAL_SRC_FILES := \ utils/cpio.c \ utils/vector.c -LOCAL_CFLAGS := -DNO_SELINUX +LOCAL_CFLAGS := -DXWRAP_EXIT LOCAL_LDLIBS := -lz include $(BUILD_EXECUTABLE) diff --git a/jni/include/logging.h b/jni/include/logging.h index fc55afbd2..dbc0cc74e 100644 --- a/jni/include/logging.h +++ b/jni/include/logging.h @@ -11,8 +11,24 @@ #define str(a) #a #define xstr(a) str(a) +/************** + * No logging * + **************/ + +#define LOGI(...) +#define LOGE(...) +#define PLOGE(...) + +/****************** + * Daemon logging * + ******************/ + #ifdef IS_DAEMON +#undef LOGI +#undef LOGE +#undef PLOGE + #include #include @@ -41,7 +57,17 @@ void start_debug_full_log(); void stop_debug_full_log(); void start_debug_log(); -#else // IS_DAEMON +#endif + +/******************** + * Tools Log & Exit * + ********************/ + +#ifdef XWRAP_EXIT + +#undef LOGI +#undef LOGE +#undef PLOGE #include @@ -49,6 +75,7 @@ void start_debug_log(); #define LOGE(...) { fprintf(stderr, __VA_ARGS__); exit(1); } #define PLOGE(fmt, args...) { fprintf(stderr, fmt " failed with %d: %s\n\n", ##args, errno, strerror(errno)); exit(1); } -#endif // IS_DAEMON +#endif + #endif // _LOGGING_H_ diff --git a/jni/utils/file.c b/jni/utils/file.c index 308bd0376..f6027d915 100644 --- a/jni/utils/file.c +++ b/jni/utils/file.c @@ -12,7 +12,7 @@ #include #include -#ifndef NO_SELINUX +#ifdef SELINUX #include #endif @@ -238,8 +238,8 @@ void wait_till_exists(const char *target) { int getattr(const char *path, struct file_attr *a) { if (xlstat(path, &a->st) == -1) return -1; +#ifdef SELINUX char *con = ""; -#ifndef NO_SELINUX if (lgetfilecon(path, &con) == -1) return -1; strcpy(a->con, con); @@ -277,7 +277,7 @@ int setattr(const char *path, struct file_attr *a) { return -1; if (chown(path, a->st.st_uid, a->st.st_gid) < 0) return -1; -#ifndef NO_SELINUX +#ifdef SELINUX if (strlen(a->con) && lsetfilecon(path, a->con) < 0) return -1; #endif @@ -294,7 +294,7 @@ int setattrat(int dirfd, const char *pathname, struct file_attr *a) { } int fsetattr(int fd, struct file_attr *a) { -#ifndef NO_SELINUX +#ifdef SELINUX char path[PATH_MAX]; fd_getpath(fd, path, sizeof(path)); return setattr(path, a); @@ -319,7 +319,7 @@ void fclone_attr(const int sourcefd, const int targetfd) { fsetattr(targetfd, &a); } -#ifndef NO_SELINUX +#ifdef SELINUX #define UNLABEL_CON "u:object_r:unlabeled:s0" #define SYSTEM_CON "u:object_r:system_file:s0" @@ -355,7 +355,7 @@ void restorecon(int dirfd, int force) { } } -#endif // NO_SELINUX +#endif // SELINUX static void _mmap(int rw, const char *filename, void **buf, size_t *size) { struct stat st;