Audit logger(1)

1) Update manpage to current style
2) Line spacing
3) Local variable grouping
4) check for getline >= 0 instead of != -1
5) error message cleanup
This commit is contained in:
FRIGN 2015-03-07 00:08:43 +01:00
parent d21a958d88
commit 0c2f19c210
3 changed files with 31 additions and 22 deletions

2
README
View File

@ -40,7 +40,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
=* kill yes none
=*| link yes none
=*| ln yes none
=* logger yes none
=*| logger yes none
=* logname yes none
= ls no (-C), -S, -f, -m, -s, -x
=*| md5sum non-posix none

View File

@ -1,4 +1,4 @@
.Dd December 4, 2014
.Dd March 7, 2015
.Dt LOGGER 1
.Os sbase
.Sh NAME
@ -14,24 +14,31 @@
.Nm
provides a shell command interface to the
.Xr syslog 3
system log module.
system log module and writes each
.Ar message
to the log.
If no
.Ar message
is given,
.Nm
logs stdin.
.Sh OPTIONS
.Bl -tag -width xxxxxxxxxxxx
.It Fl i
Log the process ID of the logger process with each line.
Add the logger process ID to each line in the log.
.It Fl p Ar priority
Enter the message with the specified priority. They priority has to be
specified symbolically as
Set the message
.Ar priority
given symbolically as a
.Dq facility.level
pair. The default is
.Dq user.notice .
.It Fl s
Log the message to standard error, as well as the system log.
Also log to stderr.
.It Fl t Ar tag
Mark every line in the log with the specified
.Ar tag .
.It Ar message
Write the message to the log; if not specified, standard input is logged.
Add
.Ar tag
to each line in the log.
.El
.Sh SEE ALSO
.Xr syslogd 1 ,
@ -43,6 +50,6 @@ utility is compliant with the
.St -p1003.1-2008
specification.
.Pp
The flags
The
.Op Fl ipst
are extensions to that specification.
flags are an extensions to that specification.

View File

@ -18,8 +18,8 @@ decodetable(CODE *table, char *name)
if (!strcasecmp(name, c->c_name))
return c->c_val;
eprintf("invalid priority name: %s\n", name);
/* NOTREACHED */
return -1;
return -1; /* not reached */
}
static int
@ -32,6 +32,7 @@ decodepri(char *pri)
*lev++ = '\0';
if (!*lev)
eprintf("invalid priority name: %s\n", pri);
return (decodetable(facilitynames, fac) & LOG_FACMASK) |
(decodetable(prioritynames, lev) & LOG_PRIMASK);
}
@ -45,10 +46,9 @@ usage(void)
int
main(int argc, char *argv[])
{
size_t sz;
int logflags = 0, priority = LOG_NOTICE, i;
char *buf = NULL, *tag = NULL;
size_t sz = 0;
int logflags = 0, priority = LOG_NOTICE;
int i;
ARGBEGIN {
case 'i':
@ -69,13 +69,13 @@ main(int argc, char *argv[])
openlog(tag ? tag : getlogin(), logflags, 0);
if (argc == 0) {
while (getline(&buf, &sz, stdin) != -1)
if (!argc) {
while (getline(&buf, &sz, stdin) >= 0)
syslog(priority, "%s", buf);
if (ferror(stdin))
eprintf("%s: read error:", "<stdin>");
eprintf("getline %s:", "<stdin>");
} else {
for (i = 0; i < argc; i++)
for (i = 0, sz = 0; i < argc; i++)
sz += strlen(argv[i]);
sz += argc;
buf = ecalloc(1, sz);
@ -86,6 +86,8 @@ main(int argc, char *argv[])
}
syslog(priority, "%s", buf);
}
closelog();
return 0;
}