X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fprocess.c;h=9d1c489ff88fbd1bbe2f583b40df802444a67649;hp=5c0eb9f91b0b1c10023b8e730aca8b4c4ed74774;hb=627f7c22b447bd464b536cd016278545674df93d;hpb=4fda4560bbdd41e217ce0e1a90ba98c79e4f3519 diff --git a/src/process.c b/src/process.c index 5c0eb9f9..9d1c489f 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.36 2002/03/11 11:23:04 guus Exp $ + $Id: process.c,v 1.1.2.41 2002/06/21 10:11:13 guus Exp $ */ #include "config.h" @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -81,6 +82,7 @@ int fcloseall(void) fclose(stdin); fclose(stdout); fclose(stderr); + return 0; } #endif @@ -205,10 +207,9 @@ 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) __attribute__ ((noreturn)); +void _execute_script(const char *scriptname) { - char *scriptname; char *s; cp #ifdef HAVE_UNSETENV @@ -237,19 +238,16 @@ cp 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); } /* @@ -259,7 +257,16 @@ int execute_script(const char *name) { 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(scriptname, &s)) + return 0; + if((pid = fork()) < 0) { syslog(LOG_ERR, _("System call `%s' failed: %s"), "fork", strerror(errno)); @@ -271,6 +278,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 */ @@ -304,7 +313,7 @@ cp cp /* Child here */ - _execute_script(name); + _execute_script(scriptname); }