about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-01-13 08:31:23 +0000
committerEric Wong <mwrap-perl@80x24.org>2023-01-13 08:30:27 +0000
commit73d7e6dddf6a12b764d7570f3de50779c24e630b (patch)
tree2ac448e908a0972af0bc8d52dbf5f1d36a185153
parentbca8045e15c2373196634be46eef4a93029c8417 (diff)
downloadmwrap-73d7e6dddf6a12b764d7570f3de50779c24e630b.tar.gz
perror(3) is standardized and reduces our binary text size a bit:

    text           data     bss     dec     hex filename
   80330           1888    4352   86570   1522a before/Mwrap.so
   80043           1896    4352   86291   15113 after/Mwrap.so
-rw-r--r--httpd.h24
-rw-r--r--mwrap_core.h4
2 files changed, 14 insertions, 14 deletions
diff --git a/httpd.h b/httpd.h
index 9219d36..8a105aa 100644
--- a/httpd.h
+++ b/httpd.h
@@ -221,7 +221,7 @@ static FILE *fbuf_init(struct mw_fbuf *fb)
 {
         fb->ptr = NULL;
         fb->fp = open_memstream(&fb->ptr, &fb->len);
-        if (!fb->fp) fprintf(stderr, "open_memstream: %m\n");
+        if (!fb->fp) perror("open_memstream");
         return fb->fp;
 }
 
@@ -237,7 +237,7 @@ static int fbuf_close(struct mw_fbuf *fb)
 {
         int e = ferror(fb->fp) | fclose(fb->fp);
         fb->fp = NULL;
-        if (e) fprintf(stderr, "ferror|fclose: %m\n");
+        if (e) perror("ferror|fclose");
         return e;
 }
 
@@ -279,7 +279,7 @@ static enum mw_qev h1_200(struct mw_h1 *h1, struct mw_fbuf *fb, const char *ct)
          */
         off_t clen = ftello(fb->fp);
         if (clen < 0) {
-                fprintf(stderr, "ftello: %m\n");
+                perror("ftello");
                 fbuf_close(fb);
                 return h1_close(h1);
         }
@@ -468,7 +468,7 @@ static off_t write_loc_name(FILE *fp, const struct src_loc *l)
         off_t beg = ftello(fp);
 
         if (beg < 0) {
-                fprintf(stderr, "ftello: %m\n");
+                perror("ftello");
                 return beg;
         }
         if (l->f) {
@@ -498,7 +498,7 @@ static off_t write_loc_name(FILE *fp, const struct src_loc *l)
         }
         off_t end = ftello(fp);
         if (end < 0) {
-                fprintf(stderr, "ftello: %m\n");
+                perror("ftello");
                 return end;
         }
         return end - beg;
@@ -868,7 +868,7 @@ static enum mw_qev h1_drain_input(struct mw_h1 *h1, struct mw_h1req *h1r,
                                 return h1_close(h1);
                         default: /* ENOMEM, ENOBUFS, ... */
                                 assert(errno != EBADF);
-                                fprintf(stderr, "read: %m\n");
+                                perror("read");
                                 return h1_close(h1);
                         }
                 }
@@ -1001,7 +1001,7 @@ static enum mw_qev h1_event_step(struct mw_h1 *h1, struct mw_h1d *h1d)
         if (!h1r) {
                 h1r = h1d->shared_h1r = malloc(sizeof(*h1r));
                 if (!h1r) {
-                        fprintf(stderr, "h1r malloc: %m\n");
+                        perror("h1r malloc");
                         return h1_close(h1);
                 }
         }
@@ -1045,7 +1045,7 @@ static enum mw_qev h1_event_step(struct mw_h1 *h1, struct mw_h1d *h1d)
                                 return h1_close(h1);
                         default: /* ENOMEM, ENOBUFS, ... */
                                 assert(errno != EBADF);
-                                fprintf(stderr, "read: %m\n");
+                                perror("read");
                                 return h1_close(h1);
                         }
                 }
@@ -1153,7 +1153,7 @@ static void h1d_unlink(struct mw_h1d *h1d, bool do_close)
         if (h1d->lfd < 0 || !h1d->pid_len)
                 return;
         if (getsockname(h1d->lfd, &sa.any, &len) < 0) {
-                fprintf(stderr, "getsockname: %m\n");
+                perror("getsockname");
                 return;
         }
         if (do_close) { /* only safe to close if thread isn't running */
@@ -1219,13 +1219,13 @@ static int h1d_init(struct mw_h1d *h1d, const char *menv)
                 return fprintf(stderr, "unlink(%s): %m\n", sa.un.sun_path);
         h1d->lfd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
         if (h1d->lfd < 0)
-                return fprintf(stderr, "socket: %m\n");
+                return perror("socket"), 1;
         if (bind(h1d->lfd, &sa.any, (socklen_t)sizeof(sa)) < 0) {
-                fprintf(stderr, "bind: %m\n");
+                perror("bind");
                 goto close_fail;
         }
         if (listen(h1d->lfd, 1024) < 0) {
-                fprintf(stderr, "listen: %m\n");
+                perror("listen");
                 goto close_fail;
         }
         h1d->alive = 1; /* runs in parent, before pthread_create */
diff --git a/mwrap_core.h b/mwrap_core.h
index a246fea..a84cd6d 100644
--- a/mwrap_core.h
+++ b/mwrap_core.h
@@ -742,7 +742,7 @@ char **bt_syms(void * const *addrlist, uint32_t size)
 #else /* make FreeBSD look like glibc output: */
         char **s = backtrace_symbols_fmt(addrlist, size, "%f(%n%D) [%a]");
 #endif
-        if (!s) fprintf(stderr, "backtrace_symbols: %m\n");
+        if (!s) perror("backtrace_symbols");
         return s;
 }
 
@@ -1057,7 +1057,7 @@ __attribute__((constructor)) static void mwrap_ctor(void)
                 h->real = h;
                 call_rcu(&h->as.dead, free_hdr_rcu);
         } else
-                fprintf(stderr, "malloc: %m\n");
+                perror("malloc");
 
         h1d_start();
         CHECK(int, 0, pthread_sigmask(SIG_SETMASK, &old, NULL));