Skip to content

Commit 64acdc3

Browse files
committed
vlogger: add logger(1) compatible -s and -i flag, and -S to force syslog
1 parent 3095ba6 commit 64acdc3

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

vlogger.8

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
.Nd log messages to syslog or an arbitrary executable
77
.Sh SYNOPSIS
88
.Nm vlogger
9-
.Op Fl p Ar priority
9+
.Op Fl isS
10+
.Op Fl p Ar pri
1011
.Op Fl t Ar tag
1112
.Sh DESCRIPTION
1213
By default,
@@ -36,10 +37,33 @@ it uses
3637
.Dv foo
3738
as default
3839
.Ar tag .
40+
.Pp
41+
The options are as follows:
3942
.Bl -tag -width indent
40-
.It Fl p Ar priority
43+
.It Fl S
44+
Force
45+
.Nm
46+
to use
47+
.Xr syslog 3
48+
even if
49+
.Pa /etc/vlogger
50+
exists.
51+
.It Fl s
52+
Output the message to standard error, as well as
53+
.Xr syslog 3 .
54+
Only supported if
55+
.Xr syslog 3
56+
is used.
57+
.It Fl i
58+
Log the PID of the
59+
.Nm
60+
process.
61+
Only supported if
62+
.Xr syslog 3
63+
is used.
64+
.It Fl p Ar pri
4165
The.
42-
.Ar priority
66+
.Ar pri
4367
can be
4468
.Pa facility.level
4569
or just

vlogger.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ main(int argc, char *argv[])
7979
char *p, *argv0;
8080
char *tag = "vlogger";
8181
int c;
82+
int Sflag = 0;
83+
int logflags = 0;
8284
int facility = LOG_DAEMON;
8385
int level = LOG_INFO;
8486

@@ -96,23 +98,26 @@ main(int argc, char *argv[])
9698
}
9799
}
98100

99-
while ((c = getopt(argc, argv, "p:t:")) != -1)
101+
while ((c = getopt(argc, argv, "ip:Sst:")) != -1)
100102
switch (c) {
103+
case 'i': logflags |= LOG_PID; break;
101104
case 'p': strpriority(optarg, &facility, &level); break;
105+
case 'S': Sflag++; break;
106+
case 's': logflags |= LOG_PERROR; break;
102107
case 't': tag = optarg; break;
103108
default:
104109
usage:
105-
fprintf(stderr, "usage: vlogger [-p priority] [-t tag]\n");
110+
fprintf(stderr, "usage: vlogger [-isS] [-p pri] [-t tag]\n");
106111
exit(1);
107112
}
108113

109-
if (access("/etc/vlogger", X_OK) != -1) {
114+
if (!Sflag && access("/etc/vlogger", X_OK) != -1) {
110115
execl("/etc/vlogger", argv0, tag, (char *)0);
111116
fprintf(stderr, "vlogger: exec: %s\n", strerror(errno));
112117
exit(1);
113118
}
114119

115-
openlog(tag, 0, facility);
120+
openlog(tag, logflags, facility);
116121

117122
char *line = NULL;
118123
size_t linelen = 0;

0 commit comments

Comments
 (0)