X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fprocess.c;h=eb084f4e54b3e98683c4d7e72dcf019bb209f84a;hb=b3b89e46b1b84fa6cf1726fabe9e9c7bb0d3d831;hp=0f399e79605dc8a7e357427beb06113cc9a45a15;hpb=cc3c69c892b0dad9a6ece0a0f4ccd429a22fcbff;p=meshlink diff --git a/src/process.c b/src/process.c index 0f399e79..eb084f4e 100644 --- a/src/process.c +++ b/src/process.c @@ -23,7 +23,6 @@ #include "conf.h" #include "connection.h" #include "control.h" -#include "device.h" #include "edge.h" #include "event.h" #include "logger.h" @@ -214,72 +213,4 @@ bool detach(void) { return true; } -bool execute_script(const char *name, char **envp) { -#ifdef HAVE_SYSTEM - char *scriptname; - char *command; - xasprintf(&scriptname, "%s" SLASH "%s%s", confbase, name, scriptextension); - - /* First check if there is a script */ - - if(access(scriptname, F_OK)) { - free(scriptname); - return true; - } - - logger(DEBUG_STATUS, LOG_INFO, "Executing script %s", name); - -#ifdef HAVE_PUTENV - /* Set environment */ - - for(int i = 0; envp[i]; i++) - putenv(envp[i]); -#endif - - if(scriptinterpreter) - xasprintf(&command, "%s \"%s\"", scriptinterpreter, scriptname); - else - xasprintf(&command, "\"%s\"", scriptname); - - int status = system(command); - - free(command); - free(scriptname); - - /* Unset environment */ - - for(int i = 0; envp[i]; i++) { - char *e = strchr(envp[i], '='); - if(e) { - char p[e - envp[i] + 1]; - strncpy(p, envp[i], e - envp[i]); - p[e - envp[i]] = '\0'; - putenv(p); - } - } - -#ifdef WEXITSTATUS - if(status != -1) { - if(WIFEXITED(status)) { /* Child exited by itself */ - if(WEXITSTATUS(status)) { - logger(DEBUG_ALWAYS, LOG_ERR, "Script %s exited with non-zero status %d", - name, WEXITSTATUS(status)); - return false; - } - } else if(WIFSIGNALED(status)) { /* Child was killed by a signal */ - logger(DEBUG_ALWAYS, LOG_ERR, "Script %s was killed by signal %d (%s)", - name, WTERMSIG(status), strsignal(WTERMSIG(status))); - return false; - } else { /* Something strange happened */ - logger(DEBUG_ALWAYS, LOG_ERR, "Script %s terminated abnormally", name); - return false; - } - } else { - logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "system", strerror(errno)); - return false; - } -#endif -#endif - return true; -}