-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(scriptname, &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);
-
- free(scriptname);
-
- 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(scriptname, envp);
-}