diff options
author | Duncaen <mail@duncano.de> | 2018-06-22 16:52:52 +0200 |
---|---|---|
committer | Duncaen <mail@duncano.de> | 2018-06-23 02:09:57 +0200 |
commit | 469b7a38cba68497103915dc2eec87a9b6d343ec (patch) | |
tree | 448650face7290b9b67090ac1d80a8d5c935491e | |
parent | 895727940f54d7eaa72765cfdb28d4d1fa652651 (diff) | |
download | runit-void-469b7a38cba68497103915dc2eec87a9b6d343ec.tar.gz runit-void-469b7a38cba68497103915dc2eec87a9b6d343ec.tar.xz runit-void-469b7a38cba68497103915dc2eec87a9b6d343ec.zip |
vlogger: add message argument for POSIX logger compatibility
-rw-r--r-- | vlogger.8 | 7 | ||||
-rw-r--r-- | vlogger.c | 33 |
2 files changed, 38 insertions, 2 deletions
diff --git a/vlogger.8 b/vlogger.8 index 4a9b19d..d2e88ff 100644 --- a/vlogger.8 +++ b/vlogger.8 @@ -10,6 +10,7 @@ .Op Fl f Ar file .Op Fl p Ar pri .Op Fl t Ar tag +.Op Ar message ... .Sh DESCRIPTION By default, .Nm @@ -40,7 +41,7 @@ as default .Ar tag . .Pp The options are as follows: -.Bl -tag -width indent +.Bl -tag -width "-f file" .It Fl f Ar file Read lines from the specified .Ar file . @@ -86,6 +87,10 @@ Defines the .Pa ident which is used as prefix for each log message or passed as first argument to .Pa /etc/vlogger . +.It Ar message +Write the +.Ar message +to the log. .El .Sh FACILITIES .Bl -tag -width 11n -compact diff --git a/vlogger.c b/vlogger.c index aaf569b..a2a683e 100644 --- a/vlogger.c +++ b/vlogger.c @@ -113,9 +113,11 @@ main(int argc, char *argv[]) case 's': logflags |= LOG_PERROR; break; case 't': tag = optarg; break; default: - fprintf(stderr, "usage: vlogger [-isS] [-f file] [-p pri] [-t tag]\n"); + fprintf(stderr, "usage: vlogger [-isS] [-f file] [-p pri] [-t tag] [message ...]\n"); exit(1); } + argc -= optind; + argv += optind; if (!Sflag && access("/etc/vlogger", X_OK) != -1) { CODE *cp; @@ -135,6 +137,35 @@ main(int argc, char *argv[]) openlog(tag, logflags, facility); + if (argc > 0) { + size_t len; + char *p, *e; + p = buf; + *p = '\0'; + e = buf + sizeof buf - 2; + for (; *argv;) { + len = strlen(*argv); + if (p + len > e && p > buf) { + syslog(level|facility, "%s", buf); + p = buf; + *p = '\0'; + } + if (len > sizeof buf - 1) { + syslog(level|facility, "%s", *argv++); + } else { + if (p != buf) { + *p++ = ' '; + *p = '\0'; + } + strncat(p, *argv++, e-p); + p += len; + } + } + if (p != buf) + syslog(level|facility, "%s", buf); + return 0; + } + while (fgets(buf, sizeof buf, stdin) != NULL) syslog(level|facility, "%s", buf); |