diff --git a/src/kiwmi/ipc.c b/src/kiwmi/ipc.c index 8471b9f..fcb4380 100644 --- a/src/kiwmi/ipc.c +++ b/src/kiwmi/ipc.c @@ -57,7 +57,7 @@ init_socket(void) #define CMDIS(c) (strcmp(command, (c)) == 0) void -handle_ipc_event(char *msg) +handle_ipc_event(FILE *client, char *msg) { char *command = strtok(msg, " "); @@ -67,6 +67,7 @@ handle_ipc_event(char *msg) exec_config(); } else if (CMDIS("exec")) { char *command = strtok(NULL, ""); + fclose(client); execl("/bin/sh", "/bin/sh", "-c", command, NULL); g_is_about_to_quit = true; } else { diff --git a/src/kiwmi/ipc.h b/src/kiwmi/ipc.h index 670891e..642e78e 100644 --- a/src/kiwmi/ipc.h +++ b/src/kiwmi/ipc.h @@ -8,8 +8,10 @@ #ifndef IPC_H #define IPC_H +#include + void init_socket(void); -void handle_ipc_event(char *msg); +void handle_ipc_event(FILE *client, char *msg); extern int g_sock_fd; diff --git a/src/kiwmi/main.c b/src/kiwmi/main.c index 8c1fce3..f22e560 100644 --- a/src/kiwmi/main.c +++ b/src/kiwmi/main.c @@ -117,8 +117,15 @@ main(int argc, char *argv[]) if (!(client_fd < 0) && (msg_len = read(client_fd, msg, sizeof(msg) - 1)) > 0) { // client sent something msg[msg_len] = '\0'; - handle_ipc_event(msg); - close(client_fd); + + FILE *file = fdopen(client_fd, "w"); + if (!file) { + warn("failed to open client as file\n"); + close(client_fd); + } else { + handle_ipc_event(file, msg); + fclose(file); + } } }