From dd7beccdf87889976d653f4debd47bdd80be7cba Mon Sep 17 00:00:00 2001 From: "flyingscorpio@clevo" Date: Fri, 21 Oct 2022 16:31:07 +0200 Subject: [PATCH] Remove obsolete service() function --- src/server.c | 66 ---------------------------------------------------- 1 file changed, 66 deletions(-) diff --git a/src/server.c b/src/server.c index 944f9ef..b7801ee 100644 --- a/src/server.c +++ b/src/server.c @@ -172,72 +172,6 @@ void *ClientSender(void *arg) { pthread_exit(0); } -/* Handles a client after its connection */ -// TODO: remove this function -void service(int sockid) { - int i, n, t; - pid_t pid; - char buf[BUF_LEN], buf2[BUF_LEN], eot = EOT; - void *memory = NULL; - char **command_line; - char delim[] = {' ', '\t', '\n', '\0'}; - char *token, *text; - - while (1) { - if ((n = readline(sockid, buf, BUF_LEN)) == -1) { - sprintf(buf, "ERROR: receive message - probably too long\n"); - write(sockid, buf, strlen(buf) + 1); - } else { - if ((pid = fork()) == -1) { - sprintf(buf, "ERROR: system\n"); - write(sockid, buf, strlen(buf) + 1); - close(sockid); - return; - } else if (pid == 0) { - /* The child has the command to execute in buf */ - - /* Redirect stdout and stderr to the socket */ - dup2(sockid, STDOUT_FILENO); - dup2(sockid, STDERR_FILENO); - - strcpy(buf2, buf); - text = buf; - t = 0; - while ((token = strtok_r(text, delim, &text)) != NULL) { - t++; - } - t++; // To add NULL at the end - - if ((memory = malloc(t * sizeof(memory))) == NULL) { - sprintf(buf, "ERROR: memory\n"); - write(sockid, buf, strlen(buf) + 1); - close(sockid); - return; - } - command_line = (char**) memory; - - text = buf2; - for (i = 0; ((token = strtok_r(text, delim, &text)) != NULL); i++) { - command_line[i] = token; - } - command_line[i] = NULL; - - execvp(command_line[0], command_line); - - /* If execvp worked, the following code will never be executed. - * No need for a test */ - perror("execvp"); - exit(EXIT_FAILURE); - } else { - /* Back to parent */ - wait(NULL); - write(sockid, &eot, 1); - } - } - } - close(sockid); -} - /* Handler for signal() */ void interrupt(int signal) { switch (signal) {