projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add /sw/{include,lib} to search paths if they exist
[tinc]
/
src
/
process.c
diff --git
a/src/process.c
b/src/process.c
index
a7f5d5f
..
ae1985d
100644
(file)
--- a/
src/process.c
+++ b/
src/process.c
@@
-17,7
+17,7
@@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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.
37 2002/03/19 00:07:09
guus Exp $
+ $Id: process.c,v 1.1.2.
40 2002/04/27 11:40:45
guus Exp $
*/
#include "config.h"
*/
#include "config.h"
@@
-30,6
+30,7
@@
#include <syslog.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <syslog.h>
#include <sys/ioctl.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
@@
-206,10
+207,9
@@
cp
Execute the program name, with sane environment. All output will be
redirected to syslog.
*/
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 *
script
name) __attribute__ ((noreturn));
+void _execute_script(const char *
script
name)
{
{
- char *scriptname;
char *s;
cp
#ifdef HAVE_UNSETENV
char *s;
cp
#ifdef HAVE_UNSETENV
@@
-238,19
+238,16
@@
cp
chdir("/");
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 */
/* 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);
}
/*
}
/*
@@
-260,7
+257,16
@@
int execute_script(const char *name)
{
pid_t pid;
int status;
{
pid_t pid;
int status;
+ struct stat s;
+ char *scriptname;
cp
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));
if((pid = fork()) < 0)
{
syslog(LOG_ERR, _("System call `%s' failed: %s"), "fork", strerror(errno));
@@
-272,6
+278,8
@@
cp
if(debug_lvl >= DEBUG_STATUS)
syslog(LOG_INFO, _("Executing script %s"), name);
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 */
if(waitpid(pid, &status, 0) == pid)
{
if(WIFEXITED(status)) /* Child exited by itself */
@@
-305,7
+313,7
@@
cp
cp
/* Child here */
cp
/* Child here */
- _execute_script(name);
+ _execute_script(
script
name);
}
}