Add daemon response code

This commit is contained in:
topjohnwu
2017-05-05 16:13:26 +08:00
parent d66c284bed
commit 58849f28a8
8 changed files with 59 additions and 28 deletions

View File

@@ -32,6 +32,27 @@ static void *request_handler(void *args) {
int client = *((int *) args);
free(args);
client_request req = read_int(client);
struct ucred credentials;
get_client_cred(client, &credentials);
switch (req) {
case LAUNCH_MAGISKHIDE:
case STOP_MAGISKHIDE:
case ADD_HIDELIST:
case RM_HIDELIST:
case POST_FS:
case POST_FS_DATA:
case LATE_START:
if (credentials.uid != 0) {
write_int(client, ROOT_REQUIRED);
close(client);
return NULL;
}
default:
break;
}
switch (req) {
case LAUNCH_MAGISKHIDE:
launch_magiskhide(client);
@@ -65,9 +86,8 @@ static void *request_handler(void *args) {
case LATE_START:
late_start(client);
break;
case TEST:
// test(client);
break;
default:
close(client);
}
return NULL;
}

View File

@@ -10,6 +10,7 @@ extern pthread_t sepol_patch;
// Commands require connecting to daemon
typedef enum {
DO_NOTHING = 0,
LAUNCH_MAGISKHIDE,
STOP_MAGISKHIDE,
ADD_HIDELIST,
@@ -23,6 +24,17 @@ typedef enum {
TEST
} client_request;
// Return codes for daemon
typedef enum {
DAEMON_ERROR = -1,
DAEMON_SUCCESS = 0,
ROOT_REQUIRED,
HIDE_IS_ENABLED,
HIDE_NOT_ENABLED,
HIDE_ITEM_EXIST,
HIDE_ITEM_NOT_EXIST,
} daemon_response;
// daemon.c
void start_daemon();