Setup log file when manually starting daemon

This commit is contained in:
topjohnwu 2020-12-04 01:07:47 -08:00
parent ab207a1bb3
commit dead74801d
3 changed files with 12 additions and 7 deletions

View File

@ -25,7 +25,7 @@ int DAEMON_STATE = STATE_UNKNOWN;
static struct stat self_st; static struct stat self_st;
static bool verify_client(int client, pid_t pid) { static bool verify_client(pid_t pid) {
// Verify caller is the same as server // Verify caller is the same as server
char path[32]; char path[32];
sprintf(path, "/proc/%d/exe", pid); sprintf(path, "/proc/%d/exe", pid);
@ -71,11 +71,14 @@ static void handle_request(int client) {
// Verify client credentials // Verify client credentials
ucred cred; ucred cred;
get_client_cred(client, &cred); get_client_cred(client, &cred);
if (cred.uid != 0 && !verify_client(client, cred.pid)) if (cred.uid != 0 && !verify_client(cred.pid))
goto shortcut;
req_code = read_int(client);
if (req_code < 0 || req_code >= DAEMON_CODE_END)
goto shortcut; goto shortcut;
// Check client permissions // Check client permissions
req_code = read_int(client);
switch (req_code) { switch (req_code) {
case MAGISKHIDE: case MAGISKHIDE:
case POST_FS_DATA: case POST_FS_DATA:
@ -108,7 +111,7 @@ static void handle_request(int client) {
DAEMON_STATE = STATE_BOOT_COMPLETE; DAEMON_STATE = STATE_BOOT_COMPLETE;
break; break;
// Simple requests to query daemon info // Simple requests
case CHECK_VERSION: case CHECK_VERSION:
write_string(client, MAGISK_VERSION ":MAGISK"); write_string(client, MAGISK_VERSION ":MAGISK");
goto shortcut; goto shortcut;
@ -118,7 +121,8 @@ static void handle_request(int client) {
case GET_PATH: case GET_PATH:
write_string(client, MAGISKTMP.data()); write_string(client, MAGISKTMP.data());
goto shortcut; goto shortcut;
case DO_NOTHING: case START_DAEMON:
setup_logfile(true);
goto shortcut; goto shortcut;
} }

View File

@ -81,7 +81,7 @@ int magisk_main(int argc, char *argv[]) {
return 0; return 0;
} else if (argv[1] == "--daemon"sv) { } else if (argv[1] == "--daemon"sv) {
int fd = connect_daemon(true); int fd = connect_daemon(true);
write_int(fd, DO_NOTHING); write_int(fd, START_DAEMON);
return 0; return 0;
} else if (argv[1] == "--post-fs-data"sv) { } else if (argv[1] == "--post-fs-data"sv) {
int fd = connect_daemon(true); int fd = connect_daemon(true);

View File

@ -8,7 +8,7 @@
// Daemon command codes // Daemon command codes
enum { enum {
DO_NOTHING = 0, START_DAEMON,
SUPERUSER, SUPERUSER,
CHECK_VERSION, CHECK_VERSION,
CHECK_VERSION_CODE, CHECK_VERSION_CODE,
@ -19,6 +19,7 @@ enum {
SQLITE_CMD, SQLITE_CMD,
REMOVE_MODULES, REMOVE_MODULES,
GET_PATH, GET_PATH,
DAEMON_CODE_END,
}; };
// Return codes for daemon // Return codes for daemon