]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
modern C: use err(3)
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 20 Apr 2022 09:55:38 +0000 (11:55 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 20 Oct 2022 11:17:27 +0000 (13:17 +0200)
contrib/receivestrip/mlmmj-receive-strip.c
include/mlmmj.h
src/mlmmj-bounce.c
src/mlmmj-list.c
src/mlmmj-maintd.c
src/mlmmj-process.c
src/mlmmj-receive.c
src/mlmmj-send.c
src/mlmmj-sub.c
src/mlmmj-unsub.c

index 23e404eb9690fc615f97992572e2311e582497ac..ea8392d9c9b5382be4862deb5b9771f9cfeb6458 100644 (file)
@@ -36,7 +36,7 @@
 #include <errno.h>
 #include <string.h>
 #include <sys/types.h>
-
+#include <err.h>
 
 
 #include "mlmmj.h"
@@ -435,9 +435,8 @@ int main(int argc, char **argv)
        }
 
        if(listdir == NULL) {
-               fprintf(stderr, "You have to specify -L\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "You have to specify -L\n"
+                   "%s -h for help\n", argv[0]);
        }
 
        /* Lets make sure no random user tries to send mail to the list */
@@ -449,10 +448,8 @@ int main(int argc, char **argv)
                                        "Have to invoke either as root "
                                        "or as the user owning listdir "
                                        "Invoked with uid = [%d]", (int)uid);
-                               writen(STDERR_FILENO,
-                                       "Have to invoke either as root "
-                                       "or as the user owning listdir\n", 60);
-                               exit(EXIT_FAILURE);
+                               errx(EXIT_FAILURE, "Have to invoke either as root "
+                                       "or as the user owning listdir");
                        }
                } else {
                        log_error(LOG_ARGS, "Could not stat %s", listdir);
index bf44064746a2433b8353f6d105a9c6b02aee32d0..82758ec314c94129aae3d4c21926c2bfc90f76a8 100644 (file)
@@ -103,10 +103,9 @@ void print_version(const char *prg);
                }
 
 #define CHECKFULLPATH(name) if(strchr(name, '/') == NULL) { \
-                       fprintf(stderr, "All mlmmj binaries have to " \
-                                       "be invoked with full path,\n" \
-                                       "e.g. /usr/local/bin/%s\n", name); \
-                       exit(EXIT_FAILURE); \
+                       errx(EXIT_FAILURE, "All mlmmj binaries have to " \
+                           "be invoked with full path,\n" \
+                           "e.g. /usr/local/bin/%s", name); \
                        };
 
 /* make sure we use the wrappers */
index bde2c3f3b3133b487ed11bbed57c4a7c8158af29..54f62e858ec38b86c551cb743590c7628fbed2d1 100644 (file)
@@ -34,6 +34,7 @@
 #include <sys/mman.h>
 #include <string.h>
 #include <ctype.h>
+#include <err.h>
 
 #include "getlistaddr.h"
 #include "getlistdelim.h"
@@ -235,10 +236,8 @@ int main(int argc, char **argv)
 
        if(listdir == NULL || (address == NULL && dsnbounce == 0)
                                || (number == NULL && probe == 0)) {
-               fprintf(stderr,
-                       "You have to specify -L, -a or -d and -n or -p\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "You have to specify -L, -a or -d and -n or -p\n"
+                   "%s -h for help", argv[0]);
        }
 
        /* Lets make sure no random user tries to do bouncehandling */
@@ -249,10 +248,8 @@ int main(int argc, char **argv)
                                log_error(LOG_ARGS,
                                        "Have to invoke either as root "
                                        "or as the user owning listdir");
-                               writen(STDERR_FILENO,
-                                       "Have to invoke either as root "
-                                       "or as the user owning listdir\n", 60);
-                               exit(EXIT_FAILURE);
+                               errx(EXIT_FAILURE, "Have to invoke either as root "
+                                       "or as the user owning listdir");
                        }
                } else {
                        log_error(LOG_ARGS, "Could not stat %s", listdir);
@@ -285,9 +282,8 @@ int main(int argc, char **argv)
        address = lowcaseaddr;
 
        if(number != NULL && probe != 0) {
-               fprintf(stderr, "You can only specify one of -n or -p\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "You can only specify one of -n or -p\n"
+                   "%s -h for help", argv[0]);
        }
 
        if (probe) {
index 2337e6a69fd23a7b4b3d7f824cd89da161727942..82d0d2fddce3b5634c4ec5feb2b83114c1de1506 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
+#include <err.h>
 
 #include "mlmmj.h"
 #include "wrappers.h"
@@ -143,9 +144,8 @@ int main(int argc, char **argv)
        }
 
        if(listdir == NULL) {
-               fprintf(stderr, "You have to specify -L\n"
-                               "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "You have to specify -L\n"
+                   "%s -h for help", argv[0]);
        }
 
        switch(typesub) {
@@ -172,8 +172,7 @@ int main(int argc, char **argv)
        if(subdir) {
                dirp = opendir(subdir);
                if(dirp == NULL) {
-                       fprintf(stderr, "Could not opendir(%s);\n", subdir);
-                       exit(EXIT_FAILURE);
+                       errx(EXIT_FAILURE,  "Could not opendir(%s);", subdir);
                }
                while((dp = readdir(dirp)) != NULL) {
                        if((strcmp(dp->d_name, "..") == 0) ||
index f555b57b4f72a0f4d1fd7c9266dac039b6b7ec92..c8caae995e20dc019bb9ad4c587b589ded61a1c0 100644 (file)
@@ -1069,15 +1069,13 @@ int main(int argc, char **argv)
        }
 
        if(listdir == NULL && dirlists == NULL) {
-               fprintf(stderr, "You have to specify -d or -L\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "You have to specify -d or -L\n"
+                   "%s -h for help", argv[0]);
        }
        
        if(listdir && dirlists) {
-               fprintf(stderr, "You have to specify either -d or -L\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "You have to specify either -d or -L\n"
+                   "%s -h for help", argv[0]);
        }
 
        bindir = mydirname(argv[0]);
index f7d2557b70497a259b504e962b401f081193d5ee..e192e5b626b698a814511c5b317f3805fed2ca00 100644 (file)
@@ -32,6 +32,7 @@
 #include <sys/wait.h>
 #include <libgen.h>
 #include <regex.h>
+#include <err.h>
 
 #include "mlmmj.h"
 #include "wrappers.h"
@@ -526,9 +527,8 @@ int main(int argc, char **argv)
        }
 
        if(listdir == NULL || mailfile == NULL) {
-               fprintf(stderr, "You have to specify -L and -m\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "You have to specify -L and -m\n"
+                   "%s -h for help", argv[0]);
        }
 
        /* Lets make sure no random user tries to send mail to the list */
@@ -539,10 +539,8 @@ int main(int argc, char **argv)
                                log_error(LOG_ARGS,
                                        "Have to invoke either as root "
                                        "or as the user owning listdir");
-                               writen(STDERR_FILENO,
-                                       "Have to invoke either as root "
-                                       "or as the user owning listdir\n", 60);
-                               exit(EXIT_FAILURE);
+                               errx(EXIT_FAILURE, "Have to invoke either as root "
+                                       "or as the user owning listdir");
                        }
                } else {
                        log_error(LOG_ARGS, "Could not stat %s", listdir);
index b67de9a27a810529e95dee1f98b9079819fb1f05..987ae29ee8d2a20324a6c0c224f7910feaf4db3f 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <libgen.h>
+#include <err.h>
 
 #include "mlmmj.h"
 #include "wrappers.h"
@@ -99,9 +100,8 @@ int main(int argc, char **argv)
        }
 
        if(listdir == NULL) {
-               fprintf(stderr, "You have to specify -L\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "You have to specify -L\n"
+                   "%s -h for help", argv[0]);
        }
 
        /* Lets make sure no random user tries to send mail to the list */
@@ -113,10 +113,8 @@ int main(int argc, char **argv)
                                        "Have to invoke either as root "
                                        "or as the user owning listdir "
                                        "Invoked with uid = [%d]", (int)uid);
-                               writen(STDERR_FILENO,
-                                       "Have to invoke either as root "
-                                       "or as the user owning listdir\n", 60);
-                               exit(EXIT_FAILURE);
+                               errx(EXIT_FAILURE, "Have to invoke either as root "
+                                       "or as the user owning listdir");
                        }
                } else {
                        log_error(LOG_ARGS, "Could not stat %s", listdir);
index cedd3d8ab0b9e41275e4fa8469140b6bb8bc6b01..65d3e276e448b67f9320f00300fb62d71be5dfd8 100644 (file)
@@ -42,6 +42,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <signal.h>
+#include <err.h>
 
 #include "mlmmj.h"
 #include "mlmmj-send.h"
@@ -887,9 +888,8 @@ int main(int argc, char **argv)
        }
 
        if(mailfilename == NULL || (listdir == NULL && listctrl == NULL)) {
-               fprintf(stderr, "You have to specify -m and -L or -l\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "You have to specify -m and -L or -l\n"
+                   "%s -h for help", argv[0]);
        }
 
        /* Lets make sure no random user tries to send mail to the list */
@@ -900,10 +900,9 @@ int main(int argc, char **argv)
                                log_error(LOG_ARGS,
                                        "Have to invoke either as root "
                                        "or as the user owning listdir");
-                               writen(STDERR_FILENO,
+                               errx(EXIT_FAILURE,
                                        "Have to invoke either as root "
-                                       "or as the user owning listdir\n", 60);
-                               exit(EXIT_FAILURE);
+                                       "or as the user owning listdir");
                        }
                } else {
                        log_error(LOG_ARGS, "Could not stat %s", listdir);
@@ -917,18 +916,15 @@ int main(int argc, char **argv)
        
        /* get the list address */
        if(listctrl[0] == '1' && (bounceaddr == NULL || to_addr == NULL)) {
-               fprintf(stderr, "With -l 1 you need -F and -T\n");
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "With -l 1 you need -F and -T");
        }
 
        if((listctrl[0] == '2' && (listdir == NULL || bounceaddr == NULL))) {
-               fprintf(stderr, "With -l 2 you need -L and -F\n");
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "With -l 2 you need -L and -F");
        }
 
        if((listctrl[0] == '7' && listdir == NULL)) {
-               fprintf(stderr, "With -l 7 you need -L\n");
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "With -l 7 you need -L");
        }
 
        verp = ctrlvalue(listdir, "verp");
index d21765aba0cf37a8bdc08b9a9ddacb500df2e3e4..29da25e3dd56b80c8bda79e050409a3929cb1707 100644 (file)
@@ -33,6 +33,7 @@
 #include <libgen.h>
 #include <sys/wait.h>
 #include <ctype.h>
+#include <err.h>
 
 #include "mlmmj.h"
 #include "mlmmj-sub.h"
@@ -716,21 +717,18 @@ int main(int argc, char **argv)
        }
 
        if(listdir == NULL) {
-               fprintf(stderr, "You have to specify -L\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "You have to specify -L\n"
+                   "%s -h for help", argv[0]);
        }
        
        if(address == NULL && modstr == NULL) {
-               fprintf(stderr, "You have to specify -a or -m\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "You have to specify -a or -m\n"
+                   "%s -h for help", argv[0]);
        }
 
        if(both + digest + nomail > 1) {
-               fprintf(stderr, "Specify at most one of -b, -d and -n\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "Specify at most one of -b, -d and -n\n"
+                   "%s -h for help", argv[0]);
        }
 
        if(digest)
@@ -741,9 +739,8 @@ int main(int argc, char **argv)
                typesub = SUB_BOTH;
 
        if(reasonsub == SUB_CONFIRM && subconfirm) {
-               fprintf(stderr, "Cannot specify both -C and -R\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "Cannot specify both -C and -R\n"
+                   "%s -h for help", argv[0]);
        }
 
        if(modstr) {
@@ -781,7 +778,7 @@ int main(int argc, char **argv)
                        if(setuid(st.st_uid) < 0) {
                                perror("setuid");
                                fprintf(stderr, "Continuing as uid %d\n",
-                                               (int)uid);
+                                   (int)uid);
                        }
                }
        }
index 8e13f3cac5ce8b38806fc0779d7d5ebac87a1429..e4f598ab912cad84d9966a82d9d1d9ae32ec69e6 100644 (file)
@@ -593,15 +593,13 @@ int main(int argc, char **argv)
                }
        }
        if(listdir == 0 || address == 0) {
-               fprintf(stderr, "You have to specify -L and -a\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "You have to specify -L and -a\n"
+                   "%s -h for help", argv[0]);
        }
 
        if(digest + nomail + normal > 1) {
-               fprintf(stderr, "Specify at most one of -d, -n and -N\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "Specify at most one of -d, -n and -N\n"
+                   "%s -h for help", argv[0]);
        }
 
        if(digest)
@@ -612,21 +610,18 @@ int main(int argc, char **argv)
                typesub = SUB_NORMAL;
 
        if(confirmunsub && unsubconfirm) {
-               fprintf(stderr, "Cannot specify both -C and -c\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "Cannot specify both -C and -c\n"
+                   "%s -h for help", argv[0]);
        }
 
        if(reasonsub == SUB_CONFIRM && unsubconfirm) {
-               fprintf(stderr, "Cannot specify both -C and -R\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "Cannot specify both -C and -R\n"
+                   "%s -h for help", argv[0]);
        }
 
        if(reasonsub == SUB_BOUNCING && unsubconfirm) {
-               fprintf(stderr, "Cannot specify both -C and -b\n");
-               fprintf(stderr, "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
+               errx(EXIT_FAILURE, "Cannot specify both -C and -b\n"
+                   "%s -h for help", argv[0]);
        }
 
        /* Make the address lowercase */