scout: band-aid -Wformat-truncation
[openafs.git] / src / bozo / smail-notifier.c
index 3c52be3..e9a0aa6 100644 (file)
@@ -9,17 +9,14 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
 
+#include <roken.h>
 
-#include <afs/stds.h>
-#include <sys/types.h>
-#include <sys/file.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <stdio.h>
 #include <afs/afsutil.h>
+#ifdef HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
 
 /*
  * XXX CHANGE the following depedent stuff XXX
 
 #include "AFS_component_version_number.c"
 
-main(argc, argv)
-     int argc;
-     char **argv;
+int
+main(int argc, char **argv)
 {
     struct stat tstat;
     FILE *fin = stdin;
     char buf[BUFSIZ], *bufp, *bufp1, *typep, *cmd, *bp;
-    afs_int32 code, c, fd, id, pflags = -1, len, core = 0, lastE = 0;
-    char comLine[60], coreName[40], name[40], lastErrorName[50];
-    afs_int32 pid = -1, lastExit = -1, lastSignal = -1, rsCount = -1;
+    afs_int32 code, c, fd, pflags = -1, len, core = 0;
+    char comLine[60], coreName[40], name[40];
+    afs_int32 pid = -1, rsCount = -1;
     afs_int32 procStarts = -1;
     afs_int32 errorCode = -1, errorSignal = -1, goal = -1;
     time_t procStartTime = -1, rsTime = -1, lastAnyExit = -1, lastErrorExit = -1;
     char *timeStamp;
 
-    typep = (char *)malloc(50);
-    cmd = (char *)malloc(50);
-    bufp = bufp1 = (char *)malloc(1000);
+    typep = malloc(50);
+    cmd = malloc(50);
+    bufp = bufp1 = malloc(1000);
     while (fgets(buf, sizeof(buf), fin)) {
        code = sscanf(buf, "%s %s\n", typep, cmd);
        if (code < 2) {
@@ -68,12 +64,6 @@ main(argc, argv)
                    strcpy(coreName, cmd);
                else if (!strcmp(typep, "pid:"))
                    pid = atoi(cmd);
-#ifdef notdef
-               else if (!strcmp(typep, "lastExit:"))
-                   lastExit = atoi(cmd);
-               else if (!strcmp(typep, "lastSignal:"))
-                   lastSignal = atoi(cmd);
-#endif
                else if (!strcmp(typep, "flags:"))
                    pflags = atoi(cmd);
                else if (!strcmp(typep, "END")) {
@@ -171,12 +161,6 @@ main(argc, argv)
                  (core ? (c ? "a recent " : "an 'old' ") : "no "),
                  (core ? bp : ""));
     bufp += strlen(bufp);
-#ifdef notdef
-    (void)sprintf(bufp, "Last Exit code %d\n", lastExit);
-    bufp += strlen(bufp);
-    (void)sprintf(bufp, "Last Signal number %d\n", lastSignal);
-    bufp += strlen(bufp);
-#endif
     if (pflags == 1)
        strcpy(bp, "PROCESS STARTED");
     else if (pflags == 2)
@@ -216,16 +200,6 @@ main(argc, argv)
     bufp += strlen(bufp);
     (void)sprintf(bufp, "Last process terminating signal %d\n", errorSignal);
     bufp += strlen(bufp);
-#ifdef notdef
-    if (strcmp(lastErrorName, "(null)"))
-       lastE = 1;
-    if (lastE) {
-       (void)sprintf(bufp,
-                     "Short name of process that failed last in this bnode is: %s\n",
-                     lastErrorName);
-       bufp += strlen(bufp);
-    }
-#endif
     (void)sprintf(bufp, "The server is now %srunning\n",
                  (goal ? "" : "not "));
     bufp += strlen(bufp);
@@ -240,6 +214,18 @@ main(argc, argv)
      */
     sprintf(bufp1, "%s %s -s TESTING < %s", SENDMAIL, RECIPIENT, buf);
     code = system(bufp1);
+    if (code == -1)
+       perror("system");
+    else if (code == 127)
+       fprintf(stderr, "system: unable to execute shell\n");
+#ifdef WTERMSIG
+    else if (WIFSIGNALED(code))
+       fprintf(stderr, "%s terminated with signal %d\n", SENDMAIL,
+           WTERMSIG(code));
+    else if (WEXITSTATUS(code) != 0)
+       fprintf(stderr, "%s exited with status %d\n", SENDMAIL,
+           WEXITSTATUS(code));
+#endif /* WTERMSIG */
     unlink(buf);
     exit(0);
 }