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>
31 #if !defined BB_SYSLOGD
34 #include <sys/syslog.h>
37 /* We have to do this since the header file defines static
38 * structues. Argh.... bad libc, bad, bad...
40 #include <sys/syslog.h>
41 typedef struct _code {
45 extern CODE prioritynames[];
46 extern CODE facilitynames[];
49 /* Decode a symbolic name to a numeric value
50 * this function is based on code
51 * Copyright (c) 1983, 1993
52 * The Regents of the University of California. All rights reserved.
54 static int decode(char *name, CODE * codetab)
60 for (c = codetab; c->c_name; c++) {
61 if (!strcasecmp(name, c->c_name)) {
69 /* Decode a symbolic name to a numeric value
70 * this function is based on code
71 * Copyright (c) 1983, 1993
72 * The Regents of the University of California. All rights reserved.
74 static int pencode(char *s)
77 int lev, fac = LOG_USER;
79 for (save = s; *s && *s != '.'; ++s);
82 fac = decode(save, facilitynames);
84 fatalError("unknown facility name: %s\n", save);
89 lev = decode(s, prioritynames);
91 fatalError("unknown priority name: %s\n", save);
92 return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
96 extern int logger_main(int argc, char **argv)
98 int pri = LOG_USER | LOG_NOTICE;
100 int fromStdinFlag = FALSE;
101 int stopLookingAtMeLikeThat = FALSE;
102 char *message=NULL, buf[1024], name[128];
104 /* Fill out the name string early (may be overwritten later */
105 my_getpwuid(name, geteuid());
107 /* Parse any options */
108 while (--argc > 0 && **(++argv) == '-') {
109 if (*((*argv) + 1) == '\0') {
110 fromStdinFlag = TRUE;
112 stopLookingAtMeLikeThat = FALSE;
113 while (*(++(*argv)) && stopLookingAtMeLikeThat == FALSE) {
116 option |= LOG_PERROR;
122 pri = pencode(*(++argv));
123 stopLookingAtMeLikeThat = TRUE;
129 strncpy(name, *(++argv), sizeof(name));
130 stopLookingAtMeLikeThat = TRUE;
138 if (fromStdinFlag == TRUE) {
139 /* read from stdin */
143 while ((c = getc(stdin)) != EOF && i < sizeof(buf)) {
151 fatalError("No message\n");
154 openlog(name, option, (pri | LOG_FACMASK));
155 syslog(pri, message);