More precise logging configuration

This commit is contained in:
topjohnwu 2017-12-01 17:38:57 +08:00
parent a5e4f3cc6b
commit 32c8e7522f
3 changed files with 37 additions and 11 deletions

View File

@ -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)

View File

@ -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 <pthread.h>
#include <android/log.h>
@ -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 <stdio.h>
@ -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_

View File

@ -12,7 +12,7 @@
#include <sys/inotify.h>
#include <linux/fs.h>
#ifndef NO_SELINUX
#ifdef SELINUX
#include <selinux/selinux.h>
#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;