Testing something else I needed to call syslog(3) with LOG_CONS. Diff
below adds support to logger(1) for doing that. Option choice is
compatible with NetBSD.
ok?
Philip Guenther
Index: logger.1
===================================================================
RCS file: /data/src/openbsd/src/usr.bin/logger/logger.1,v
retrieving revision 1.21
diff -u -p -r1.21 logger.1
--- logger.1 5 Jun 2013 17:35:12 -0000 1.21
+++ logger.1 16 Jun 2019 19:19:26 -0000
@@ -38,7 +38,7 @@
.Nd make entries in the system log
.Sh SYNOPSIS
.Nm logger
-.Op Fl is
+.Op Fl cis
.Op Fl f Ar file
.Op Fl p Ar pri
.Op Fl t Ar tag
@@ -52,6 +52,10 @@ system log module.
.Pp
The options are as follows:
.Bl -tag -width "-f file"
+.It Fl c
+If unable to pass the message to
+.Xr syslogd 8 ,
+attempt to write the message to the console.
.It Fl f Ar file
Read from the specified
.Ar file .
@@ -102,5 +106,5 @@ utility is compliant with the
specification.
.Pp
The flags
-.Op Fl ifpst
+.Op Fl cfipst
are extensions to that specification.
Index: logger.c
===================================================================
RCS file: /data/src/openbsd/src/usr.bin/logger/logger.c,v
retrieving revision 1.17
diff -u -p -r1.17 logger.c
--- logger.c 28 Mar 2016 18:18:52 -0000 1.17
+++ logger.c 16 Jun 2019 19:18:33 -0000
@@ -61,8 +61,11 @@ main(int argc, char *argv[])
tag = NULL;
pri = LOG_NOTICE;
logflags = 0;
- while ((ch = getopt(argc, argv, "f:ip:st:")) != -1)
+ while ((ch = getopt(argc, argv, "cf:ip:st:")) != -1)
switch(ch) {
+ case 'c': /* log to console */
+ logflags |= LOG_CONS;
+ break;
case 'f': /* file to log */
if (freopen(optarg, "r", stdin) == NULL) {
(void)fprintf(stderr, "logger: %s: %s.\n",
@@ -180,6 +183,6 @@ void
usage(void)
{
(void)fprintf(stderr,
- "usage: logger [-is] [-f file] [-p pri] [-t tag] [message ...]\n");
+ "usage: logger [-cis] [-f file] [-p pri] [-t tag] [message ...]\n");
exit(1);
}