xref: /titanic_51/usr/src/cmd/logger/logger.c (revision f48205be61a214698b763ff550ab9e657525104c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*f48205beScasper  * Common Development and Distribution License (the "License").
6*f48205beScasper  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*f48205beScasper  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
317c478bd9Sstevel@tonic-gate  * The Regents of the University of California
327c478bd9Sstevel@tonic-gate  * All Rights Reserved
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
357c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
367c478bd9Sstevel@tonic-gate  * contributors.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <sys/types.h>
427c478bd9Sstevel@tonic-gate #include <unistd.h>
437c478bd9Sstevel@tonic-gate #include <stdio.h>
447c478bd9Sstevel@tonic-gate #include <syslog.h>
457c478bd9Sstevel@tonic-gate #include <ctype.h>
467c478bd9Sstevel@tonic-gate #include <stdlib.h>
477c478bd9Sstevel@tonic-gate #include <string.h>
487c478bd9Sstevel@tonic-gate #include <locale.h>
497c478bd9Sstevel@tonic-gate #include <limits.h>
507c478bd9Sstevel@tonic-gate #include <pwd.h>
517c478bd9Sstevel@tonic-gate #include <errno.h>
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #define	LOG_MARK	(LOG_NFACILITIES << 3)	/* mark "facility" */
547c478bd9Sstevel@tonic-gate #define	LOGGER_BUFLEN	1024
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate struct code {
577c478bd9Sstevel@tonic-gate 	char	*c_name;
587c478bd9Sstevel@tonic-gate 	int	c_val;
597c478bd9Sstevel@tonic-gate };
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate static struct code	PriNames[] = {
627c478bd9Sstevel@tonic-gate 	"panic",	LOG_EMERG,
637c478bd9Sstevel@tonic-gate 	"emerg",	LOG_EMERG,
647c478bd9Sstevel@tonic-gate 	"alert",	LOG_ALERT,
657c478bd9Sstevel@tonic-gate 	"crit",		LOG_CRIT,
667c478bd9Sstevel@tonic-gate 	"err",		LOG_ERR,
677c478bd9Sstevel@tonic-gate 	"error",	LOG_ERR,
687c478bd9Sstevel@tonic-gate 	"warn",		LOG_WARNING,
697c478bd9Sstevel@tonic-gate 	"warning", 	LOG_WARNING,
707c478bd9Sstevel@tonic-gate 	"notice",	LOG_NOTICE,
717c478bd9Sstevel@tonic-gate 	"info",		LOG_INFO,
727c478bd9Sstevel@tonic-gate 	"debug",	LOG_DEBUG,
737c478bd9Sstevel@tonic-gate 	NULL,		-1
747c478bd9Sstevel@tonic-gate };
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate static struct code	FacNames[] = {
777c478bd9Sstevel@tonic-gate 	"kern",		LOG_KERN,
787c478bd9Sstevel@tonic-gate 	"user",		LOG_USER,
797c478bd9Sstevel@tonic-gate 	"mail",		LOG_MAIL,
807c478bd9Sstevel@tonic-gate 	"daemon",	LOG_DAEMON,
817c478bd9Sstevel@tonic-gate 	"auth",		LOG_AUTH,
827c478bd9Sstevel@tonic-gate 	"security",	LOG_AUTH,
837c478bd9Sstevel@tonic-gate 	"mark",		LOG_MARK,
847c478bd9Sstevel@tonic-gate 	"syslog",	LOG_SYSLOG,
857c478bd9Sstevel@tonic-gate 	"lpr",		LOG_LPR,
867c478bd9Sstevel@tonic-gate 	"news",		LOG_NEWS,
877c478bd9Sstevel@tonic-gate 	"uucp",		LOG_UUCP,
887c478bd9Sstevel@tonic-gate 	"cron",		LOG_CRON,
897c478bd9Sstevel@tonic-gate 	"audit",	LOG_AUDIT,
907c478bd9Sstevel@tonic-gate 	"local0",	LOG_LOCAL0,
917c478bd9Sstevel@tonic-gate 	"local1",	LOG_LOCAL1,
927c478bd9Sstevel@tonic-gate 	"local2",	LOG_LOCAL2,
937c478bd9Sstevel@tonic-gate 	"local3",	LOG_LOCAL3,
947c478bd9Sstevel@tonic-gate 	"local4",	LOG_LOCAL4,
957c478bd9Sstevel@tonic-gate 	"local5",	LOG_LOCAL5,
967c478bd9Sstevel@tonic-gate 	"local6",	LOG_LOCAL6,
977c478bd9Sstevel@tonic-gate 	"local7",	LOG_LOCAL7,
987c478bd9Sstevel@tonic-gate 	NULL,		-1
997c478bd9Sstevel@tonic-gate };
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate static int	pencode(register char *);
1027c478bd9Sstevel@tonic-gate static int	decode(char *, struct code *);
1037c478bd9Sstevel@tonic-gate static void	bailout(char *, char *);
1047c478bd9Sstevel@tonic-gate static void	usage(void);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  *  LOGGER -- read and log utility
1087c478bd9Sstevel@tonic-gate  *
1097c478bd9Sstevel@tonic-gate  *	This routine reads from an input and arranges to write the
1107c478bd9Sstevel@tonic-gate  *	result on the system log, along with a useful tag.
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate 
11378eb75caSchin int
11478eb75caSchin main(int argc, char **argv)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate 	char tmp[23];
1177c478bd9Sstevel@tonic-gate 	char *tag = NULL;
1187c478bd9Sstevel@tonic-gate 	char *infile = NULL;
1197c478bd9Sstevel@tonic-gate 	char *buf = NULL;
1207c478bd9Sstevel@tonic-gate 	size_t buflen;
1217c478bd9Sstevel@tonic-gate 	int pri = LOG_NOTICE;
1227c478bd9Sstevel@tonic-gate 	int logflags = 0;
1237c478bd9Sstevel@tonic-gate 	int opt;
1247c478bd9Sstevel@tonic-gate 	int pid_len = 0;
1257c478bd9Sstevel@tonic-gate 	struct passwd *pw;
1267c478bd9Sstevel@tonic-gate 	uid_t u;
1277c478bd9Sstevel@tonic-gate 	char fmt_uid[16];
1287c478bd9Sstevel@tonic-gate 	char *p, *endp;
1297c478bd9Sstevel@tonic-gate 	size_t len;
1307c478bd9Sstevel@tonic-gate 	ptrdiff_t offset = 0;
1317c478bd9Sstevel@tonic-gate 	int status = 0;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1347c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
1357c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it weren't */
1367c478bd9Sstevel@tonic-gate #endif
1377c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1387c478bd9Sstevel@tonic-gate 	/* initialize */
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	while ((opt = getopt(argc, argv, "it:p:f:")) != EOF)
1417c478bd9Sstevel@tonic-gate 		switch (opt) {
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 		    case 't':		/* tag */
1447c478bd9Sstevel@tonic-gate 			tag = optarg;
1457c478bd9Sstevel@tonic-gate 			break;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 		    case 'p':		/* priority */
1487c478bd9Sstevel@tonic-gate 			pri = pencode(optarg);
1497c478bd9Sstevel@tonic-gate 			break;
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 		    case 'i':		/* log process id also */
1527c478bd9Sstevel@tonic-gate 			logflags |= LOG_PID;
1537c478bd9Sstevel@tonic-gate 			pid_len = sprintf(tmp, "%ld", (long)getpid());
1547c478bd9Sstevel@tonic-gate 			pid_len = (pid_len <= 0) ? 0 : pid_len +2;
1557c478bd9Sstevel@tonic-gate 			break;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 		    case 'f':		/* file to log */
1587c478bd9Sstevel@tonic-gate 			if (strcmp(optarg, "-") == 0)
1597c478bd9Sstevel@tonic-gate 				break;
1607c478bd9Sstevel@tonic-gate 			infile = optarg;
16178eb75caSchin 			if (freopen(infile, "r", stdin) == NULL) {
1627c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext("logger: "));
1637c478bd9Sstevel@tonic-gate 				perror(infile);
1647c478bd9Sstevel@tonic-gate 				exit(1);
1657c478bd9Sstevel@tonic-gate 			}
1667c478bd9Sstevel@tonic-gate 			break;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 		    default:
1697c478bd9Sstevel@tonic-gate 			usage();
1707c478bd9Sstevel@tonic-gate 		}
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 		argc -= optind;
1737c478bd9Sstevel@tonic-gate 		argv = &argv[optind];
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	if ((tag == NULL) && ((tag = getlogin()) == NULL)) {
1767c478bd9Sstevel@tonic-gate 		u = getuid();
1777c478bd9Sstevel@tonic-gate 		if ((pw = getpwuid(u)) == NULL) {
178*f48205beScasper 			(void) sprintf(fmt_uid, "%u", u);
1797c478bd9Sstevel@tonic-gate 			tag = fmt_uid;
1807c478bd9Sstevel@tonic-gate 		} else
1817c478bd9Sstevel@tonic-gate 			tag = pw->pw_name;
1827c478bd9Sstevel@tonic-gate 	}
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	/* setup for logging */
1857c478bd9Sstevel@tonic-gate 	openlog(tag, logflags, 0);
1867c478bd9Sstevel@tonic-gate 	(void) fclose(stdout);
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	/* log input line if appropriate */
1897c478bd9Sstevel@tonic-gate 	if (argc > 0) {
1907c478bd9Sstevel@tonic-gate 		/*
1917c478bd9Sstevel@tonic-gate 		 * Log arguments from command line
1927c478bd9Sstevel@tonic-gate 		 */
1937c478bd9Sstevel@tonic-gate 		int i;
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 		len = 0;
1967c478bd9Sstevel@tonic-gate 		for (i = 0; i < argc; i++) {
1977c478bd9Sstevel@tonic-gate 			len += strlen(argv[i]) + 1;	/* add 1 for <space> */
1987c478bd9Sstevel@tonic-gate 		}
1997c478bd9Sstevel@tonic-gate 		if ((buf = malloc(len + 1)) == NULL) {
2007c478bd9Sstevel@tonic-gate 			perror("logger");
2017c478bd9Sstevel@tonic-gate 			exit(1);
2027c478bd9Sstevel@tonic-gate 		}
2037c478bd9Sstevel@tonic-gate 		buf[0] = '\0';
2047c478bd9Sstevel@tonic-gate 		for (i = 0; i < argc; i++) {
2057c478bd9Sstevel@tonic-gate 			if (i != 0) {
2067c478bd9Sstevel@tonic-gate 				(void) strcat(buf, " ");
2077c478bd9Sstevel@tonic-gate 			}
2087c478bd9Sstevel@tonic-gate 			(void) strcat(buf, argv[i]);
2097c478bd9Sstevel@tonic-gate 		}
2107c478bd9Sstevel@tonic-gate #ifdef DEBUG
2117c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "len=%d, buf >%s<\n", len, buf);
2127c478bd9Sstevel@tonic-gate #endif
2137c478bd9Sstevel@tonic-gate 		syslog(pri, "%s", buf);
2147c478bd9Sstevel@tonic-gate 	} else {
2157c478bd9Sstevel@tonic-gate 		/*
2167c478bd9Sstevel@tonic-gate 		 * Log arguments from stdin (or input file).
2177c478bd9Sstevel@tonic-gate 		 * When reading from stdin, logger grows its buffer if
2187c478bd9Sstevel@tonic-gate 		 * needed, to handle long lines.
2197c478bd9Sstevel@tonic-gate 		 */
2207c478bd9Sstevel@tonic-gate 		if ((buf = malloc(LOGGER_BUFLEN)) == NULL) {
2217c478bd9Sstevel@tonic-gate 			perror("logger");
2227c478bd9Sstevel@tonic-gate 			exit(1);
2237c478bd9Sstevel@tonic-gate 		}
2247c478bd9Sstevel@tonic-gate 		buflen = LOGGER_BUFLEN;
2257c478bd9Sstevel@tonic-gate 		p = buf;
2267c478bd9Sstevel@tonic-gate 		endp = buf + buflen;
2277c478bd9Sstevel@tonic-gate 		offset = 0;
2287c478bd9Sstevel@tonic-gate 		while (fgets(p, endp - p, stdin) != NULL) {
2297c478bd9Sstevel@tonic-gate 			len = strlen(p);
2307c478bd9Sstevel@tonic-gate 			if (p[len - 1] == '\n') {
2317c478bd9Sstevel@tonic-gate #ifdef DEBUG
2327c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
2337c478bd9Sstevel@tonic-gate 				    "p-buf =%d, len=%d, buflen=%d, buf >%s<\n",
2347c478bd9Sstevel@tonic-gate 				    p-buf, len, buflen, buf);
2357c478bd9Sstevel@tonic-gate #endif
2367c478bd9Sstevel@tonic-gate 				syslog(pri, "%s", buf);
2377c478bd9Sstevel@tonic-gate 				p = buf;
2387c478bd9Sstevel@tonic-gate 				offset = 0;
2397c478bd9Sstevel@tonic-gate 			} else if (len < endp - p - 1) {
2407c478bd9Sstevel@tonic-gate 				/* short read or line with no <newline> */
2417c478bd9Sstevel@tonic-gate 				p += len;
2427c478bd9Sstevel@tonic-gate 				offset += len;
2437c478bd9Sstevel@tonic-gate #ifdef DEBUG
2447c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
2457c478bd9Sstevel@tonic-gate 				    "p-buf=%d, len=%d, buflen=%d, buf >%s<\n",
2467c478bd9Sstevel@tonic-gate 				    p-buf, len, buflen, buf);
2477c478bd9Sstevel@tonic-gate #endif
2487c478bd9Sstevel@tonic-gate 				continue;
2497c478bd9Sstevel@tonic-gate 			} else {
2507c478bd9Sstevel@tonic-gate 				/* line longer than buflen, so get larger buf */
2517c478bd9Sstevel@tonic-gate 				buflen += LOGGER_BUFLEN;
2527c478bd9Sstevel@tonic-gate 				offset += len;
2537c478bd9Sstevel@tonic-gate #ifdef DEBUG
2547c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
2557c478bd9Sstevel@tonic-gate 				    "Realloc endp-p=%d, len=%d, offset=%d, "
2567c478bd9Sstevel@tonic-gate 				    "buflen %d\n",
2577c478bd9Sstevel@tonic-gate 				    endp - p, len, offset, buflen);
2587c478bd9Sstevel@tonic-gate #endif
2597c478bd9Sstevel@tonic-gate 				if ((buf = realloc(buf, buflen)) == NULL) {
2607c478bd9Sstevel@tonic-gate 					perror("logger");
2617c478bd9Sstevel@tonic-gate 					exit(1);
2627c478bd9Sstevel@tonic-gate 				}
2637c478bd9Sstevel@tonic-gate 				p = buf + offset;
2647c478bd9Sstevel@tonic-gate 				endp = buf + buflen;
2657c478bd9Sstevel@tonic-gate 			}
2667c478bd9Sstevel@tonic-gate 		}	/* while */
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 		if (feof(stdin)) {
2697c478bd9Sstevel@tonic-gate 			if (p > buf) {
2707c478bd9Sstevel@tonic-gate 				/* the last line did not end with newline */
2717c478bd9Sstevel@tonic-gate #ifdef DEBUG
2727c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
2737c478bd9Sstevel@tonic-gate 				    "(2) p-buf=%d, len=%d, buflen=%d, "
2747c478bd9Sstevel@tonic-gate 				    "buf >%s<\n",
2757c478bd9Sstevel@tonic-gate 				    p-buf, len, buflen, buf);
2767c478bd9Sstevel@tonic-gate #endif
2777c478bd9Sstevel@tonic-gate 				syslog(pri, "%s", buf);
2787c478bd9Sstevel@tonic-gate 			}
2797c478bd9Sstevel@tonic-gate 		} else {
2807c478bd9Sstevel@tonic-gate 			/*
2817c478bd9Sstevel@tonic-gate 			 * fgets() encountered an error.  Log unlogged data
2827c478bd9Sstevel@tonic-gate 			 * from earlier fgets() (if any).  Write null byte
2837c478bd9Sstevel@tonic-gate 			 * after last full read, in case the fgets() that
2847c478bd9Sstevel@tonic-gate 			 * encountered error removed it and failed to null
2857c478bd9Sstevel@tonic-gate 			 * terminate.
2867c478bd9Sstevel@tonic-gate 			 */
2877c478bd9Sstevel@tonic-gate 			perror("logger");
2887c478bd9Sstevel@tonic-gate 			if (p > buf) {
2897c478bd9Sstevel@tonic-gate 				*p = '\0';
2907c478bd9Sstevel@tonic-gate 				syslog(pri, "%s", buf);
2917c478bd9Sstevel@tonic-gate 			}
2927c478bd9Sstevel@tonic-gate 			status = 1;
2937c478bd9Sstevel@tonic-gate 		}
2947c478bd9Sstevel@tonic-gate 	}	/* else !(argc > 0) */
2957c478bd9Sstevel@tonic-gate 	free(buf);
2967c478bd9Sstevel@tonic-gate 	return (status);
2977c478bd9Sstevel@tonic-gate }
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate /*
3007c478bd9Sstevel@tonic-gate  *  Decode a symbolic name to a numeric value
3017c478bd9Sstevel@tonic-gate  */
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate static int
3057c478bd9Sstevel@tonic-gate pencode(s)
3067c478bd9Sstevel@tonic-gate register char *s;
3077c478bd9Sstevel@tonic-gate {
3087c478bd9Sstevel@tonic-gate 	register char *p;
3097c478bd9Sstevel@tonic-gate 	int lev;
3107c478bd9Sstevel@tonic-gate 	int fac = 0;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	for (p = s; *s && *s != '.'; s++);
3137c478bd9Sstevel@tonic-gate 	if (*s) {
3147c478bd9Sstevel@tonic-gate 		*s = '\0';
3157c478bd9Sstevel@tonic-gate 		fac = decode(p, FacNames);
3167c478bd9Sstevel@tonic-gate 		if (fac < 0)
3177c478bd9Sstevel@tonic-gate 			bailout("unknown facility name: ", p);
3187c478bd9Sstevel@tonic-gate 		*s++ = '.';
3197c478bd9Sstevel@tonic-gate 	} else
3207c478bd9Sstevel@tonic-gate 		s = p;
3217c478bd9Sstevel@tonic-gate 	lev = decode(s, PriNames);
3227c478bd9Sstevel@tonic-gate 	if (lev < 0)
3237c478bd9Sstevel@tonic-gate 		bailout("unknown priority name: ", s);
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
3267c478bd9Sstevel@tonic-gate }
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate static int
3307c478bd9Sstevel@tonic-gate decode(name, codetab)
3317c478bd9Sstevel@tonic-gate char *name;
3327c478bd9Sstevel@tonic-gate struct code *codetab;
3337c478bd9Sstevel@tonic-gate {
3347c478bd9Sstevel@tonic-gate 	register struct code *c;
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 	if (isdigit(*name))
3377c478bd9Sstevel@tonic-gate 		return (atoi(name));
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 	for (c = codetab; c->c_name; c++)
3407c478bd9Sstevel@tonic-gate 		if (strcasecmp(name, c->c_name) == 0)
3417c478bd9Sstevel@tonic-gate 			return (c->c_val);
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	return (-1);
3447c478bd9Sstevel@tonic-gate }
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate static void
3487c478bd9Sstevel@tonic-gate bailout(a, b)
3497c478bd9Sstevel@tonic-gate char *a, *b;
3507c478bd9Sstevel@tonic-gate {
3517c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("logger: %s%s\n"), a, b);
3527c478bd9Sstevel@tonic-gate 	exit(1);
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate static void
3577c478bd9Sstevel@tonic-gate usage(void)
3587c478bd9Sstevel@tonic-gate {
3597c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
3607c478bd9Sstevel@tonic-gate 	    "Usage:\tlogger string\n"
3617c478bd9Sstevel@tonic-gate 	    "\tlogger [-i] [-f filename] [-p priority] [-t tag] "
3627c478bd9Sstevel@tonic-gate 		"[message] ...\n"));
3637c478bd9Sstevel@tonic-gate 	exit(1);
3647c478bd9Sstevel@tonic-gate }
365