| @@ -1,6 +1,6 @@
.\" geomyidae.8 handcrafted in GNU groff -mdoc using nvi
.\"
-.Dd February 23, 2020
+.Dd March 17, 2021
.Dt GEOMYIDAE 8
.Os
.
@@ -17,6 +17,7 @@
.Op Fl d
.Op Fl e
.Op Fl n
+.Op Fl s
.Op Fl l Ar logfile
.Op Fl v Ar loglevel
.Op Fl b Ar base
@@ -79,7 +80,8 @@ values if set. See
.Ic OPTIONS
below for specifics. Launching geomyidae automatically is best done via a UNIX
run-time (rc.d) script; several sample rc.d scripts are included in the geomyidae
-source archive.
+source archive. Logging in geomyidae can be done through either logfiles
+or syslog.
.
.Sh OPTIONS
geomyidae options and default settings:
@@ -108,6 +110,9 @@ Disable execution of any CGI or DCGI script.
.It Fl n
Don't perform reverse lookups.
.
+.It Fl s
+Log using syslog for logging.
+.
.It Fl l Ar logfile
Specify file where log output is written (no default).
. |
| @@ -26,6 +26,7 @@
#include
#include
#include
+#include
#ifdef ENABLE_TLS
#include
@@ -46,12 +47,14 @@ enum {
};
int glfd = -1;
+int dosyslog = 0;
int loglvl = 47;
-int *listfds = NULL;
-int nlistfds = 0;
int revlookup = 1;
char *logfile = NULL;
+int *listfds = NULL;
+int nlistfds = 0;
+
char *argv0;
char stdbase[] = "/var/gopher";
char *stdport = "70";
@@ -104,15 +107,17 @@ logentry(char *host, char *port, char *qry, char *status)
struct tm *ptr;
char timstr[128], *ahost;
- if (glfd >= 0) {
- tim = time(0);
- ptr = gmtime(&tim);
-
+ if (glfd >= 0 || dosyslog) {
ahost = revlookup ? reverselookup(host) : host;
- strftime(timstr, sizeof(timstr), "%F %T %z", ptr);
-
- dprintf(glfd, "[%s|%s|%s|%s] %s\n",
- timstr, ahost, port, status, qry);
+ if (dosyslog) {
+ syslog("[%s|%s|%s] %s\n", ahost, port, status, qry);
+ } else {
+ tim = time(0);
+ ptr = gmtime(&tim);
+ strftime(timstr, sizeof(timstr), "%F %T %z", ptr);
+ dprintf(glfd, "[%s|%s|%s|%s] %s\n",
+ timstr, ahost, port, status, qry);
+ }
if (revlookup)
free(ahost);
}
@@ -284,7 +289,9 @@ sighandler(int sig)
case SIGABRT:
case SIGTERM:
case SIGKILL:
- if (logfile != NULL && glfd != -1) {
+ if (dosyslog) {
+ closelog();
+ } else if (logfile != NULL && glfd != -1) {
close(glfd);
glfd = -1;
}
@@ -402,7 +409,7 @@ getlistenfd(struct addrinfo *hints, char *bindip, char *port, int *rlfdnum)
void
usage(void)
{
- dprintf(2, "usage: %s [-46cden] [-l logfile] "
+ dprintf(2, "usage: %s [-46cdens] [-l logfile] "
#ifdef ENABLE_TLS
"[-t keyfile certfile] "
#endif /* ENABLE_TLS */
@@ -490,6 +497,9 @@ main(int argc, char *argv[])
if (sport == NULL)
sport = port;
break;
+ case 's':
+ dosyslog = 1;
+ break;
#ifdef ENABLE_TLS
case 't':
dotls = 1;
@@ -590,7 +600,13 @@ main(int argc, char *argv[])
}
}
- if (logfile != NULL) {
+ 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);
+ }
+ } else if (logfile != NULL) {
glfd = open(logfile, O_APPEND | O_WRONLY | O_CREAT, 0644);
if (glfd < 0) {
perror("log");
@@ -906,7 +922,9 @@ main(int argc, char *argv[])
close(sock);
}
- if (logfile != NULL && glfd != -1) {
+ if (dosyslog) {
+ closelog();
+ } else if (logfile != NULL && glfd != -1) {
close(glfd);
glfd = -1;
} |