1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-29 08:08:37 +00:00

Use err(3).

This commit is contained in:
Philippe Charnier 1997-07-22 07:33:48 +00:00
parent 3ec665d482
commit df0715563d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=27604
2 changed files with 21 additions and 26 deletions

View File

@ -38,7 +38,7 @@
.Nm logger
.Nd make entries in the system log
.Sh SYNOPSIS
.Nm logger
.Nm
.Op Fl is
.Op Fl f Ar file
.Op Fl p Ar pri
@ -81,7 +81,7 @@ provided, standard input is logged.
.El
.Pp
The
.Nm logger
.Nm
utility exits 0 on success, and >0 if an error occurs.
.Sh EXAMPLES
.Bd -literal -offset indent -compact
@ -94,7 +94,7 @@ logger \-p local0.notice \-t HOSTIDM \-f /dev/idmc
.Xr syslogd 8
.Sh STANDARDS
The
.Nm logger
.Nm
command is expected to be
.St -p1003.2
compatible.

View File

@ -32,28 +32,32 @@
*/
#ifndef lint
static char copyright[] =
static const char copyright[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)logger.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define SYSLOG_NAMES
#include <syslog.h>
int decode __P((char *, CODE *));
int pencode __P((char *));
void usage __P((void));
static void usage __P((void));
/*
* logger -- read and log utility
@ -76,11 +80,8 @@ main(argc, argv)
while ((ch = getopt(argc, argv, "f:ip:st:")) != -1)
switch((char)ch) {
case 'f': /* file to log */
if (freopen(optarg, "r", stdin) == NULL) {
(void)fprintf(stderr, "logger: %s: %s.\n",
optarg, strerror(errno));
exit(1);
}
if (freopen(optarg, "r", stdin) == NULL)
err(1, "%s", optarg);
break;
case 'i': /* log process id also */
logflags |= LOG_PID;
@ -147,11 +148,8 @@ pencode(s)
if (*s) {
*s = '\0';
fac = decode(save, facilitynames);
if (fac < 0) {
(void)fprintf(stderr,
"logger: unknown facility name: %s.\n", save);
exit(1);
}
if (fac < 0)
errx(1, "unknown facility name: %s", save);
*s++ = '.';
}
else {
@ -159,11 +157,8 @@ pencode(s)
s = save;
}
lev = decode(s, prioritynames);
if (lev < 0) {
(void)fprintf(stderr,
"logger: unknown priority name: %s.\n", save);
exit(1);
}
if (lev < 0)
errx(1, "unknown priority name: %s", save);
return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
}
@ -184,10 +179,10 @@ decode(name, codetab)
return (-1);
}
void
static void
usage()
{
(void)fprintf(stderr,
"logger: [-is] [-f file] [-p pri] [-t tag] [ message ... ]\n");
"usage: logger [-is] [-f file] [-p pri] [-t tag] [message ...]\n");
exit(1);
}