1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 32*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 33*7c478bd9Sstevel@tonic-gate * All Rights Reserved 34*7c478bd9Sstevel@tonic-gate * 35*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 36*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 37*7c478bd9Sstevel@tonic-gate * contributors. 38*7c478bd9Sstevel@tonic-gate */ 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 43*7c478bd9Sstevel@tonic-gate #include <unistd.h> 44*7c478bd9Sstevel@tonic-gate #include <stdio.h> 45*7c478bd9Sstevel@tonic-gate #include <syslog.h> 46*7c478bd9Sstevel@tonic-gate #include <ctype.h> 47*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 48*7c478bd9Sstevel@tonic-gate #include <string.h> 49*7c478bd9Sstevel@tonic-gate #include <locale.h> 50*7c478bd9Sstevel@tonic-gate #include <limits.h> 51*7c478bd9Sstevel@tonic-gate #include <pwd.h> 52*7c478bd9Sstevel@tonic-gate #include <errno.h> 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate #define LOG_MARK (LOG_NFACILITIES << 3) /* mark "facility" */ 55*7c478bd9Sstevel@tonic-gate #define LOGGER_BUFLEN 1024 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate struct code { 58*7c478bd9Sstevel@tonic-gate char *c_name; 59*7c478bd9Sstevel@tonic-gate int c_val; 60*7c478bd9Sstevel@tonic-gate }; 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate static struct code PriNames[] = { 63*7c478bd9Sstevel@tonic-gate "panic", LOG_EMERG, 64*7c478bd9Sstevel@tonic-gate "emerg", LOG_EMERG, 65*7c478bd9Sstevel@tonic-gate "alert", LOG_ALERT, 66*7c478bd9Sstevel@tonic-gate "crit", LOG_CRIT, 67*7c478bd9Sstevel@tonic-gate "err", LOG_ERR, 68*7c478bd9Sstevel@tonic-gate "error", LOG_ERR, 69*7c478bd9Sstevel@tonic-gate "warn", LOG_WARNING, 70*7c478bd9Sstevel@tonic-gate "warning", LOG_WARNING, 71*7c478bd9Sstevel@tonic-gate "notice", LOG_NOTICE, 72*7c478bd9Sstevel@tonic-gate "info", LOG_INFO, 73*7c478bd9Sstevel@tonic-gate "debug", LOG_DEBUG, 74*7c478bd9Sstevel@tonic-gate NULL, -1 75*7c478bd9Sstevel@tonic-gate }; 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate static struct code FacNames[] = { 78*7c478bd9Sstevel@tonic-gate "kern", LOG_KERN, 79*7c478bd9Sstevel@tonic-gate "user", LOG_USER, 80*7c478bd9Sstevel@tonic-gate "mail", LOG_MAIL, 81*7c478bd9Sstevel@tonic-gate "daemon", LOG_DAEMON, 82*7c478bd9Sstevel@tonic-gate "auth", LOG_AUTH, 83*7c478bd9Sstevel@tonic-gate "security", LOG_AUTH, 84*7c478bd9Sstevel@tonic-gate "mark", LOG_MARK, 85*7c478bd9Sstevel@tonic-gate "syslog", LOG_SYSLOG, 86*7c478bd9Sstevel@tonic-gate "lpr", LOG_LPR, 87*7c478bd9Sstevel@tonic-gate "news", LOG_NEWS, 88*7c478bd9Sstevel@tonic-gate "uucp", LOG_UUCP, 89*7c478bd9Sstevel@tonic-gate "cron", LOG_CRON, 90*7c478bd9Sstevel@tonic-gate "audit", LOG_AUDIT, 91*7c478bd9Sstevel@tonic-gate "local0", LOG_LOCAL0, 92*7c478bd9Sstevel@tonic-gate "local1", LOG_LOCAL1, 93*7c478bd9Sstevel@tonic-gate "local2", LOG_LOCAL2, 94*7c478bd9Sstevel@tonic-gate "local3", LOG_LOCAL3, 95*7c478bd9Sstevel@tonic-gate "local4", LOG_LOCAL4, 96*7c478bd9Sstevel@tonic-gate "local5", LOG_LOCAL5, 97*7c478bd9Sstevel@tonic-gate "local6", LOG_LOCAL6, 98*7c478bd9Sstevel@tonic-gate "local7", LOG_LOCAL7, 99*7c478bd9Sstevel@tonic-gate NULL, -1 100*7c478bd9Sstevel@tonic-gate }; 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate static int pencode(register char *); 103*7c478bd9Sstevel@tonic-gate static int decode(char *, struct code *); 104*7c478bd9Sstevel@tonic-gate static void bailout(char *, char *); 105*7c478bd9Sstevel@tonic-gate static void usage(void); 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate /* 108*7c478bd9Sstevel@tonic-gate * LOGGER -- read and log utility 109*7c478bd9Sstevel@tonic-gate * 110*7c478bd9Sstevel@tonic-gate * This routine reads from an input and arranges to write the 111*7c478bd9Sstevel@tonic-gate * result on the system log, along with a useful tag. 112*7c478bd9Sstevel@tonic-gate */ 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate main(argc, argv) 115*7c478bd9Sstevel@tonic-gate int argc; 116*7c478bd9Sstevel@tonic-gate char **argv; 117*7c478bd9Sstevel@tonic-gate { 118*7c478bd9Sstevel@tonic-gate char tmp[23]; 119*7c478bd9Sstevel@tonic-gate char *tag = NULL; 120*7c478bd9Sstevel@tonic-gate char *infile = NULL; 121*7c478bd9Sstevel@tonic-gate char *buf = NULL; 122*7c478bd9Sstevel@tonic-gate size_t buflen; 123*7c478bd9Sstevel@tonic-gate int pri = LOG_NOTICE; 124*7c478bd9Sstevel@tonic-gate int logflags = 0; 125*7c478bd9Sstevel@tonic-gate int opt; 126*7c478bd9Sstevel@tonic-gate int pid_len = 0; 127*7c478bd9Sstevel@tonic-gate struct passwd *pw; 128*7c478bd9Sstevel@tonic-gate uid_t u; 129*7c478bd9Sstevel@tonic-gate char fmt_uid[16]; 130*7c478bd9Sstevel@tonic-gate char *p, *endp; 131*7c478bd9Sstevel@tonic-gate size_t len; 132*7c478bd9Sstevel@tonic-gate ptrdiff_t offset = 0; 133*7c478bd9Sstevel@tonic-gate int status = 0; 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 136*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ 137*7c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ 138*7c478bd9Sstevel@tonic-gate #endif 139*7c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 140*7c478bd9Sstevel@tonic-gate /* initialize */ 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate while ((opt = getopt(argc, argv, "it:p:f:")) != EOF) 143*7c478bd9Sstevel@tonic-gate switch (opt) { 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate case 't': /* tag */ 146*7c478bd9Sstevel@tonic-gate tag = optarg; 147*7c478bd9Sstevel@tonic-gate break; 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate case 'p': /* priority */ 150*7c478bd9Sstevel@tonic-gate pri = pencode(optarg); 151*7c478bd9Sstevel@tonic-gate break; 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate case 'i': /* log process id also */ 154*7c478bd9Sstevel@tonic-gate logflags |= LOG_PID; 155*7c478bd9Sstevel@tonic-gate pid_len = sprintf(tmp, "%ld", (long)getpid()); 156*7c478bd9Sstevel@tonic-gate pid_len = (pid_len <= 0) ? 0 : pid_len +2; 157*7c478bd9Sstevel@tonic-gate break; 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate case 'f': /* file to log */ 160*7c478bd9Sstevel@tonic-gate if (strcmp(optarg, "-") == 0) 161*7c478bd9Sstevel@tonic-gate break; 162*7c478bd9Sstevel@tonic-gate infile = optarg; 163*7c478bd9Sstevel@tonic-gate if (freopen(infile, "r", stdin) == NULL) 164*7c478bd9Sstevel@tonic-gate { 165*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("logger: ")); 166*7c478bd9Sstevel@tonic-gate perror(infile); 167*7c478bd9Sstevel@tonic-gate exit(1); 168*7c478bd9Sstevel@tonic-gate } 169*7c478bd9Sstevel@tonic-gate break; 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate default: 172*7c478bd9Sstevel@tonic-gate usage(); 173*7c478bd9Sstevel@tonic-gate } 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate argc -= optind; 176*7c478bd9Sstevel@tonic-gate argv = &argv[optind]; 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate if ((tag == NULL) && ((tag = getlogin()) == NULL)) { 179*7c478bd9Sstevel@tonic-gate u = getuid(); 180*7c478bd9Sstevel@tonic-gate if ((pw = getpwuid(u)) == NULL) { 181*7c478bd9Sstevel@tonic-gate (void) sprintf(fmt_uid, "%ld", u); 182*7c478bd9Sstevel@tonic-gate tag = fmt_uid; 183*7c478bd9Sstevel@tonic-gate } else 184*7c478bd9Sstevel@tonic-gate tag = pw->pw_name; 185*7c478bd9Sstevel@tonic-gate } 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate /* setup for logging */ 188*7c478bd9Sstevel@tonic-gate openlog(tag, logflags, 0); 189*7c478bd9Sstevel@tonic-gate (void) fclose(stdout); 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate /* log input line if appropriate */ 192*7c478bd9Sstevel@tonic-gate if (argc > 0) { 193*7c478bd9Sstevel@tonic-gate /* 194*7c478bd9Sstevel@tonic-gate * Log arguments from command line 195*7c478bd9Sstevel@tonic-gate */ 196*7c478bd9Sstevel@tonic-gate int i; 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate len = 0; 199*7c478bd9Sstevel@tonic-gate for (i = 0; i < argc; i++) { 200*7c478bd9Sstevel@tonic-gate len += strlen(argv[i]) + 1; /* add 1 for <space> */ 201*7c478bd9Sstevel@tonic-gate } 202*7c478bd9Sstevel@tonic-gate if ((buf = malloc(len + 1)) == NULL) { 203*7c478bd9Sstevel@tonic-gate perror("logger"); 204*7c478bd9Sstevel@tonic-gate exit(1); 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate buf[0] = '\0'; 207*7c478bd9Sstevel@tonic-gate for (i = 0; i < argc; i++) { 208*7c478bd9Sstevel@tonic-gate if (i != 0) { 209*7c478bd9Sstevel@tonic-gate (void) strcat(buf, " "); 210*7c478bd9Sstevel@tonic-gate } 211*7c478bd9Sstevel@tonic-gate (void) strcat(buf, argv[i]); 212*7c478bd9Sstevel@tonic-gate } 213*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 214*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "len=%d, buf >%s<\n", len, buf); 215*7c478bd9Sstevel@tonic-gate #endif 216*7c478bd9Sstevel@tonic-gate syslog(pri, "%s", buf); 217*7c478bd9Sstevel@tonic-gate } else { 218*7c478bd9Sstevel@tonic-gate /* 219*7c478bd9Sstevel@tonic-gate * Log arguments from stdin (or input file). 220*7c478bd9Sstevel@tonic-gate * When reading from stdin, logger grows its buffer if 221*7c478bd9Sstevel@tonic-gate * needed, to handle long lines. 222*7c478bd9Sstevel@tonic-gate */ 223*7c478bd9Sstevel@tonic-gate if ((buf = malloc(LOGGER_BUFLEN)) == NULL) { 224*7c478bd9Sstevel@tonic-gate perror("logger"); 225*7c478bd9Sstevel@tonic-gate exit(1); 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate buflen = LOGGER_BUFLEN; 228*7c478bd9Sstevel@tonic-gate p = buf; 229*7c478bd9Sstevel@tonic-gate endp = buf + buflen; 230*7c478bd9Sstevel@tonic-gate offset = 0; 231*7c478bd9Sstevel@tonic-gate while (fgets(p, endp - p, stdin) != NULL) { 232*7c478bd9Sstevel@tonic-gate len = strlen(p); 233*7c478bd9Sstevel@tonic-gate if (p[len - 1] == '\n') { 234*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 235*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 236*7c478bd9Sstevel@tonic-gate "p-buf =%d, len=%d, buflen=%d, buf >%s<\n", 237*7c478bd9Sstevel@tonic-gate p-buf, len, buflen, buf); 238*7c478bd9Sstevel@tonic-gate #endif 239*7c478bd9Sstevel@tonic-gate syslog(pri, "%s", buf); 240*7c478bd9Sstevel@tonic-gate p = buf; 241*7c478bd9Sstevel@tonic-gate offset = 0; 242*7c478bd9Sstevel@tonic-gate } else if (len < endp - p - 1) { 243*7c478bd9Sstevel@tonic-gate /* short read or line with no <newline> */ 244*7c478bd9Sstevel@tonic-gate p += len; 245*7c478bd9Sstevel@tonic-gate offset += len; 246*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 247*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 248*7c478bd9Sstevel@tonic-gate "p-buf=%d, len=%d, buflen=%d, buf >%s<\n", 249*7c478bd9Sstevel@tonic-gate p-buf, len, buflen, buf); 250*7c478bd9Sstevel@tonic-gate #endif 251*7c478bd9Sstevel@tonic-gate continue; 252*7c478bd9Sstevel@tonic-gate } else { 253*7c478bd9Sstevel@tonic-gate /* line longer than buflen, so get larger buf */ 254*7c478bd9Sstevel@tonic-gate buflen += LOGGER_BUFLEN; 255*7c478bd9Sstevel@tonic-gate offset += len; 256*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 257*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 258*7c478bd9Sstevel@tonic-gate "Realloc endp-p=%d, len=%d, offset=%d, " 259*7c478bd9Sstevel@tonic-gate "buflen %d\n", 260*7c478bd9Sstevel@tonic-gate endp - p, len, offset, buflen); 261*7c478bd9Sstevel@tonic-gate #endif 262*7c478bd9Sstevel@tonic-gate if ((buf = realloc(buf, buflen)) == NULL) { 263*7c478bd9Sstevel@tonic-gate perror("logger"); 264*7c478bd9Sstevel@tonic-gate exit(1); 265*7c478bd9Sstevel@tonic-gate } 266*7c478bd9Sstevel@tonic-gate p = buf + offset; 267*7c478bd9Sstevel@tonic-gate endp = buf + buflen; 268*7c478bd9Sstevel@tonic-gate } 269*7c478bd9Sstevel@tonic-gate } /* while */ 270*7c478bd9Sstevel@tonic-gate 271*7c478bd9Sstevel@tonic-gate if (feof(stdin)) { 272*7c478bd9Sstevel@tonic-gate if (p > buf) { 273*7c478bd9Sstevel@tonic-gate /* the last line did not end with newline */ 274*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 275*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 276*7c478bd9Sstevel@tonic-gate "(2) p-buf=%d, len=%d, buflen=%d, " 277*7c478bd9Sstevel@tonic-gate "buf >%s<\n", 278*7c478bd9Sstevel@tonic-gate p-buf, len, buflen, buf); 279*7c478bd9Sstevel@tonic-gate #endif 280*7c478bd9Sstevel@tonic-gate syslog(pri, "%s", buf); 281*7c478bd9Sstevel@tonic-gate } 282*7c478bd9Sstevel@tonic-gate } else { 283*7c478bd9Sstevel@tonic-gate /* 284*7c478bd9Sstevel@tonic-gate * fgets() encountered an error. Log unlogged data 285*7c478bd9Sstevel@tonic-gate * from earlier fgets() (if any). Write null byte 286*7c478bd9Sstevel@tonic-gate * after last full read, in case the fgets() that 287*7c478bd9Sstevel@tonic-gate * encountered error removed it and failed to null 288*7c478bd9Sstevel@tonic-gate * terminate. 289*7c478bd9Sstevel@tonic-gate */ 290*7c478bd9Sstevel@tonic-gate perror("logger"); 291*7c478bd9Sstevel@tonic-gate if (p > buf) { 292*7c478bd9Sstevel@tonic-gate *p = '\0'; 293*7c478bd9Sstevel@tonic-gate syslog(pri, "%s", buf); 294*7c478bd9Sstevel@tonic-gate } 295*7c478bd9Sstevel@tonic-gate status = 1; 296*7c478bd9Sstevel@tonic-gate } 297*7c478bd9Sstevel@tonic-gate } /* else !(argc > 0) */ 298*7c478bd9Sstevel@tonic-gate free(buf); 299*7c478bd9Sstevel@tonic-gate return (status); 300*7c478bd9Sstevel@tonic-gate } 301*7c478bd9Sstevel@tonic-gate 302*7c478bd9Sstevel@tonic-gate /* 303*7c478bd9Sstevel@tonic-gate * Decode a symbolic name to a numeric value 304*7c478bd9Sstevel@tonic-gate */ 305*7c478bd9Sstevel@tonic-gate 306*7c478bd9Sstevel@tonic-gate 307*7c478bd9Sstevel@tonic-gate static int 308*7c478bd9Sstevel@tonic-gate pencode(s) 309*7c478bd9Sstevel@tonic-gate register char *s; 310*7c478bd9Sstevel@tonic-gate { 311*7c478bd9Sstevel@tonic-gate register char *p; 312*7c478bd9Sstevel@tonic-gate int lev; 313*7c478bd9Sstevel@tonic-gate int fac = 0; 314*7c478bd9Sstevel@tonic-gate 315*7c478bd9Sstevel@tonic-gate for (p = s; *s && *s != '.'; s++); 316*7c478bd9Sstevel@tonic-gate if (*s) { 317*7c478bd9Sstevel@tonic-gate *s = '\0'; 318*7c478bd9Sstevel@tonic-gate fac = decode(p, FacNames); 319*7c478bd9Sstevel@tonic-gate if (fac < 0) 320*7c478bd9Sstevel@tonic-gate bailout("unknown facility name: ", p); 321*7c478bd9Sstevel@tonic-gate *s++ = '.'; 322*7c478bd9Sstevel@tonic-gate } else 323*7c478bd9Sstevel@tonic-gate s = p; 324*7c478bd9Sstevel@tonic-gate lev = decode(s, PriNames); 325*7c478bd9Sstevel@tonic-gate if (lev < 0) 326*7c478bd9Sstevel@tonic-gate bailout("unknown priority name: ", s); 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK)); 329*7c478bd9Sstevel@tonic-gate } 330*7c478bd9Sstevel@tonic-gate 331*7c478bd9Sstevel@tonic-gate 332*7c478bd9Sstevel@tonic-gate static int 333*7c478bd9Sstevel@tonic-gate decode(name, codetab) 334*7c478bd9Sstevel@tonic-gate char *name; 335*7c478bd9Sstevel@tonic-gate struct code *codetab; 336*7c478bd9Sstevel@tonic-gate { 337*7c478bd9Sstevel@tonic-gate register struct code *c; 338*7c478bd9Sstevel@tonic-gate 339*7c478bd9Sstevel@tonic-gate if (isdigit(*name)) 340*7c478bd9Sstevel@tonic-gate return (atoi(name)); 341*7c478bd9Sstevel@tonic-gate 342*7c478bd9Sstevel@tonic-gate for (c = codetab; c->c_name; c++) 343*7c478bd9Sstevel@tonic-gate if (strcasecmp(name, c->c_name) == 0) 344*7c478bd9Sstevel@tonic-gate return (c->c_val); 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate return (-1); 347*7c478bd9Sstevel@tonic-gate } 348*7c478bd9Sstevel@tonic-gate 349*7c478bd9Sstevel@tonic-gate 350*7c478bd9Sstevel@tonic-gate static void 351*7c478bd9Sstevel@tonic-gate bailout(a, b) 352*7c478bd9Sstevel@tonic-gate char *a, *b; 353*7c478bd9Sstevel@tonic-gate { 354*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("logger: %s%s\n"), a, b); 355*7c478bd9Sstevel@tonic-gate exit(1); 356*7c478bd9Sstevel@tonic-gate } 357*7c478bd9Sstevel@tonic-gate 358*7c478bd9Sstevel@tonic-gate 359*7c478bd9Sstevel@tonic-gate static void 360*7c478bd9Sstevel@tonic-gate usage(void) 361*7c478bd9Sstevel@tonic-gate { 362*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 363*7c478bd9Sstevel@tonic-gate "Usage:\tlogger string\n" 364*7c478bd9Sstevel@tonic-gate "\tlogger [-i] [-f filename] [-p priority] [-t tag] " 365*7c478bd9Sstevel@tonic-gate "[message] ...\n")); 366*7c478bd9Sstevel@tonic-gate exit(1); 367*7c478bd9Sstevel@tonic-gate } 368