summary refs log tree commit diff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2018-06-22 15:04:47 +0200
committerDuncaen <mail@duncano.de>2018-06-22 16:53:50 +0200
commit64acdc39935548eeca43fd3c31a6e59faa008a9b (patch)
tree35b56a815d23c75b5102b0a2275592c6d6feba6e
parent3095ba6629084a92542631fe8402070e5f089161 (diff)
downloadrunit-void-64acdc39935548eeca43fd3c31a6e59faa008a9b.tar.gz
runit-void-64acdc39935548eeca43fd3c31a6e59faa008a9b.tar.xz
runit-void-64acdc39935548eeca43fd3c31a6e59faa008a9b.zip
vlogger: add logger(1) compatible -s and -i flag, and -S to force syslog
-rw-r--r--vlogger.830
-rw-r--r--vlogger.c13
2 files changed, 36 insertions, 7 deletions
diff --git a/vlogger.8 b/vlogger.8
index 9dcb92d..cae3b12 100644
--- a/vlogger.8
+++ b/vlogger.8
@@ -6,7 +6,8 @@
 .Nd log messages to syslog or an arbitrary executable
 .Sh SYNOPSIS
 .Nm vlogger
-.Op Fl p Ar priority
+.Op Fl isS
+.Op Fl p Ar pri
 .Op Fl t Ar tag
 .Sh DESCRIPTION
 By default,
@@ -36,10 +37,33 @@ it uses
 .Dv foo
 as default
 .Ar tag .
+.Pp
+The options are as follows:
 .Bl -tag -width indent
-.It Fl p Ar priority
+.It Fl S
+Force
+.Nm
+to use
+.Xr syslog 3
+even if
+.Pa /etc/vlogger
+exists.
+.It Fl s
+Output the message to standard error, as well as
+.Xr syslog 3 .
+Only supported if
+.Xr syslog 3
+is used.
+.It Fl i
+Log the PID of the
+.Nm
+process.
+Only supported if
+.Xr syslog 3
+is used.
+.It Fl p Ar pri
 The.
-.Ar priority
+.Ar pri
 can be
 .Pa facility.level
 or just
diff --git a/vlogger.c b/vlogger.c
index a3f7a08..0393bc8 100644
--- a/vlogger.c
+++ b/vlogger.c
@@ -79,6 +79,8 @@ main(int argc, char *argv[])
 	char *p, *argv0;
 	char *tag = "vlogger";
 	int c;
+	int Sflag = 0;
+	int logflags = 0;
 	int facility = LOG_DAEMON;
 	int level = LOG_INFO;
 
@@ -96,23 +98,26 @@ main(int argc, char *argv[])
 		}
 	}
 
-	while ((c = getopt(argc, argv, "p:t:")) != -1)
+	while ((c = getopt(argc, argv, "ip:Sst:")) != -1)
 		switch (c) {
+		case 'i': logflags |= LOG_PID; break;
 		case 'p': strpriority(optarg, &facility, &level); break;
+		case 'S': Sflag++; break;
+		case 's': logflags |= LOG_PERROR; break;
 		case 't': tag = optarg; break;
 		default:
 usage:
-			fprintf(stderr, "usage: vlogger [-p priority] [-t tag]\n");
+			fprintf(stderr, "usage: vlogger [-isS] [-p pri] [-t tag]\n");
 			exit(1);
 		}
 
-	if (access("/etc/vlogger", X_OK) != -1) {
+	if (!Sflag && access("/etc/vlogger", X_OK) != -1) {
 		execl("/etc/vlogger", argv0, tag, (char *)0);
 		fprintf(stderr, "vlogger: exec: %s\n", strerror(errno));
 		exit(1);
 	}
 
-	openlog(tag, 0, facility);
+	openlog(tag, logflags, facility);
 
 	char *line = NULL;
 	size_t linelen = 0;