tSet priority on every invokation. Shorten the check for openlog. - geomyidae - A small C-based gopherd. (gopher://bitreich.org/1/scm/geomyidae)
git clone git://r-36.net/geomyidae
Log
Files
Refs
README
LICENSE
---
commit 42b52f54ede822d8e937025394d69702d5f910d3
parent c555b684d623e711d266e6b15c5abba55ab02347
Author: Christoph Lohmann <20h@r-36.net>
Date:   Thu, 18 Mar 2021 18:57:35 +0100

Set priority on every invokation. Shorten the check for openlog.

Thanks escapeinsert for the proposal!

Diffstat:
  main.c                              |      11 +++++------

1 file changed, 5 insertions(+), 6 deletions(-)
---
diff --git a/main.c b/main.c
t@@ -48,6 +48,7 @@ enum {
 
 int glfd = -1;
 int dosyslog = 0;
+int logpriority = LOG_INFO|LOG_DAEMON;
 int loglvl = 47;
 int revlookup = 1;
 char *logfile = NULL;
t@@ -110,7 +111,8 @@ logentry(char *host, char *port, char *qry, char *status)
         if (glfd >= 0 || dosyslog) {
                 ahost = revlookup ? reverselookup(host) : host;
                 if (dosyslog) {
-                        syslog("[%s|%s|%s] %s\n", ahost, port, status, qry);
+                        syslog(logpriority, "[%s|%s|%s] %s\n", ahost, port,
+                                        status, qry);
                 } else {
                         tim = time(0);
                         ptr = gmtime(&tim);
t@@ -601,11 +603,8 @@ main(int argc, char *argv[])
         }
 
         if (dosyslog) {
-                if (!dofork) {
-                        openlog("geomyidae", LOG_CONS|LOG_PERROR, LOG_DAEMON|LOG_INFO);
-                } else {
-                        openlog("geomyidae", LOG_NDELAY|LOG_PID, LOG_DAEMON|LOG_INFO);
-                }
+                openlog("geomyidae", dofork? LOG_NDELAY|LOG_PID \
+                                : LOG_CONS|LOG_PERROR, logpriority);
         } else if (logfile != NULL) {
                 glfd = open(logfile, O_APPEND | O_WRONLY | O_CREAT, 0644);
                 if (glfd < 0) {