Skip to content

Commit 469b7a3

Browse files
committed
vlogger: add message argument for POSIX logger compatibility
1 parent 8957279 commit 469b7a3

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

vlogger.8

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
.Op Fl f Ar file
1111
.Op Fl p Ar pri
1212
.Op Fl t Ar tag
13+
.Op Ar message ...
1314
.Sh DESCRIPTION
1415
By default,
1516
.Nm
@@ -40,7 +41,7 @@ as default
4041
.Ar tag .
4142
.Pp
4243
The options are as follows:
43-
.Bl -tag -width indent
44+
.Bl -tag -width "-f file"
4445
.It Fl f Ar file
4546
Read lines from the specified
4647
.Ar file .
@@ -86,6 +87,10 @@ Defines the
8687
.Pa ident
8788
which is used as prefix for each log message or passed as first argument to
8889
.Pa /etc/vlogger .
90+
.It Ar message
91+
Write the
92+
.Ar message
93+
to the log.
8994
.El
9095
.Sh FACILITIES
9196
.Bl -tag -width 11n -compact

vlogger.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ main(int argc, char *argv[])
113113
case 's': logflags |= LOG_PERROR; break;
114114
case 't': tag = optarg; break;
115115
default:
116-
fprintf(stderr, "usage: vlogger [-isS] [-f file] [-p pri] [-t tag]\n");
116+
fprintf(stderr, "usage: vlogger [-isS] [-f file] [-p pri] [-t tag] [message ...]\n");
117117
exit(1);
118118
}
119+
argc -= optind;
120+
argv += optind;
119121

120122
if (!Sflag && access("/etc/vlogger", X_OK) != -1) {
121123
CODE *cp;
@@ -135,6 +137,35 @@ main(int argc, char *argv[])
135137

136138
openlog(tag, logflags, facility);
137139

140+
if (argc > 0) {
141+
size_t len;
142+
char *p, *e;
143+
p = buf;
144+
*p = '\0';
145+
e = buf + sizeof buf - 2;
146+
for (; *argv;) {
147+
len = strlen(*argv);
148+
if (p + len > e && p > buf) {
149+
syslog(level|facility, "%s", buf);
150+
p = buf;
151+
*p = '\0';
152+
}
153+
if (len > sizeof buf - 1) {
154+
syslog(level|facility, "%s", *argv++);
155+
} else {
156+
if (p != buf) {
157+
*p++ = ' ';
158+
*p = '\0';
159+
}
160+
strncat(p, *argv++, e-p);
161+
p += len;
162+
}
163+
}
164+
if (p != buf)
165+
syslog(level|facility, "%s", buf);
166+
return 0;
167+
}
168+
138169
while (fgets(buf, sizeof buf, stdin) != NULL)
139170
syslog(level|facility, "%s", buf);
140171

0 commit comments

Comments
 (0)