mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-21 21:11:27 +00:00
Minor log_daemon changes
This commit is contained in:
parent
411ea56a3e
commit
5e4d2dedbe
@ -18,7 +18,7 @@
|
|||||||
#include "daemon.h"
|
#include "daemon.h"
|
||||||
#include "flags.h"
|
#include "flags.h"
|
||||||
|
|
||||||
int log_daemon_started = 0;
|
bool log_daemon_started = false;
|
||||||
static Array<const char *> log_cmd, clear_cmd;
|
static Array<const char *> log_cmd, clear_cmd;
|
||||||
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
@ -27,16 +27,18 @@ enum {
|
|||||||
LOG_EVENT
|
LOG_EVENT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define EVENT_NUM 2
|
||||||
|
|
||||||
struct log_listener {
|
struct log_listener {
|
||||||
int fd;
|
int fd;
|
||||||
int (*filter) (const char*);
|
bool (*filter)(const char *);
|
||||||
};
|
};
|
||||||
|
|
||||||
static int am_proc_start_filter(const char *log) {
|
static bool am_proc_start_filter(const char *log) {
|
||||||
return strstr(log, "am_proc_start") != nullptr;
|
return strstr(log, "am_proc_start") != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int magisk_log_filter(const char *log) {
|
static bool magisk_log_filter(const char *log) {
|
||||||
return !am_proc_start_filter(log);
|
return !am_proc_start_filter(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +52,6 @@ static struct log_listener events[] = {
|
|||||||
.filter = magisk_log_filter
|
.filter = magisk_log_filter
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#define EVENT_NUM (sizeof(events) / sizeof(struct log_listener))
|
|
||||||
|
|
||||||
static void sigpipe_handler(int) {
|
static void sigpipe_handler(int) {
|
||||||
close(events[HIDE_EVENT].fd);
|
close(events[HIDE_EVENT].fd);
|
||||||
@ -126,7 +127,7 @@ static void log_daemon() {
|
|||||||
// Construct cmdline
|
// Construct cmdline
|
||||||
log_cmd.push_back(MIRRDIR "/system/bin/logcat");
|
log_cmd.push_back(MIRRDIR "/system/bin/logcat");
|
||||||
// Test whether these buffers actually works
|
// Test whether these buffers actually works
|
||||||
const char* b[] = { "main", "events", "crash" };
|
const char *b[] = { "main", "events", "crash" };
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
if (exec_command_sync(MIRRDIR "/system/bin/logcat", "-b", b[i], "-d", "-f", "/dev/null", nullptr) == 0) {
|
if (exec_command_sync(MIRRDIR "/system/bin/logcat", "-b", b[i], "-d", "-f", "/dev/null", nullptr) == 0) {
|
||||||
log_cmd.push_back("-b");
|
log_cmd.push_back("-b");
|
||||||
@ -179,12 +180,12 @@ static void log_daemon() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int start_log_daemon() {
|
bool start_log_daemon() {
|
||||||
if (!log_daemon_started) {
|
if (!log_daemon_started) {
|
||||||
if (exec_command_sync(MIRRDIR "/system/bin/logcat", "-d", "-f", "/dev/null", nullptr) == 0) {
|
if (exec_command_sync(MIRRDIR "/system/bin/logcat", "-d", "-f", "/dev/null", nullptr) == 0) {
|
||||||
if (fork_dont_care() == 0)
|
if (fork_dont_care() == 0)
|
||||||
log_daemon();
|
log_daemon();
|
||||||
log_daemon_started = 1;
|
log_daemon_started = true;
|
||||||
// Wait till we can connect to log_daemon and receive ack
|
// Wait till we can connect to log_daemon and receive ack
|
||||||
int fd = connect_log_daemon();
|
int fd = connect_log_daemon();
|
||||||
write_int(fd, HANDSHAKE);
|
write_int(fd, HANDSHAKE);
|
||||||
|
@ -43,9 +43,9 @@ int connect_daemon();
|
|||||||
|
|
||||||
// log_monitor.c
|
// log_monitor.c
|
||||||
|
|
||||||
extern int log_daemon_started;
|
extern bool log_daemon_started;
|
||||||
int connect_log_daemon();
|
int connect_log_daemon();
|
||||||
int start_log_daemon();
|
bool start_log_daemon();
|
||||||
|
|
||||||
// socket.c
|
// socket.c
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user