X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fprocess.c;h=262b092c165404dd2e78f8e586a6661fac611b8a;hp=01ebe494ba7c79b0ab2cc62cb0b5c2454da2537f;hb=aa9d61b5cd0d6dd8b911cfd06f6bb50ec028d0d1;hpb=4c85542894f7fca823b119b05e07179deb24229a diff --git a/src/process.c b/src/process.c index 01ebe494..262b092c 100644 --- a/src/process.c +++ b/src/process.c @@ -1,7 +1,7 @@ /* process.c -- process management functions Copyright (C) 1999-2005 Ivo Timmermans, - 2000-2009 Guus Sliepen + 2000-2011 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,6 +25,7 @@ #include "device.h" #include "edge.h" #include "logger.h" +#include "net.h" #include "node.h" #include "pidfile.h" #include "process.h" @@ -41,9 +42,10 @@ extern char *identname; extern char *pidfilename; extern char **g_argv; extern bool use_logfile; -extern volatile bool running; -sigset_t emptysigset; +#ifndef HAVE_MINGW +static sigset_t emptysigset; +#endif static int saved_debug_level = -1; @@ -103,13 +105,18 @@ bool install_service(void) { command, NULL, NULL, NULL, NULL, NULL); if(!service) { - logger(LOG_ERR, "Could not create %s service: %s", identname, winerror(GetLastError())); - return false; + DWORD lasterror = GetLastError(); + logger(LOG_ERR, "Could not create %s service: %s", identname, winerror(lasterror)); + if(lasterror != ERROR_SERVICE_EXISTS) + return false; } - ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &description); - - logger(LOG_INFO, "%s service installed", identname); + if(service) { + ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &description); + logger(LOG_INFO, "%s service installed", identname); + } else { + service = OpenService(manager, identname, SERVICE_ALL_ACCESS); + } if(!StartService(service, 0, NULL)) logger(LOG_WARNING, "Could not start %s service: %s", identname, winerror(GetLastError())); @@ -349,8 +356,9 @@ bool detach(void) { bool execute_script(const char *name, char **envp) { #ifdef HAVE_SYSTEM int status, len; - char *scriptname, *p; + char *scriptname; int i; + char *interpreter = NULL; #ifndef HAVE_MINGW len = xasprintf(&scriptname, "\"%s/%s\"", confbase, name); @@ -371,6 +379,16 @@ bool execute_script(const char *name, char **envp) { } #endif + // Custom scripts interpreter + if(get_config_string(lookup_config(config_tree, "ScriptsInterpreter"), &interpreter)) { + // Force custom scripts interpreter allowing execution of scripts on android without execution flag (such as on /sdcard) + free(scriptname); + len = xasprintf(&scriptname, "%s \"%s/%s\"", interpreter, confbase, name); + free(interpreter); + if(len < 0) + return false; + } + ifdebug(STATUS) logger(LOG_INFO, "Executing script %s", name); #ifdef HAVE_PUTENV @@ -390,7 +408,7 @@ bool execute_script(const char *name, char **envp) { for(i = 0; envp[i]; i++) { char *e = strchr(envp[i], '='); if(e) { - p = alloca(e - envp[i] + 1); + char p[e - envp[i] + 1]; strncpy(p, envp[i], e - envp[i]); p[e - envp[i]] = '\0'; putenv(p); @@ -504,7 +522,7 @@ static RETSIGTYPE sigusr1_handler(int a) { } static RETSIGTYPE sigusr2_handler(int a) { - dump_device_stats(); + devops.dump_stats(); dump_nodes(); dump_edges(); dump_subnets(); @@ -539,6 +557,7 @@ static struct { {SIGCHLD, ignore_signal_handler}, {SIGALRM, sigalrm_handler}, {SIGWINCH, sigwinch_handler}, + {SIGABRT, SIG_DFL}, {0, NULL} }; #endif