From ed052e0b0ba2a2e07bf396ce3bdfc3d5683e2aa7 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 6 Apr 2017 06:18:39 +0800 Subject: [PATCH] Compile with unified binary only The su binary itself cannot do much, since it still requires a daemon to work The daemon code will soon be moved to a higher level (out of MagiskSU), so there is no point in creating a separate binary --- Android.mk | 12 ------------ indep_bin.h | 34 ---------------------------------- su.c | 52 ---------------------------------------------------- su.h | 9 --------- 4 files changed, 107 deletions(-) delete mode 100644 Android.mk delete mode 100644 indep_bin.h diff --git a/Android.mk b/Android.mk deleted file mode 100644 index 414faa631..000000000 --- a/Android.mk +++ /dev/null @@ -1,12 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) -LOCAL_MODULE := su -LOCAL_STATIC_LIBRARIES := libselinux libsqlite3 -LOCAL_C_INCLUDES := jni/selinux/libselinux/include/ jni/selinux/libsepol/include/ jni/sqlite3/ -LOCAL_SRC_FILES := su.c daemon.c activity.c db.c utils.c pts.c -LOCAL_CFLAGS := -DSQLITE_OMIT_LOAD_EXTENSION -DINDEP_BINARY -include $(BUILD_EXECUTABLE) - -include jni/selinux/libselinux/Android.mk -include jni/sqlite3/Android.mk diff --git a/indep_bin.h b/indep_bin.h deleted file mode 100644 index 5bc41ff3c..000000000 --- a/indep_bin.h +++ /dev/null @@ -1,34 +0,0 @@ -/* This file is here because is uses some same macros in magisk.h - * So we have to remove them from su.h. - * However, if we want to build our own binary, we still have to define them - */ - - -#ifndef _INDEP_BIN_H_ -#define _INDEP_BIN_H_ - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "su" - -// fallback to using /system/bin/log. -// can't use liblog.so because this is a static binary. -#ifndef LOGE -#define LOGE exec_loge -#endif -#ifndef LOGD -#define LOGD exec_logd -#endif -#ifndef LOGW -#define LOGW exec_logw -#endif - -#include -#include -#define PLOGE(fmt,args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno)) -#define PLOGEV(fmt,err,args...) LOGE(fmt " failed with %d: %s", ##args, err, strerror(err)) - -int su_main(int argc, char *argv[]); - -#endif \ No newline at end of file diff --git a/su.c b/su.c index f44823e53..b97dbe606 100644 --- a/su.c +++ b/su.c @@ -45,12 +45,6 @@ #include "su.h" #include "utils.h" -#ifdef INDEP_BINARY -int main(int argc, char *argv[]) { - return su_main(argc, argv); -} -#endif - extern int is_daemon; extern int daemon_from_uid; extern int daemon_from_pid; @@ -96,52 +90,6 @@ int fork_zero_fucks() { } } -void exec_log(char *priority, char* logline) { - int pid; - if ((pid = fork()) == 0) { - int null = open("/dev/null", O_WRONLY | O_CLOEXEC); - dup2(null, STDIN_FILENO); - dup2(null, STDOUT_FILENO); - dup2(null, STDERR_FILENO); - execl("/system/bin/log", "/system/bin/log", "-p", priority, "-t", LOG_TAG, logline, NULL); - _exit(0); - } - int status; - waitpid(pid, &status, 0); -} - -void exec_loge(const char* fmt, ...) { - va_list args; - - char logline[PATH_MAX]; - va_start(args, fmt); - vsnprintf(logline, PATH_MAX, fmt, args); - va_end(args); - exec_log("e", logline); -} - -void exec_logw(const char* fmt, ...) { - va_list args; - - char logline[PATH_MAX]; - va_start(args, fmt); - vsnprintf(logline, PATH_MAX, fmt, args); - va_end(args); - exec_log("w", logline); -} - -void exec_logd(const char* fmt, ...) { -#ifdef DEBUG - va_list args; - - char logline[PATH_MAX]; - va_start(args, fmt); - vsnprintf(logline, PATH_MAX, fmt, args); - va_end(args); - exec_log("d", logline); -#endif -} - static int from_init(struct su_initiator *from) { char path[PATH_MAX], exe[PATH_MAX]; char args[4096], *argv0, *argv_rest; diff --git a/su.h b/su.h index d17225a88..d2ab7b61f 100644 --- a/su.h +++ b/su.h @@ -18,12 +18,7 @@ #ifndef SU_h #define SU_h 1 -#ifdef INDEP_BINARY -#include "indep_bin.h" -#else #include "magisk.h" -#endif - #ifndef AID_SHELL #define AID_SHELL (get_shell_uid()) @@ -167,10 +162,6 @@ static inline char *get_command(const struct su_request *to) return DEFAULT_SHELL; } -void exec_loge(const char* fmt, ...); -void exec_logw(const char* fmt, ...); -void exec_logd(const char* fmt, ...); - int run_daemon(); int connect_daemon(int argc, char *argv[], int ppid); int su_main(int argc, char *argv[]);