Give the magic `current time' constant used by `fw_log' a sensible name.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 5 Feb 2016 01:07:18 +0000 (01:07 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 5 Feb 2016 01:07:18 +0000 (01:07 +0000)
endpt.c
exec.c
file.c
fwd.c
fwd.h

diff --git a/endpt.c b/endpt.c
index 1fbf188..97efef1 100644 (file)
--- a/endpt.c
+++ b/endpt.c
@@ -123,9 +123,9 @@ void endpt_kill(endpt *a)
 
   if (a->f & b->f & EPF_FILE) {
     if (t->c->ab.err)
-      fw_log(-1, "[%s] error: %s", t->desc, strerror(t->c->ab.err));
+      fw_log(NOW, "[%s] error: %s", t->desc, strerror(t->c->ab.err));
     else if (t->c->ba.err)
-      fw_log(-1, "[%s] error: %s", t->desc, strerror(t->c->ba.err));
+      fw_log(NOW, "[%s] error: %s", t->desc, strerror(t->c->ba.err));
     if (t->s & EPS_AB)
       chan_close(&t->c->ab);
     if (!(b->f & EPF_PENDING) && (t->s & EPS_BA))
diff --git a/exec.c b/exec.c
index afd7942..d41a31d 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -450,7 +450,7 @@ static void xept_attach(endpt *e, reffd *in, reffd *out)
   /* --- Make a pipe for standard error --- */
 
   if (pipe(fd)) {
-    fw_log(-1, "[%s] couldn't create pipe: %s", xe->desc, strerror(errno));
+    fw_log(NOW, "[%s] couldn't create pipe: %s", xe->desc, strerror(errno));
     return;
   }
   fdflags(fd[0], O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
@@ -458,7 +458,7 @@ static void xept_attach(endpt *e, reffd *in, reffd *out)
   /* --- Fork a child, and handle an error if there was one --- */
 
   if ((kid = fork()) == -1) {
-    fw_log(-1, "[%s] couldn't fork: %s", xe->desc, strerror(errno));
+    fw_log(NOW, "[%s] couldn't fork: %s", xe->desc, strerror(errno));
     close(fd[0]);
     close(fd[1]);
     return;
@@ -563,7 +563,7 @@ static void xept_attach(endpt *e, reffd *in, reffd *out)
     xept_list->prev = xe;
   xept_list = xe;
   if (!(xe->xo->f & XF_NOLOG))
-    fw_log(-1, "[%s] started with pid %i", xe->desc, kid);
+    fw_log(NOW, "[%s] started with pid %i", xe->desc, kid);
   fw_inc();
   return;
 }
@@ -600,9 +600,9 @@ static void xept_destroy(xept *xe)
     /* Nothin' doin' */;
   else if (WIFEXITED(xe->st)) {
     if (WEXITSTATUS(xe->st) == 0)
-      fw_log(-1, "[%s] pid %i exited successfully", xe->desc, xe->kid);
+      fw_log(NOW, "[%s] pid %i exited successfully", xe->desc, xe->kid);
     else {
-      fw_log(-1, "[%s] pid %i failed: status %i",
+      fw_log(NOW, "[%s] pid %i failed: status %i",
             xe->desc, xe->kid, WEXITSTATUS(xe->st));
     }
   } else if (WIFSIGNALED(xe->st)) {
@@ -616,9 +616,10 @@ static void xept_destroy(xept *xe)
     sprintf(buf, "signal %i", WTERMSIG(xe->st));
     s = buf;
 #endif
-    fw_log(-1, "[%s] pid %i failed: %s", xe->desc, xe->kid, s);
+    fw_log(NOW, "[%s] pid %i failed: %s", xe->desc, xe->kid, s);
   } else
-    fw_log(-1, "[%s] pid %i failed: unrecognized status", xe->desc, xe->kid);
+    fw_log(NOW, "[%s] pid %i failed: unrecognized status",
+          xe->desc, xe->kid);
 
   /* --- Free up the parent-side resources --- */
 
@@ -683,7 +684,7 @@ static void xept_error(char *p, size_t len, void *v)
 {
   xept *xe = v;
   if (p)
-    fw_log(-1, "[%s] pid %i: %s", xe->desc, xe->kid, p);
+    fw_log(NOW, "[%s] pid %i: %s", xe->desc, xe->kid, p);
   else {
     close(xe->err.reader.fd);
     selbuf_destroy(&xe->err);
diff --git a/file.c b/file.c
index 88b7666..8b4f533 100644 (file)
--- a/file.c
+++ b/file.c
@@ -140,7 +140,7 @@ static reffd *file_nullref(void)
   else {
     int n;
     if ((n = open("/dev/null", O_RDWR)) < 0) {
-      fw_log(-1, "couldn't open `/dev/null': %s", strerror(errno));
+      fw_log(NOW, "couldn't open `/dev/null': %s", strerror(errno));
       return (0);
     }
     fdflags(n, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
@@ -359,7 +359,7 @@ static endpt *file_endpt(fdata *f, const char *desc)
     case FTYPE_NAME: {
       int fd;
       if ((fd = open(f->in.u.name, O_RDONLY | O_NONBLOCK)) < 0) {
-       fw_log(-1, "[%s] couldn't open `%s' for reading: %s",
+       fw_log(NOW, "[%s] couldn't open `%s' for reading: %s",
               desc, f->in.u.name, strerror(errno));
        return (0);
       }
@@ -391,7 +391,7 @@ static endpt *file_endpt(fdata *f, const char *desc)
       if ((m & O_CREAT) &&
          (fd = open(f->out.u.name, m | O_EXCL, f->fa.mode)) < 0 &&
          (errno != EEXIST || (m & O_EXCL))) {
-       fw_log(-1, "[%s] couldn't create `%s': %s",
+       fw_log(NOW, "[%s] couldn't create `%s': %s",
               desc, f->out.u.name, strerror(errno));
        REFFD_DEC(in);
        return (0);
@@ -399,11 +399,11 @@ static endpt *file_endpt(fdata *f, const char *desc)
 
       if (fd != -1) {
        if (fattr_apply(f->out.u.name, &f->fa)) {
-         fw_log(-1, "[%s] couldn't apply file attributes to `%s': %s",
+         fw_log(NOW, "[%s] couldn't apply file attributes to `%s': %s",
                 desc, f->out.u.name, strerror(errno));
        }
       } else if ((fd = open(f->out.u.name, m & ~O_CREAT)) < 0) {
-       fw_log(-1, "[%s] couldn't open `%s': %s",
+       fw_log(NOW, "[%s] couldn't open `%s': %s",
               desc, f->out.u.name, strerror(errno));
        REFFD_DEC(in);
        return (0);
diff --git a/fwd.c b/fwd.c
index 5b4e248..df5c821 100644 (file)
--- a/fwd.c
+++ b/fwd.c
@@ -241,7 +241,7 @@ void fw_log(time_t t, const char *fmt, ...)
   if (flags & FW_QUIET)
     return;
 
-  if (t == -1)
+  if (t == NOW)
     t = time(0);
   tm = localtime(&t);
   DENSURE(&d, 64);
@@ -305,7 +305,7 @@ static void fw_tidy(int n, void *p)
     default: abort();
   }
 
-  fw_log(-1, "closing down gracefully on %s", sn);
+  fw_log(NOW, "closing down gracefully on %s", sn);
   source_killall();
 }
 
@@ -327,7 +327,7 @@ static void fw_die(int n, void *p)
     default: abort();
   }
 
-  fw_log(-1, "closing down abruptly on %s", sn);
+  fw_log(NOW, "closing down abruptly on %s", sn);
   source_killall();
   endpt_killall();
 }
@@ -350,20 +350,20 @@ static void fw_reload(int n, void *p)
 
   assert(n == SIGHUP);
   if (!conffiles) {
-    fw_log(-1, "no configuration files to reload: ignoring SIGHUP");
+    fw_log(NOW, "no configuration files to reload: ignoring SIGHUP");
     return;
   }
-  fw_log(-1, "reloading configuration files...");
+  fw_log(NOW, "reloading configuration files...");
   source_killall();
   scan_create(&sc);
   for (cf = conffiles; cf; cf = cf->next) {
     if ((fp = fopen(cf->name, "r")) == 0)
-      fw_log(-1, "error loading `%s': %s", cf->name, strerror(errno));
+      fw_log(NOW, "error loading `%s': %s", cf->name, strerror(errno));
     else
       scan_add(&sc, scan_file(fp, cf->name, 0));
   }
   parse(&sc);
-  fw_log(-1, "... reload completed OK");
+  fw_log(NOW, "... reload completed OK");
 }
 
 /*----- Startup and options parsing ---------------------------------------*/
@@ -702,10 +702,10 @@ int main(int argc, char *argv[])
       if (!sel_select(sel))
        selerr = 0;
       else if (errno != EINTR && errno != EAGAIN) {
-       fw_log(-1, "error from select: %s", strerror(errno));
+       fw_log(NOW, "error from select: %s", strerror(errno));
        selerr++;
        if (selerr > 8) {
-         fw_log(-1, "too many consecutive select errors: bailing out");
+         fw_log(NOW, "too many consecutive select errors: bailing out");
          exit(EXIT_FAILURE);
        }
       }
diff --git a/fwd.h b/fwd.h
index ba06144..a900e31 100644 (file)
--- a/fwd.h
+++ b/fwd.h
@@ -271,9 +271,13 @@ extern sel_state *sel;
 extern const char grammar_text[];
 extern const char option_text[];
 
+/* --- Generally useful magic constants --- */
+
+#define NOW ((time_t)-1)
+
 /* --- @fw_log@ --- *
  *
- * Arguments:  @time_t t@ = when the connection occurred or (@-1@)
+ * Arguments:  @time_t t@ = when the connection occurred or (@NOW@)
  *             @const char *fmt@ = format string to fill in
  *             @...@ = other arguments
  *