]> Git repositories of Nishi - rbuild.git/commitdiff
can take args
authorNishi <nishi@nishi.boats>
Fri, 11 Oct 2024 21:05:32 +0000 (21:05 +0000)
committerNishi <nishi@nishi.boats>
Fri, 11 Oct 2024 21:05:32 +0000 (21:05 +0000)
git-svn-id: file:///raid/svn-personal/rbuild/trunk@13 c68d3453-7f82-0740-9748-1d72386a946b

Server/server.c
Server/task.c

index e765c36bb2a71455f9aaf88205effc2d0f0bb4b3..c21e354bc89cb0fad97f5acd1c73bde36ba47387 100644 (file)
@@ -184,18 +184,21 @@ void rbs_server_handler(void* sockptr) {
                                break;
                        } else if(strcmp(cmd, "SECTION") == 0 && arg != NULL) {
                                if(strcmp(rbs_config_get(arg, "auth"), "") == 0 || section != NULL) {
+                                       rbs_write(sock, "FAIL\n", 5);
                                        free(line);
                                        break;
                                }
                                section = cm_strdup(arg);
                        } else if(strcmp(cmd, "USER") == 0 && arg != NULL) {
                                if(section == NULL || user != NULL) {
+                                       rbs_write(sock, "FAIL\n", 5);
                                        free(line);
                                        break;
                                }
                                user = cm_strdup(arg);
                        } else if(strcmp(cmd, "PASS") == 0 && arg != NULL) {
                                if(user == NULL || pass != NULL) {
+                                       rbs_write(sock, "FAIL\n", 5);
                                        free(line);
                                        break;
                                }
@@ -209,7 +212,9 @@ void rbs_server_handler(void* sockptr) {
                                        break;
                                }
                        } else if(strcmp(cmd, "CC") == 0 && arg != NULL && authed) {
-                               if(!rbs_task(sock, section, cmd, arg)) {
+                               if(rbs_task(sock, section, cmd, arg)) {
+                                       rbs_write(sock, "SUCCESS\n", 8);
+                               } else {
                                        rbs_write(sock, "FAIL\n", 5);
                                        free(line);
                                        break;
@@ -222,6 +227,8 @@ void rbs_server_handler(void* sockptr) {
                }
        }
 
+       rbs_write(sock, "BYE\n", 4);
+
        rbs_close(sock);
 #ifdef WINSOCK
        _endthread();
@@ -249,6 +256,9 @@ CMBOOL rbs_server_loop(void) {
                        if(p == 0) {
                                int* sockptr = malloc(sizeof(*sockptr));
                                *sockptr = sock;
+#ifndef WINSOCK
+                               signal(SIGCHLD, SIG_DFL);
+#endif
                                rbs_server_handler(sockptr);
                                _exit(0);
                        } else {
index 5963445bc1d2da72fb46742f08b69fbaecf69cc7..882bc5d06b95b372e59670e148ea15908c5a0fe6 100644 (file)
@@ -5,9 +5,16 @@
 #include "rbs_server.h"
 #include "rbs_config.h"
 
+#include <unistd.h>
+#include <string.h>
 #include <stddef.h>
 #include <stdlib.h>
 
+#ifdef __MINGW32__
+#else
+#include <sys/wait.h>
+#endif
+
 #include <cm_string.h>
 #include <cm_bool.h>
 
@@ -31,19 +38,31 @@ void rbs_stack_free(char** stack) {
        free(stack);
 }
 
-char** rbs_parse_args(const char* arg) {
+char** rbs_parse_args(const char* cmd, const char* arg) {
        char* str = cm_strdup(arg);
        char** stack = malloc(sizeof(*stack));
        int i;
        int incr = 0;
        stack[0] = NULL;
+       rbs_push(&stack, cmd);
        for(i = 0;; i++) {
                if(str[i] == 0 || str[i] == ' ') {
                        char oldc = str[i];
                        char* got = str + incr;
                        str[i] = 0;
 
-                       rbs_push(&stack, got);
+                       if(strlen(got) > 2 && got[0] == '-' && got[1] == 'o') {
+                               rbs_push(&stack, "-o");
+                               rbs_push(&stack, got + 2);
+                       } else if(strlen(got) > 2 && got[0] == '-' && got[1] == 'L') {
+                               rbs_push(&stack, "-L");
+                               rbs_push(&stack, got + 2);
+                       } else if(strlen(got) > 2 && got[0] == '-' && got[1] == 'I') {
+                               rbs_push(&stack, "-I");
+                               rbs_push(&stack, got + 2);
+                       } else {
+                               rbs_push(&stack, got);
+                       }
 
                        incr = i + 1;
                        if(oldc == 0) break;
@@ -56,8 +75,56 @@ char** rbs_parse_args(const char* arg) {
        return stack;
 }
 
+#ifdef __MINGW32__
+#else
+int outpipe[2];
+pid_t pid;
+
+CMBOOL rbs_start_process(const char* cmd, char** args) {
+       pipe(outpipe);
+       pid = fork();
+       if(pid == 0) {
+               dup2(outpipe[1], 1);
+               dup2(outpipe[1], 2);
+               close(outpipe[0]);
+               execvp(cmd, args);
+               _exit(-1);
+       } else if(pid == -1) {
+               return CMFALSE;
+       }
+       close(outpipe[1]);
+       return CMTRUE;
+}
+
+CMBOOL rbs_wait_process(int sock) {
+       int status;
+       unsigned char c = 0;
+       rbs_write(sock, "+", 1);
+       while(1) {
+               char oldc = c;
+               int len = read(outpipe[0], &c, 1);
+               if(len <= 0) break;
+               if(c == '\n') {
+                       rbs_write(sock, "\n", 1);
+               } else {
+                       if(oldc == '\n') rbs_write(sock, "+", 1);
+                       rbs_write(sock, &c, 1);
+               }
+       }
+       if(c != '\n') {
+               rbs_write(sock, "\n", 1);
+       }
+       waitpid(pid, &status, 0);
+       close(outpipe[0]);
+       return WEXITSTATUS(status) == 0;
+}
+#endif
+
 CMBOOL rbs_task(int sock, const char* section, const char* cmd, const char* arg) {
-       char** args = rbs_parse_args(arg);
+       char** args = rbs_parse_args("gcc", arg);
+       CMBOOL status = rbs_start_process("gcc", args);
        rbs_stack_free(args);
-       return CMFALSE;
+       if(!status) return CMFALSE;
+       rbs_write(sock, "SUCCESS\n", 8);
+       return rbs_wait_process(sock);
 }