]> andersk Git - moira.git/blobdiff - dcm/dcm.c
in ASCII backups, write `|'s within fields as \174 instead of \| so
[moira.git] / dcm / dcm.c
index 52fbfaa46949c69f4f774fb14a06e2e909b04b3b..5a2d32a238f883abeeab851f734cdb909ab617c6 100644 (file)
--- a/dcm/dcm.c
+++ b/dcm/dcm.c
@@ -15,24 +15,25 @@ static char rcsid_dcm_c[] = "$Header$";
 #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. */
@@ -54,8 +55,9 @@ char *argv[];
        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 == '-')
@@ -157,7 +159,8 @@ do_services()
     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");
@@ -217,18 +220,23 @@ do_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));
@@ -386,15 +394,17 @@ struct service *svc;
        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));
@@ -422,24 +432,22 @@ struct service *svc;
                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);
This page took 0.036486 seconds and 4 git commands to generate.