#endif lint
#include <stdio.h>
+#include <stdlib.h>
#include <update.h>
#include <sys/file.h>
#include <sys/time.h>
#include <sys/wait.h>
+#include <sys/stat.h>
+#include <time.h>
+#include <fcntl.h>
#include <signal.h>
#include <ctype.h>
#include <moira.h>
#include <moira_site.h>
#include "dcm.h"
#include "mit-copyright.h"
+#include <unistd.h>
+#include <com_err.h>
-extern char *ctime();
-extern char *getenv();
-extern int log_flags;
-extern char *error_message();
-char *itoa();
+extern int log_flags, errno;
int gqval();
-long time();
/* declared global so that we can get the current time from different places. */
dbg = s ? atoi(s) : 0;
umask(UMASK);
log_flags = 0;
- setlinebuf(stderr);
- setlinebuf(stdout);
+
+ setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
+ setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
while(++arg - argv < argc) {
if (**arg == '-')
int status, lock_fd, ex, (*cstat)();
struct timezone tz;
register char *p;
- union wait waits;
+ int waits;
+ struct sigaction action, prevaction;
if (dbg & DBG_VERBOSE)
com_err(whoami, 0, "starting pass over services");
}
com_err(whoami, status, " running %s", dfgen_prog);
- cstat = signal(SIGCHLD, SIG_DFL);
- waits.w_status = system(dfgen_cmd);
- signal(SIGCHLD, cstat);
- if (waits.w_termsig) {
+
+ action.sa_flags = 0;
+ sigemptyset(&action.sa_mask);
+ action.sa_handler = SIG_DFL;
+ sigaction(SIGCHLD, &action, &prevaction);
+ waits = system(dfgen_cmd);
+ sigaction(SIGCHLD, &prevaction, NULL);
+ if (WIFSIGNALED(waits)) {
status = MR_COREDUMP;
com_err(whoami, status, " %s exited on signal %d",
- dfgen_prog, waits.w_termsig);
- } else if (waits.w_retcode) {
+ dfgen_prog, WTERMSIG(waits));
+ } else if (WEXITSTATUS(waits)) {
/* extract the process's exit value */
- status = waits.w_retcode + ERROR_TABLE_BASE_sms;
+ status = WEXITSTATUS(waits) + ERROR_TABLE_BASE_sms;
com_err(whoami, status, " %s exited", dfgen_prog);
}
+
if (SOFT_FAIL(status)) {
free(qargv[5]);
qargv[5] = strsave(error_message(status));
status = mr_update_server(svc->service, machine, svc->target,
svc->script);
if (status == MR_SUCCESS) {
- argv[2] = "0";
+ argv[2] = argv[4] = "0";
argv[3] = "1";
free(argv[8]);
argv[8] = itoa(tv.tv_sec);
} else if (SOFT_FAIL(status)) {
+ argv[4] = "0";
free(argv[6]);
argv[6] = strsave(error_message(status));
} else { /* HARD_FAIL */
argv[2] = itoa(shost.override);
+ argv[4] = "0";
argv[5] = itoa(status);
free(argv[6]);
argv[6] = strsave(error_message(status));
free(qargv[4]);
free(qargv[5]);
close(lock_fd);
- free(argv[2]);
- argv[4] = "0";
- free(argv[5]);
status = mr_query_with_retry("set_server_host_internal",
9, argv,scream,NULL);
+ free(argv[2]);
+ free(argv[5]);
if (status)
com_err(whoami, status, " setting host state again");
return(-1);
}
- free(argv[2]);
- free(argv[5]);
}
- argv[4] = "0";
close(lock_fd);
status = mr_query_with_retry("set_server_host_internal", 9, argv,
scream, NULL);
if (status)
com_err(whoami, status, " setting host state again");
+/* free(argv[2]);
+ free(argv[5]); */
free_mach:
free(machine);
close(lock_fd);