Re: smtpd: err/errx -> fatal/fatalx

2021-05-26 Thread Todd C . Miller
On Wed, 26 May 2021 16:24:42 +0200, Eric Faurot wrote:

> This diff replaces calls to err(3)/errx(3) with fatal()/fatalx() from
> log.c for code that runs in the deamon (we want errors logged to
> syslog, not stderr).  It's pretty mechanical, with two things to note:
>
> The call to default_config() has to be done after log_init() in smtpd.c,
> and log_init() is called early in smtpctl.c, since it uses files (iobuf.c)
> that uses the log api. It still logs to stderr though.

OK millert@

 - todd



smtpd: err/errx -> fatal/fatalx

2021-05-26 Thread Eric Faurot
This diff replaces calls to err(3)/errx(3) with fatal()/fatalx() from
log.c for code that runs in the deamon (we want errors logged to
syslog, not stderr).  It's pretty mechanical, with two things to note:

The call to default_config() has to be done after log_init() in smtpd.c,
and log_init() is called early in smtpctl.c, since it uses files (iobuf.c)
that uses the log api. It still logs to stderr though.

Eric.

Index: bounce.c
===
RCS file: /cvs/src/usr.sbin/smtpd/bounce.c,v
retrieving revision 1.83
diff -u -p -r1.83 bounce.c
--- bounce.c31 Dec 2020 08:27:15 -  1.83
+++ bounce.c26 May 2021 11:14:04 -
@@ -23,7 +23,6 @@
 #include 
 #include 
 
-#include 
 #include 
 #include 
 #include 
@@ -141,7 +140,7 @@ bounce_add(uint64_t evpid)
}
 
if (evp.type != D_BOUNCE)
-   errx(1, "bounce: evp:%016" PRIx64 " is not of type D_BOUNCE!",
+   fatalx("bounce: evp:%016" PRIx64 " is not of type D_BOUNCE!",
evp.id);
 
key.msgid = evpid_to_msgid(evpid);
Index: ca.c
===
RCS file: /cvs/src/usr.sbin/smtpd/ca.c,v
retrieving revision 1.38
diff -u -p -r1.38 ca.c
--- ca.c5 Mar 2021 12:37:32 -   1.38
+++ ca.c26 May 2021 11:17:24 -
@@ -22,7 +22,6 @@
 #include 
 #include 
 
-#include 
 #include 
 #include 
 #include 
@@ -117,7 +116,7 @@ ca(void)
mproc_disable(p_dispatcher);
 
if (pledge("stdio", NULL) == -1)
-   err(1, "pledge");
+   fatal("pledge");
 
event_dispatch();
fatalx("exited event loop");
@@ -333,7 +332,7 @@ ca_imsg(struct mproc *p, struct imsg *im
return;
}
 
-   errx(1, "ca_imsg: unexpected %s imsg", imsg_to_str(imsg->hdr.type));
+   fatalx("ca_imsg: unexpected %s imsg", imsg_to_str(imsg->hdr.type));
 }
 
 /*
Index: compress_gzip.c
===
RCS file: /cvs/src/usr.sbin/smtpd/compress_gzip.c,v
retrieving revision 1.11
diff -u -p -r1.11 compress_gzip.c
--- compress_gzip.c 23 Jan 2021 16:11:11 -  1.11
+++ compress_gzip.c 26 May 2021 11:14:58 -
@@ -24,7 +24,6 @@
 #include 
 
 #include 
-#include 
 #include 
 #include 
 #include 
Index: control.c
===
RCS file: /cvs/src/usr.sbin/smtpd/control.c,v
retrieving revision 1.126
diff -u -p -r1.126 control.c
--- control.c   31 Dec 2020 08:27:15 -  1.126
+++ control.c   26 May 2021 11:15:39 -
@@ -25,7 +25,6 @@
 #include 
 #include 
 
-#include 
 #include 
 #include 
 #include 
@@ -159,7 +158,7 @@ control_imsg(struct mproc *p, struct ims
return;
}
 
-   errx(1, "control_imsg: unexpected %s imsg",
+   fatalx("control_imsg: unexpected %s imsg",
imsg_to_str(imsg->hdr.type));
 }
 
@@ -254,7 +253,7 @@ control(void)
control_listen();
 
if (pledge("stdio unix recvfd sendfd", NULL) == -1)
-   err(1, "pledge");
+   fatal("pledge");
 
event_dispatch();
fatalx("exited event loop");
Index: dict.c
===
RCS file: /cvs/src/usr.sbin/smtpd/dict.c,v
retrieving revision 1.6
diff -u -p -r1.6 dict.c
--- dict.c  23 Dec 2018 16:06:24 -  1.6
+++ dict.c  26 May 2021 11:16:31 -
@@ -20,12 +20,12 @@
 #include 
 #include 
 
-#include 
 #include 
 #include 
 #include 
 
 #include "dict.h"
+#include "log.h"
 
 struct dictentry {
SPLAY_ENTRY(dictentry)  entry;
@@ -72,7 +72,7 @@ dict_set(struct dict *d, const char *k, 
key.key = k;
if ((entry = SPLAY_FIND(_dict, >dict, )) == NULL) {
if ((entry = dict_alloc(k, data)) == NULL)
-   err(1, "dict_set: malloc");
+   fatal("dict_set: malloc");
SPLAY_INSERT(_dict, >dict, entry);
old = NULL;
d->count += 1;
@@ -90,9 +90,9 @@ dict_xset(struct dict *d, const char * k
struct dictentry*entry;
 
if ((entry = dict_alloc(k, data)) == NULL)
-   err(1, "dict_xset: malloc");
+   fatal("dict_xset: malloc");
if (SPLAY_INSERT(_dict, >dict, entry))
-   errx(1, "dict_xset(%p, %s)", d, k);
+   fatalx("dict_xset(%p, %s)", d, k);
d->count += 1;
 }
 
@@ -115,7 +115,7 @@ dict_xget(struct dict *d, const char *k)
 
key.key = k;
if ((entry = SPLAY_FIND(_dict, >dict, )) == NULL)
-   errx(1, "dict_xget(%p, %s)", d, k);
+   fatalx("dict_xget(%p, %s)", d, k);
 
return (entry->data);
 }
@@ -146,7 +146,7 @@ dict_xpop(struct dict *d, const char *k)
 
key.key = k;
if ((entry = SPLAY_FIND(_dict, >dict, )) == NULL)
-   errx(1, "dict_xpop(%p, %s)", d, k);
+