X-Git-Url: http://nitlanguage.org diff --git a/c_src/exec_nit.c b/c_src/exec_nit.c index f339d8a..93f5f9b 100644 --- a/c_src/exec_nit.c +++ b/c_src/exec_nit.c @@ -4,7 +4,7 @@ * * This file is free software, which comes along with NIT. This software is * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. You can modify it is you want, provided this header * is kept unaltered, and a notification of the changes is added. * You are allowed to redistribute it and sell it, alone or is a part of @@ -14,19 +14,33 @@ #include "exec_nit.h" #include #include +#include +#include -se_exec_data_t* exec_Process_Process_basic_exec_execute_4(Process s, char *prog, char *args, int len, int pipeflag) { +se_exec_data_t* exec_Process_Process_basic_exec_execute_4(void *s, char *prog, char *args, int len, int pipeflag) { se_exec_data_t* result = NULL; int id; int in_fd[2]; int out_fd[2]; int err_fd[2]; - if (pipeflag & 1) - pipe(in_fd); - if (pipeflag & 2) - pipe(out_fd); - if (pipeflag & 4) - pipe(err_fd); + if (pipeflag & 1) { + int res = pipe(in_fd); + if ( res == -1 ) { + return NULL; + } + } + if (pipeflag & 2) { + int res = pipe(out_fd); + if ( res == -1 ) { + return NULL; + } + } + if (pipeflag & 4) { + int res = pipe(err_fd); + if ( res == -1 ) { + return NULL; + } + } id = fork(); if (id == 0) @@ -68,7 +82,7 @@ se_exec_data_t* exec_Process_Process_basic_exec_execute_4(Process s, char *prog, /* calls */ execvp(prog, arg); - abort(); + _exit(127); } else if (id > 0) { /* father */ @@ -96,6 +110,7 @@ se_exec_data_t* exec_Process_Process_basic_exec_execute_4(Process s, char *prog, } else result->err_fd = -1; } + return result; } @@ -127,3 +142,12 @@ void exec_NativeProcess_NativeProcess_wait_0(void*d) { data->running = 0; } } + +int string_NativeString_NativeString_system_0(const char *cmd) { + int status = system(cmd); + if (WIFSIGNALED(status) && WTERMSIG(status) == SIGINT) { + // cmd exited on SIGINT: in my opinion the user wants the main to be discontinued + kill(getpid(), SIGINT); + } + return status; +}