]> diplodocus.org Git - nmh/blobdiff - sbr/ext_hook.c
h/prototypes.h: Remove mhlsbr() prototype; no such function.
[nmh] / sbr / ext_hook.c
index 186f77c38d095a555763c1173b5be936776f7a96..ede098f09fd4dbb288a6d46811a3c49c74abf6e0 100644 (file)
@@ -1,6 +1,4 @@
-/*
- *
- *     Run a program that hooks into some other system.  The first argument is
+/*     Run a program that hooks into some other system.  The first argument is
  *     name of the hook to use, the second is the full path name of a mail message.
  *     The third argument is also the full path name of a mail message, or a NULL
  *     pointer if it isn't needed.  Look in the context for an error message if
@@ -8,7 +6,12 @@
  *     Only produce the error message once.
  */
 
-#include <h/mh.h>
+#include "h/mh.h"
+#include "ext_hook.h"
+#include "context_find.h"
+#include "pidstatus.h"
+#include "arglist.h"
+#include "error.h"
 
 int
 ext_hook(char *hook_name, char *message_file_name_1, char *message_file_name_2)
@@ -20,15 +23,15 @@ ext_hook(char *hook_name, char *message_file_name_1, char *message_file_name_2)
     int                vecp;                   /* Vector index */
     char       *program;               /* Name of program to execute */
 
-    static  int        did_message = 0;        /* set if we've already output a message */
+    static bool        did_message;            /* set if we've already output a message */
 
     if ((hook = context_find(hook_name)) == NULL)
-       return (OK);
+       return OK;
 
     switch (pid = fork()) {
     case -1:
        status = NOTOK;
-       advise(NULL, "external database may be out-of-date.");
+       inform("external database may be out-of-date.");
        break;
 
     case 0:
@@ -38,7 +41,7 @@ ext_hook(char *hook_name, char *message_file_name_1, char *message_file_name_2)
        vec[vecp++] = NULL;
        execvp(program, vec);
        advise(program, "Unable to execute");
-       _exit(-1);
+       _exit(1);
        /* NOTREACHED */
 
     default:
@@ -46,22 +49,20 @@ ext_hook(char *hook_name, char *message_file_name_1, char *message_file_name_2)
        break;
     }
 
-    if (status != OK) {
-       if (did_message == 0) {
-           char *msghook;
-           if ((msghook = context_find("msg-hook")) != NULL)
-               advise(NULL, msghook);
-           else {
-               char errbuf[BUFSIZ];
-               snprintf(errbuf, sizeof(errbuf), "external hook \"%s\"", hook);
-               pidstatus(status, stderr, errbuf);
-           }
-           did_message = 1;
-       }
+    if (status == OK)
+       return OK;
 
-       return (NOTOK);
+    if (!did_message) {
+        char *msghook;
+        if ((msghook = context_find("msg-hook")) != NULL)
+            inform("%s", msghook);
+        else {
+            char errbuf[BUFSIZ];
+            snprintf(errbuf, sizeof(errbuf), "external hook \"%s\"", hook);
+            pidstatus(status, stderr, errbuf);
+        }
+        did_message = true;
     }
 
-    else
-       return (OK);
+    return NOTOK;
 }