- pid_t pid;
- int status;
- struct stat s;
-cp
- /* First check if there is a script */
-
- if(stat(name, &s))
- return 0;
-
- if((pid = fork()) < 0)
- {
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "fork", strerror(errno));
- return -1;
- }
-
- if(pid)
- {
- if(debug_lvl >= DEBUG_STATUS)
- syslog(LOG_INFO, _("Executing script %s"), name);
-
- if(waitpid(pid, &status, 0) == pid)
- {
- if(WIFEXITED(status)) /* Child exited by itself */
- {
- if(WEXITSTATUS(status))
- {
- syslog(LOG_ERR, _("Process %d (%s) exited with non-zero status %d"), pid, name, WEXITSTATUS(status));
- return -1;
- }
- else
- return 0;
- }
- else if(WIFSIGNALED(status)) /* Child was killed by a signal */
- {
- syslog(LOG_ERR, _("Process %d (%s) was killed by signal %d (%s)"),
- pid, name, WTERMSIG(status), strsignal(WTERMSIG(status)));
- return -1;
- }
- else /* Something strange happened */
- {
- syslog(LOG_ERR, _("Process %d (%s) terminated abnormally"), pid, name);
- return -1;
- }
- }
- else
- {
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "waitpid", strerror(errno));
- return -1;
- }
- }
-cp
- /* Child here */
-
- _execute_script(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 true;
+
+ pid = fork();
+
+ if(pid < 0) {
+ logger(LOG_ERR, _("System call `%s' failed: %s"), "fork",
+ strerror(errno));
+ return false;
+ }
+
+ if(pid) {
+ ifdebug(STATUS) logger(LOG_INFO, _("Executing script %s"), name);
+
+ free(scriptname);
+
+ if(waitpid(pid, &status, 0) == pid) {
+ if(WIFEXITED(status)) { /* Child exited by itself */
+ if(WEXITSTATUS(status)) {
+ logger(LOG_ERR, _("Process %d (%s) exited with non-zero status %d"),
+ pid, name, WEXITSTATUS(status));
+ return false;
+ } else
+ return true;
+ } else if(WIFSIGNALED(status)) { /* Child was killed by a signal */
+ logger(LOG_ERR, _("Process %d (%s) was killed by signal %d (%s)"), pid,
+ name, WTERMSIG(status), strsignal(WTERMSIG(status)));
+ return false;
+ } else { /* Something strange happened */
+ logger(LOG_ERR, _("Process %d (%s) terminated abnormally"), pid,
+ name);
+ return false;
+ }
+ } else if (errno != EINTR) {
+ logger(LOG_ERR, _("System call `%s' failed: %s"), "waitpid",
+ strerror(errno));
+ return false;
+ }
+
+ /* Why do we get EINTR? */
+ return true;
+ }
+
+ /* Child here */
+
+ _execute_script(scriptname, envp);