2014-12-04 06:34:39 -05:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#define SYSLOG_NAMES
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
2014-12-04 06:45:44 -05:00
|
|
|
static int
|
2014-12-09 10:44:31 -05:00
|
|
|
decodetable(CODE *table, char *name)
|
2014-12-04 06:34:39 -05:00
|
|
|
{
|
|
|
|
CODE *c;
|
|
|
|
|
2014-12-09 10:44:31 -05:00
|
|
|
for (c = table; c->c_name; c++)
|
|
|
|
if (!strcasecmp(name, c->c_name))
|
|
|
|
return c->c_val;
|
|
|
|
eprintf("invalid priority name: %s\n", name);
|
|
|
|
/* NOTREACHED */
|
|
|
|
return -1;
|
2014-12-04 06:34:39 -05:00
|
|
|
}
|
|
|
|
|
2014-12-04 06:45:44 -05:00
|
|
|
static int
|
2014-12-04 06:34:39 -05:00
|
|
|
decodepri(char *pri)
|
|
|
|
{
|
2014-12-09 10:44:31 -05:00
|
|
|
char *lev, *fac = pri;
|
2014-12-04 06:34:39 -05:00
|
|
|
|
2014-12-09 10:44:31 -05:00
|
|
|
if (!(lev = strchr(pri, '.')))
|
2014-12-04 06:34:39 -05:00
|
|
|
eprintf("invalid priority name: %s\n", pri);
|
2014-12-09 10:44:31 -05:00
|
|
|
*lev++ = '\0';
|
|
|
|
if (!*lev)
|
2014-12-04 06:34:39 -05:00
|
|
|
eprintf("invalid priority name: %s\n", pri);
|
2014-12-09 10:44:31 -05:00
|
|
|
return (decodetable(facilitynames, fac) & LOG_FACMASK) |
|
|
|
|
(decodetable(prioritynames, lev) & LOG_PRIMASK);
|
2014-12-04 06:34:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
eprintf("usage: %s [-is] [-p priority] [-t tag] [message ...]\n", argv0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char *buf = NULL, *tag = NULL;
|
|
|
|
size_t sz = 0;
|
|
|
|
int logflags = 0, priority = LOG_NOTICE;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
case 'i':
|
|
|
|
logflags |= LOG_PID;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
priority = decodepri(EARGF(usage()));
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
logflags |= LOG_PERROR;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
tag = EARGF(usage());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
openlog(tag ? tag : getlogin(), logflags, 0);
|
|
|
|
|
|
|
|
if (argc == 0) {
|
|
|
|
while(getline(&buf, &sz, stdin) != -1)
|
|
|
|
syslog(priority, "%s", buf);
|
|
|
|
if (ferror(stdin))
|
|
|
|
eprintf("%s: read error:", "<stdin>");
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
sz += strlen(argv[i]);
|
|
|
|
sz += argc;
|
|
|
|
buf = ecalloc(1, sz);
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
strlcat(buf, argv[i], sz);
|
|
|
|
if (i + 1 < argc)
|
|
|
|
strlcat(buf, " ", sz);
|
|
|
|
}
|
|
|
|
syslog(priority, "%s", buf);
|
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
closelog();
|
|
|
|
return 0;
|
|
|
|
}
|