1 /* vi: set sw=4 ts=4: */
3 * Mini logger implementation for busybox
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 * Done in syslogd_and_logger.c:
14 #define SYSLOG_NAMES_CONST
18 /* Decode a symbolic name to a numeric value
19 * this function is based on code
20 * Copyright (c) 1983, 1993
21 * The Regents of the University of California. All rights reserved.
23 * Original copyright notice is retained at the end of this file.
25 static int decode(char *name, const CODE *codetab)
31 for (c = codetab; c->c_name; c++) {
32 if (!strcasecmp(name, c->c_name)) {
40 /* Decode a symbolic name to a numeric value
41 * this function is based on code
42 * Copyright (c) 1983, 1993
43 * The Regents of the University of California. All rights reserved.
45 * Original copyright notice is retained at the end of this file.
47 static int pencode(char *s)
50 int lev, fac = LOG_USER;
52 for (save = s; *s && *s != '.'; ++s)
56 fac = decode(save, facilitynames);
58 bb_error_msg_and_die("unknown %s name: %s", "facility", save);
63 lev = decode(s, prioritynames);
65 bb_error_msg_and_die("unknown %s name: %s", "priority", save);
66 return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
69 #define strbuf bb_common_bufsiz1
71 int logger_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
72 int logger_main(int argc, char **argv)
78 /* Fill out the name string early (may be overwritten later) */
79 str_t = uid2uname_utoa(geteuid());
81 /* Parse any options */
82 opt = getopt32(argv, "p:st:", &str_p, &str_t);
84 if (opt & 0x2) /* -s */
86 //if (opt & 0x4) /* -t */
88 i = LOG_USER | LOG_NOTICE;
89 if (opt & 0x1) /* -p */
95 while (fgets(strbuf, COMMON_BUFSIZE, stdin)) {
97 && NOT_LONE_CHAR(strbuf, '\n')
99 /* Neither "" nor "\n" */
100 syslog(i, "%s", strbuf);
104 char *message = NULL;
108 len += strlen(*argv) + 1;
109 message = xrealloc(message, len + 1);
110 sprintf(message + pos, " %s", *argv),
113 syslog(i, "%s", message + 1); /* skip leading " " */
120 /* Clean up. Needed because we are included from syslogd_and_logger.c */
124 * Copyright (c) 1983, 1993
125 * The Regents of the University of California. All rights reserved.
127 * This is the original license statement for the decode and pencode functions.
129 * Redistribution and use in source and binary forms, with or without
130 * modification, are permitted provided that the following conditions
132 * 1. Redistributions of source code must retain the above copyright
133 * notice, this list of conditions and the following disclaimer.
134 * 2. Redistributions in binary form must reproduce the above copyright
135 * notice, this list of conditions and the following disclaimer in the
136 * documentation and/or other materials provided with the distribution.
138 * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
139 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
141 * 4. Neither the name of the University nor the names of its contributors
142 * may be used to endorse or promote products derived from this software
143 * without specific prior written permission.
145 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
146 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
147 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
148 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
149 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
150 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
151 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
152 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
153 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
154 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF