From 9275975b2c8e61ddb3887130a8524c4e22bba219 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 26 Jan 2019 06:00:23 -0500 Subject: [PATCH] Re-organize functions --- native/jni/daemon/log_daemon.cpp | 4 ++-- native/jni/magiskboot/bootimg.cpp | 2 +- native/jni/magiskboot/cpio.cpp | 2 +- native/jni/utils/include/utils.h | 32 +++++++++++++++---------------- native/jni/utils/misc.cpp | 4 ++-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/native/jni/daemon/log_daemon.cpp b/native/jni/daemon/log_daemon.cpp index 97335c758..5b00b42b5 100644 --- a/native/jni/daemon/log_daemon.cpp +++ b/native/jni/daemon/log_daemon.cpp @@ -86,7 +86,7 @@ static void *logcat_thread(void *) { char line[4096]; while (1) { // Start logcat - log_pid = exec_array(false, &log_fd, nullptr, log_cmd.data()); + log_pid = exec_command(false, &log_fd, nullptr, log_cmd.data()); FILE *logs = fdopen(log_fd, "r"); while (fgets(line, sizeof(line), logs)) { if (line[0] == '-') @@ -107,7 +107,7 @@ static void *logcat_thread(void *) { LOGI("magisklogd: logcat output EOF"); // Clear buffer - log_pid = exec_array(false, nullptr, nullptr, clear_cmd.data()); + log_pid = exec_command(false, nullptr, nullptr, clear_cmd.data()); waitpid(log_pid, nullptr, 0); } } diff --git a/native/jni/magiskboot/bootimg.cpp b/native/jni/magiskboot/bootimg.cpp index 3a2e66b4f..5866a4462 100644 --- a/native/jni/magiskboot/bootimg.cpp +++ b/native/jni/magiskboot/bootimg.cpp @@ -44,7 +44,7 @@ boot_img::~boot_img() { #define CHROMEOS_RET 2 #define ELF32_RET 3 #define ELF64_RET 4 -#define pos_align() pos = align(pos, page_size()) +#define pos_align() pos = do_align(pos, page_size()) int boot_img::parse_image(const char * image) { mmap_ro(image, (void **) &map_addr, &map_size); diff --git a/native/jni/magiskboot/cpio.cpp b/native/jni/magiskboot/cpio.cpp index c2b8a4e80..d839848e9 100644 --- a/native/jni/magiskboot/cpio.cpp +++ b/native/jni/magiskboot/cpio.cpp @@ -10,7 +10,7 @@ using namespace std; -#define parse_align() lseek(fd, align(lseek(fd, 0, SEEK_CUR), 4), SEEK_SET) +#define parse_align() lseek(fd, do_align(lseek(fd, 0, SEEK_CUR), 4), SEEK_SET) static uint32_t x8u(char *hex) { uint32_t val, inpos = 8, outpos; diff --git a/native/jni/utils/include/utils.h b/native/jni/utils/include/utils.h index 038decbf0..788654ea4 100644 --- a/native/jni/utils/include/utils.h +++ b/native/jni/utils/include/utils.h @@ -12,19 +12,6 @@ #include #ifdef __cplusplus - -#include -#include - -#define str_contains(s, ss) ((ss) != nullptr && (s).find(ss) != string::npos) -#define str_starts(s, ss) ((ss) != nullptr && (s).compare(0, strlen(ss), ss) == 0) - -std::vector file_to_vector(const char *filename); -char *strdup2(const char *s, size_t *size = nullptr); - -int exec_array(bool err, int *fd, void (*pre_exec)(), const char **argv); -int exec_command(bool err, int *fd, void (*cb)(), const char *argv0, ...); - extern "C" { #endif @@ -94,7 +81,6 @@ int xpoll(struct pollfd *fds, nfds_t nfds, int timeout); unsigned get_shell_uid(); unsigned get_system_uid(); unsigned get_radio_uid(); -int exec_command_sync(const char *argv0, ...); int fork_dont_care(); void gen_rand_str(char *buf, int len); int strend(const char *s1, const char *s2); @@ -109,8 +95,8 @@ int __fsetxattr(int fd, const char *name, const void *value, size_t size, int fl // file.cpp -#define align(p, a) (((p) + (a) - 1) / (a) * (a)) -#define align_off(p, a) (align(p, a) - (p)) +#define do_align(p, a) (((p) + (a) - 1) / (a) * (a)) +#define align_off(p, a) (do_align(p, a) - (p)) extern const char **excl_list; @@ -148,6 +134,20 @@ void write_zero(int fd, size_t size); #ifdef __cplusplus } + +#include +#include + +#define str_contains(s, ss) ((ss) != nullptr && (s).find(ss) != string::npos) +#define str_starts(s, ss) ((ss) != nullptr && (s).compare(0, strlen(ss), ss) == 0) + +std::vector file_to_vector(const char *filename); +char *strdup2(const char *s, size_t *size = nullptr); + +int exec_command(bool err, int *fd, void (*pre_exec)(), const char **argv); +int exec_command(bool err, int *fd, void (*cb)(), const char *argv0, ...); +int exec_command_sync(const char *argv0, ...); + #endif #endif diff --git a/native/jni/utils/misc.cpp b/native/jni/utils/misc.cpp index 3a0831e12..f38d271ff 100644 --- a/native/jni/utils/misc.cpp +++ b/native/jni/utils/misc.cpp @@ -161,7 +161,7 @@ int __fsetxattr(int fd, const char *name, const void *value, size_t size, int fl *fd >= 0 -> STDOUT (or STDERR) will be redirected to *fd *pre_exec -> A callback function called after forking, before execvp */ -int exec_array(bool err, int *fd, void (*pre_exec)(void), const char **argv) { +int exec_command(bool err, int *fd, void (*pre_exec)(void), const char **argv) { int pipefd[2], outfd = -1; if (fd) { @@ -207,7 +207,7 @@ static int v_exec_command(bool err, int *fd, void (*cb)(void), const char *argv0 for (const char *arg = va_arg(argv, char*); arg; arg = va_arg(argv, char*)) args.push_back(arg); args.push_back(nullptr); - int pid = exec_array(err, fd, cb, args.data()); + int pid = exec_command(err, fd, cb, args.data()); return pid; }