X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fprocess.c;h=0898e70e18aff4e967f0cea8856bf942278ad8b6;hp=0b17d7acd2a5a5c94e98547c757a81f8d3464411;hb=431fa10b37e78172a03c952e28a0364cc0e438f0;hpb=6ad5dd1a9adb1c1322ceb44d6f0fd160229e72ff diff --git a/src/process.c b/src/process.c index 0b17d7ac..0898e70e 100644 --- a/src/process.c +++ b/src/process.c @@ -1,7 +1,7 @@ /* process.c -- process management functions - Copyright (C) 1999-2002 Ivo Timmermans , - 2000-2002 Guus Sliepen + Copyright (C) 1999-2002 Ivo Timmermans , + 2000-2002 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 @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: process.c,v 1.1.2.38 2002/03/24 16:22:59 guus Exp $ + $Id: process.c,v 1.1.2.44 2002/09/04 14:17:28 guus Exp $ */ #include "config.h" @@ -207,65 +207,43 @@ cp Execute the program name, with sane environment. All output will be redirected to syslog. */ -void _execute_script(const char *name) __attribute__ ((noreturn)); -void _execute_script(const char *name) +void _execute_script(const char *scriptname, char **envp) __attribute__ ((noreturn)); +void _execute_script(const char *scriptname, char **envp) { - char *scriptname; char *s; cp -#ifdef HAVE_UNSETENV - unsetenv("NETNAME"); - unsetenv("DEVICE"); - unsetenv("INTERFACE"); -#endif - - if(netname) - { - asprintf(&s, "NETNAME=%s", netname); - putenv(s); /* Don't free s! see man 3 putenv */ - } - - if(device) - { - asprintf(&s, "DEVICE=%s", device); - putenv(s); /* Don't free s! see man 3 putenv */ - } - - if(interface) - { - asprintf(&s, "INTERFACE=%s", interface); - putenv(s); /* Don't free s! see man 3 putenv */ - } - + while(*envp) + putenv(*envp++); + chdir("/"); - asprintf(&scriptname, "%s/%s", confbase, name); - /* Close all file descriptors */ closelog(); /* <- this means we cannot use syslog() here anymore! */ fcloseall(); execl(scriptname, NULL); /* No return on success */ - - if(errno != ENOENT) /* Ignore if the file does not exist */ - exit(1); /* Some error while trying execl(). */ - else - exit(0); + + openlog("tinc", LOG_CONS | LOG_PID, LOG_DAEMON); + syslog(LOG_ERR, _("Could not execute `%s': %s"), scriptname, strerror(errno)); + exit(errno); } /* Fork and execute the program pointed to by name. */ -int execute_script(const char *name) +int execute_script(const char *name, char **envp) { pid_t pid; int status; struct stat s; + char *scriptname; cp + asprintf(&scriptname, "%s/%s", confbase, name); + /* First check if there is a script */ - if(stat(name, &s)) + if(stat(scriptname, &s)) return 0; if((pid = fork()) < 0) @@ -279,6 +257,8 @@ cp if(debug_lvl >= DEBUG_STATUS) syslog(LOG_INFO, _("Executing script %s"), name); + free(scriptname); + if(waitpid(pid, &status, 0) == pid) { if(WIFEXITED(status)) /* Child exited by itself */ @@ -312,7 +292,7 @@ cp cp /* Child here */ - _execute_script(name); + _execute_script(scriptname, envp); }