Check with witch exit-code sendmail/spost exit and give an better error
authorPhilipp Takacs <philipp@bureaucracy.de>
Fri, 2 May 2014 21:21:35 +0000 (23:21 +0200)
committerPhilipp Takacs <philipp@bureaucracy.de>
Sat, 13 Dec 2014 12:50:29 +0000 (13:50 +0100)
message. So the User sees better wat's wrong. At the moment only
exit-code 75 is handlel extra.

uip/send.c

index e1e7518..adb2039 100644 (file)
@@ -15,6 +15,8 @@
 #include <h/mime.h>
 #include <h/tws.h>
 #include <h/utils.h>
+#include <sysexits.h>
+#include <sys/wait.h>
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -22,6 +24,7 @@
 #include <time.h>
 
 int debugsw = 0;  /* global */
+int verbosesw = 0;
 char *altmsg   = NULL;
 char *annotext = NULL;
 char *distfile = NULL;
@@ -50,6 +53,7 @@ static int signandenc(char *);
 static void clean_up_temporary_files(void);
 static int get_line(void);
 static void make_mime_composition_file_entry(char *);
+static char* strexit(int status);
 
 
 static struct swit switches[] = {
@@ -114,7 +118,9 @@ main(int argc, char **argv)
                                debugsw++;
                                /* fall */
                        case VERBSW:
+                               verbosesw += 2;
                        case NVERBSW:
+                               verbosesw--;
                                vec[vecp++] = --cp;
                                continue;
                        }
@@ -636,13 +642,17 @@ sendaux(char **vec, int vecp, char *drft, struct stat *st)
 
        default:
                /* parent process -- wait for it */
-               if ((status = pidwait(child_id, NOTOK)) == OK) {
+               status = pidwait(child_id, NOTOK);
+               if (WIFEXITED(status) && WEXITSTATUS(status) == EX_OK) {
                        if (annotext) {
                                anno(st);
                        }
-               } else {
-                       /* spost failed */
-                       advise(NULL, "message not delivered to anyone");
+               }
+               else {
+                       advise(NULL, "%s", strexit(status));
+                       if (verbosesw <= 0) {
+                               advise(NULL, "Try using -v to get better output");
+                       }
                        if (distfile) {
                                unlink(drft);
                                if (rename(backup, drft) == NOTOK) {
@@ -651,9 +661,9 @@ sendaux(char **vec, int vecp, char *drft, struct stat *st)
                                }
                        }
                }
-               break;
        }
 
+
        return status;
 }
 
@@ -699,6 +709,24 @@ anno(struct stat *st)
 }
 
 
+char*
+strexit(int status)
+{
+       if (WIFSIGNALED(status)) {
+               return "spost or sendmail killed by signal";
+       }
+       if (!WIFEXITED(status)) {
+               return "sendmail stopt for unknown reasen, message not deliverd to anyone";
+       }
+       switch (WEXITSTATUS(status)) {
+               case EX_TEMPFAIL:
+                       return "Temporary error, maby the MTA hase queued the Mail";
+               default:
+                       return "sendmail stopt for unknown reasen, message not deliverd to anyone";
+       }
+}
+
+
 static void
 armed_done(int status)
 {