X-Git-Url: http://tinc-vpn.org/git/browse?a=blobdiff_plain;ds=sidebyside;f=src%2Fprocess.c;h=86953adccf60cc05c09e36e435612696cd1776c7;hb=19d16e40ccfb39461eda5336f4e754e10a640aba;hp=0f399e79605dc8a7e357427beb06113cc9a45a15;hpb=cc3c69c892b0dad9a6ece0a0f4ccd429a22fcbff;p=tinc diff --git a/src/process.c b/src/process.c index 0f399e79..86953adc 100644 --- a/src/process.c +++ b/src/process.c @@ -41,6 +41,7 @@ bool sigalrm = false; extern char **g_argv; extern bool use_logfile; +extern bool use_syslog; /* Some functions the less gifted operating systems might lack... */ @@ -185,6 +186,8 @@ bool init_service(void) { Detach from current terminal */ bool detach(void) { + logmode_t logmode; + #ifndef HAVE_MINGW signal(SIGPIPE, SIG_IGN); signal(SIGUSR1, SIG_IGN); @@ -206,80 +209,13 @@ bool detach(void) { #endif } - openlogger(identname, use_logfile?LOGMODE_FILE:(do_detach?LOGMODE_SYSLOG:LOGMODE_STDERR)); + logmode = use_logfile?LOGMODE_FILE:LOGMODE_SYSLOG; + if(do_detach && !use_syslog) + logmode = LOGMODE_STDERR; + openlogger(identname, logmode); logger(DEBUG_ALWAYS, LOG_NOTICE, "tincd %s (%s %s) starting, debug level %d", VERSION, __DATE__, __TIME__, debug_level); 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; -}