1 /* vi: set sw=4 ts=4: */
3 * Mini logger implementation for busybox
5 * Copyright (C) 1999,2000 by Lineo, inc.
6 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <sys/types.h>
32 #if !defined BB_SYSLOGD
35 #include <sys/syslog.h>
38 /* We have to do this since the header file defines static
39 * structues. Argh.... bad libc, bad, bad...
41 #include <sys/syslog.h>
42 typedef struct _code {
46 extern CODE prioritynames[];
47 extern CODE facilitynames[];
50 /* Decode a symbolic name to a numeric value
51 * this function is based on code
52 * Copyright (c) 1983, 1993
53 * The Regents of the University of California. All rights reserved.
55 static int decode(char *name, CODE * codetab)
61 for (c = codetab; c->c_name; c++) {
62 if (!strcasecmp(name, c->c_name)) {
70 /* Decode a symbolic name to a numeric value
71 * this function is based on code
72 * Copyright (c) 1983, 1993
73 * The Regents of the University of California. All rights reserved.
75 static int pencode(char *s)
78 int lev, fac = LOG_USER;
80 for (save = s; *s && *s != '.'; ++s);
83 fac = decode(save, facilitynames);
85 errorMsg("unknown facility name: %s\n", save);
92 lev = decode(s, prioritynames);
94 errorMsg("unknown priority name: %s\n", save);
97 return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
101 extern int logger_main(int argc, char **argv)
103 int pri = LOG_USER | LOG_NOTICE;
105 int fromStdinFlag = FALSE;
106 int stopLookingAtMeLikeThat = FALSE;
107 char *message=NULL, buf[1024], name[128];
109 /* Fill out the name string early (may be overwritten later */
110 my_getpwuid(name, geteuid());
112 /* Parse any options */
113 while (--argc > 0 && **(++argv) == '-') {
114 if (*((*argv) + 1) == '\0') {
115 fromStdinFlag = TRUE;
117 stopLookingAtMeLikeThat = FALSE;
118 while (*(++(*argv)) && stopLookingAtMeLikeThat == FALSE) {
121 option |= LOG_PERROR;
127 pri = pencode(*(++argv));
128 stopLookingAtMeLikeThat = TRUE;
134 strncpy(name, *(++argv), sizeof(name));
135 stopLookingAtMeLikeThat = TRUE;
143 if (fromStdinFlag == TRUE) {
144 /* read from stdin */
148 while ((c = getc(stdin)) != EOF && i < sizeof(buf)) {
156 errorMsg("No message\n");
161 openlog(name, option, (pri | LOG_FACMASK));
162 syslog(pri, message);