Remove magisklogd, use threads and BlockingQueue

This commit is contained in:
topjohnwu
2019-02-10 01:05:19 -05:00
parent b3242322fd
commit 3a422c3f15
11 changed files with 260 additions and 270 deletions

View File

@@ -8,12 +8,13 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "magisk.h"
#include "utils.h"
#include "resetprop.h"
#include <magisk.h>
#include <utils.h>
#include <resetprop.h>
#include <db.h>
#include <logcat.h>
#include "magiskhide.h"
#include "daemon.h"
#include "db.h"
using namespace std;
@@ -282,7 +283,7 @@ int launch_magiskhide(int client) {
if (hide_enabled)
return HIDE_IS_ENABLED;
if (!log_daemon_started)
if (!logcat_started)
return LOGCAT_DISABLED;
hide_enabled = true;
@@ -327,7 +328,7 @@ int stop_magiskhide() {
}
void auto_start_magiskhide() {
if (!start_log_daemon())
if (!start_logcat())
return;
db_settings dbs;
get_db_settings(&dbs, HIDE_CONFIG);

View File

@@ -18,23 +18,22 @@
#include <vector>
#include <string>
#include "magisk.h"
#include "daemon.h"
#include "utils.h"
#include <magisk.h>
#include <utils.h>
#include <logcat.h>
#include "magiskhide.h"
using namespace std;
static int sockfd = -1;
extern char *system_block, *vendor_block, *magiskloop;
// Workaround for the lack of pthread_cancel
static void term_thread(int) {
LOGD("proc_monitor: running cleanup\n");
stop_logging(HIDE_EVENT);
hide_list.clear();
hide_enabled = false;
close(sockfd);
sockfd = -1;
pthread_mutex_destroy(&list_lock);
LOGD("proc_monitor: terminating\n");
pthread_exit(nullptr);
@@ -124,20 +123,14 @@ void proc_monitor() {
term_thread(TERM_THREAD);
}
// Connect to the log daemon
sockfd = connect_log_daemon();
if (sockfd < 0)
pthread_exit(nullptr);
write_int(sockfd, HIDE_CONNECT);
FILE *log_in = fdopen(sockfd, "r");
char buf[4096];
while (fgets(buf, sizeof(buf), log_in)) {
auto &queue = start_logging(HIDE_EVENT);
while (true) {
char *log;
int pid, ppid;
struct stat ns, pns;
if ((log = strchr(buf, '[')) == nullptr)
string line = queue.take();
if ((log = strchr(&line[0], '[')) == nullptr)
continue;
// Extract pid
@@ -183,5 +176,4 @@ void proc_monitor() {
if (fork_dont_care() == 0)
hide_daemon(pid);
}
pthread_exit(nullptr);
}