]> diplodocus.org Git - mdeliver/commitdiff
(run_processor): New function.
authorepg <>
Sun, 8 Sep 2002 07:52:40 +0000 (07:52 +0000)
committerepg <>
Sun, 8 Sep 2002 07:52:40 +0000 (07:52 +0000)
(main): Move the logic of running the optional message processor to
the new run_processor function.

mdeliver.c

index 7706aa5815e79f4a764bdbc78b1f1b27ff465cb3..39be29698ad07261a84d7d8e210b482c5ece9e3f 100644 (file)
@@ -244,17 +244,46 @@ deliver(char *maildir, char *newfn)
     }
 }
 
-int
-main(int argc, char *argv[])
+/* Run a program to process the new message. */
+static void
+run_processor(char *argv[], char *newfn)
 {
-    char *home;
-    char newfn[TMPNAMLEN];
     pid_t pid;
     FILE *errfile;
     char *fail;
     int olderrno;
     int fd;
 
+    if ((pid = fork()) > 0) {
+        return;
+    } else if (pid == 0) {
+        argv[0] = argv[1];
+        argv[1] = newfn;
+        execv(argv[0], argv);
+        fail = "exec";
+    } else {
+        fail = "fork";
+    }
+    olderrno = errno;
+
+    /* If we got here fork or exec failed, so try to write an error
+     * message where later mail processors can find it.  We really
+     * can't do anything about it if this fails. */
+    memcpy(newfn, "err", 3);
+    mkdir("err", 0700);
+    fd = open(newfn, O_WRONLY | O_EXCL | O_CREAT, 0644);
+    errfile = fdopen(fd, "w");
+    if (errfile) {
+        fprintf(errfile, "%s:%d\n", fail, olderrno);
+    }
+}
+
+int
+main(int argc, char *argv[])
+{
+    char *home;
+    char newfn[TMPNAMLEN];
+
     if (argv[1] && argv[1][0] == '-' && argv[1][1] == 'v') {
         puts(rcsid);
         return 0;
@@ -271,28 +300,7 @@ main(int argc, char *argv[])
     deliver("Maildir", newfn);
 
     if (argv[1]) {
-        if ((pid = fork()) > 0) {
-            return 0;
-        } else if (pid == 0) {
-            argv[0] = argv[1];
-            argv[1] = newfn;
-            execv(argv[0], argv);
-            fail = "exec";
-        } else {
-            fail = "fork";
-        }
-        olderrno = errno;
-
-        /* If we got here fork or exec failed, so try to write an
-         * error message where later mail processors can find it.  We
-         * really can't do anything about it if this fails. */
-        memcpy(newfn, "err", 3);
-        mkdir("err", 0700);
-        fd = open(newfn, O_WRONLY | O_EXCL | O_CREAT, 0644);
-        errfile = fdopen(fd, "w");
-        if (errfile) {
-            fprintf(errfile, "%s:%d\n", fail, olderrno);
-        }
+        run_processor(argv, newfn);
     }
 
     /* Always return 0 because deliver exits if it fails, and if it