Commit dead7480 authored by topjohnwu's avatar topjohnwu

Setup log file when manually starting daemon

parent ab207a1b
...@@ -25,7 +25,7 @@ int DAEMON_STATE = STATE_UNKNOWN; ...@@ -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) { ...@@ -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; goto shortcut;
// Check client permissions
req_code = read_int(client); req_code = read_int(client);
if (req_code < 0 || req_code >= DAEMON_CODE_END)
goto shortcut;
// Check client permissions
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) { ...@@ -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) { ...@@ -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;
} }
......
...@@ -81,7 +81,7 @@ int magisk_main(int argc, char *argv[]) { ...@@ -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);
......
...@@ -8,7 +8,7 @@ ...@@ -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 { ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment