]> diplodocus.org Git - mdeliver/commitdiff
Only include <sysexits.h> if MDELIVER_EXITCODE is not defined, and if
authorepg <>
Fri, 6 Sep 2002 05:58:27 +0000 (05:58 +0000)
committerepg <>
Fri, 6 Sep 2002 05:58:27 +0000 (05:58 +0000)
it isn't defined, define it to EX_TEMPFAIL.  Change all references to
EX_TEMPFAIL to MDELIVER_EXITCODE.

mdeliver.c

index b0a7091..900955a 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sysexits.h>
 #include <time.h>
 #include <unistd.h>
 
+#ifndef MDELIVER_EXITCODE
+#include <sysexits.h>
+#define MDELIVER_EXITCODE EX_TEMPFAIL
+#endif
+
 #if !defined(HOST_NAME_MAX)
 #if defined MAXHOSTNAMELEN
 #define HOST_NAME_MAX MAXHOSTNAMELEN
@@ -87,7 +91,7 @@ get_filename(char *fn)
     pid = getpid();
 
     if (gethostname(host, sizeof(host)) != 0) {
-        err(EX_TEMPFAIL, "Failed gethostname");
+        err(MDELIVER_EXITCODE, "Failed gethostname");
     }
 
     for (try = 0; ; try++) {
@@ -106,7 +110,7 @@ get_filename(char *fn)
         }
 
         if (try == 2) {
-            errx(EX_TEMPFAIL, "Attempted filename exists.");
+            errx(MDELIVER_EXITCODE, "Attempted filename exists.");
         }
 
         sleep(2);
@@ -130,7 +134,7 @@ strip_from(int fd, char *buf, char *fn)
     r = read(STDIN_FILENO, buf, 5);
     if (r != 5) {
         unlink(fn);
-        err(EX_TEMPFAIL, "Failed read from stdin");
+        err(MDELIVER_EXITCODE, "Failed read from stdin");
     }
 
     if (strncmp(buf, "From ", 5) == 0) {
@@ -143,12 +147,12 @@ strip_from(int fd, char *buf, char *fn)
 
         if (r == -1) {
             unlink(fn);
-            err(EX_TEMPFAIL, "Failed read from stdin");
+            err(MDELIVER_EXITCODE, "Failed read from stdin");
         }
     } else {
         if (full_write(fd, buf, r) != r) {
             unlink(fn);
-            err(EX_TEMPFAIL, "Failed write(%s)", fn);
+            err(MDELIVER_EXITCODE, "Failed write(%s)", fn);
         }
     }
 }
@@ -164,23 +168,23 @@ copy_message(int fd, char *buf, char *fn)
            || (r == -1 && errno == EINTR)) {
         if (full_write(fd, buf, r) != r) {
             unlink(fn);
-            err(EX_TEMPFAIL, "Failed write(%s)", fn);
+            err(MDELIVER_EXITCODE, "Failed write(%s)", fn);
         }
     }
 
     if (r == -1) {
         unlink(fn);
-        err(EX_TEMPFAIL, "Failed read from stdin");
+        err(MDELIVER_EXITCODE, "Failed read from stdin");
     }
 
     if (fsync(fd) < 0) {
         unlink(fn);
-        err(EX_TEMPFAIL, "Failed fsync(%s)", fn);
+        err(MDELIVER_EXITCODE, "Failed fsync(%s)", fn);
     }
 
     if (close(fd) < 0) {
         unlink(fn);
-        err(EX_TEMPFAIL, "Failed close(%s)", fn);
+        err(MDELIVER_EXITCODE, "Failed close(%s)", fn);
     }
 }
 
@@ -193,14 +197,14 @@ deliver(char *maildir, char *newfn)
                                  * evil) space optimization. */
 
     if (chdir(maildir) != 0) {
-        err(EX_TEMPFAIL, "Failed chdir(%s)", maildir);
+        err(MDELIVER_EXITCODE, "Failed chdir(%s)", maildir);
     }
 
     get_filename(fn);
 
     fd = open(fn, O_WRONLY | O_EXCL | O_CREAT, 0600);
     if (fd < 0) {
-        err(EX_TEMPFAIL, "Failed open(%s)", fn);
+        err(MDELIVER_EXITCODE, "Failed open(%s)", fn);
     }
 
     /* From this point, we have a tmp file, so if someting fails we
@@ -214,7 +218,7 @@ deliver(char *maildir, char *newfn)
 
     if (rename(fn, newfn) != 0) {
         unlink(fn);
-        err(EX_TEMPFAIL, "Failed rename(%s, new)", fn);
+        err(MDELIVER_EXITCODE, "Failed rename(%s, new)", fn);
     }
 }
 
@@ -234,11 +238,11 @@ main(int argc, char *argv[])
     }
 
     if (!(home = getenv("HOME"))) {
-        err(EX_TEMPFAIL, "Failed getenv(HOME)");
+        err(MDELIVER_EXITCODE, "Failed getenv(HOME)");
     }
 
     if (chdir(home) != 0) {
-        err(EX_TEMPFAIL, "Failed chdir(HOME)");
+        err(MDELIVER_EXITCODE, "Failed chdir(HOME)");
     }
 
     deliver("Maildir", newfn);