aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2004-06-22 10:07:17 +0000
committerEric Andersen <andersen@codepoet.org>2004-06-22 10:07:17 +0000
commit36adca81f54d9479a440865acd29fc2fbcfbaf1d (patch)
tree6ad08a59a2a1cd6a8c24fd9683c5f8df32f5054c
parent78a5ddeff0352ee7a4f6a02333c07657f0b4ccc0 (diff)
downloadbusybox-w32-36adca81f54d9479a440865acd29fc2fbcfbaf1d.tar.gz
busybox-w32-36adca81f54d9479a440865acd29fc2fbcfbaf1d.tar.bz2
busybox-w32-36adca81f54d9479a440865acd29fc2fbcfbaf1d.zip
Patch from Bastian Blank:
On Sat, Jun 19, 2004 at 10:57:37PM +0200, Bastian Blank wrote: > The following patch changes klogd to use openlog/syslog themself > instead of calling syslog_msg which always calls the triple > openlog/syslog/closelog. Updated patch: get rid of syslog_msg entirely. Request from Erik Andersen. Bastian
-rw-r--r--include/libbb.h3
-rw-r--r--init/init.c4
-rw-r--r--libbb/Makefile.in2
-rw-r--r--libbb/syslog_msg_with_name.c45
-rw-r--r--loginutils/getty.c4
-rw-r--r--networking/telnetd.c12
-rw-r--r--sysklogd/klogd.c19
7 files changed, 22 insertions, 67 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 17a5940ca..c52e65555 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -249,9 +249,6 @@ extern int vdprintf(int d, const char *format, va_list ap);
249int nfsmount(const char *spec, const char *node, int *flags, 249int nfsmount(const char *spec, const char *node, int *flags,
250 char **extra_opts, char **mount_opts, int running_bg); 250 char **extra_opts, char **mount_opts, int running_bg);
251 251
252void syslog_msg_with_name(const char *name, int facility, int pri, const char *msg);
253void syslog_msg(int facility, int pri, const char *msg);
254
255/* Include our own copy of struct sysinfo to avoid binary compatability 252/* Include our own copy of struct sysinfo to avoid binary compatability
256 * problems with Linux 2.4, which changed things. Grumble, grumble. */ 253 * problems with Linux 2.4, which changed things. Grumble, grumble. */
257struct sysinfo { 254struct sysinfo {
diff --git a/init/init.c b/init/init.c
index 588e4e75c..11ebc6bf9 100644
--- a/init/init.c
+++ b/init/init.c
@@ -229,7 +229,9 @@ static void message(int device, const char *fmt, ...)
229 /* Log the message to syslogd */ 229 /* Log the message to syslogd */
230 if (device & LOG) { 230 if (device & LOG) {
231 /* don`t out "\r\n" */ 231 /* don`t out "\r\n" */
232 syslog_msg(LOG_DAEMON, LOG_INFO, msg + 1); 232 openlog(bb_applet_name, 0, LOG_DAEMON);
233 syslog(LOG_INFO, "%s", msg);
234 closelog();
233 } 235 }
234 236
235 msg[l++] = '\n'; 237 msg[l++] = '\n';
diff --git a/libbb/Makefile.in b/libbb/Makefile.in
index eff3224b1..f993b21ea 100644
--- a/libbb/Makefile.in
+++ b/libbb/Makefile.in
@@ -41,7 +41,7 @@ LIBBB_SRC:= \
41 read_package_field.c recursive_action.c remove_file.c \ 41 read_package_field.c recursive_action.c remove_file.c \
42 restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \ 42 restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
43 safe_strncpy.c setup_environment.c simplify_path.c syscalls.c \ 43 safe_strncpy.c setup_environment.c simplify_path.c syscalls.c \
44 syslog_msg_with_name.c trim.c u_signal_names.c vdprintf.c verror_msg.c \ 44 trim.c u_signal_names.c vdprintf.c verror_msg.c \
45 vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c \ 45 vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c \
46 xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ 46 xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
47 get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ 47 get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
diff --git a/libbb/syslog_msg_with_name.c b/libbb/syslog_msg_with_name.c
index ac472dbda..e69de29bb 100644
--- a/libbb/syslog_msg_with_name.c
+++ b/libbb/syslog_msg_with_name.c
@@ -1,45 +0,0 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <stdio.h>
23#include <sys/syslog.h>
24#include "libbb.h"
25
26void syslog_msg_with_name(const char *name, int facility, int pri, const char *msg)
27{
28 openlog(name, 0, facility);
29 syslog(pri, "%s", msg);
30 closelog();
31}
32
33void syslog_msg(int facility, int pri, const char *msg)
34{
35 syslog_msg_with_name(bb_applet_name, facility, pri, msg);
36}
37
38/* END CODE */
39/*
40Local Variables:
41c-file-style: "linux"
42c-basic-offset: 4
43tab-width: 4
44End:
45*/
diff --git a/loginutils/getty.c b/loginutils/getty.c
index 0e475e4c0..b211733ee 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -998,7 +998,9 @@ static void error(const char *fmt, ...)
998 va_end(va_alist); 998 va_end(va_alist);
999 999
1000#ifdef USE_SYSLOG 1000#ifdef USE_SYSLOG
1001 syslog_msg(LOG_AUTH, LOG_ERR, buf); 1001 openlog(bb_applet_name, 0, LOG_AUTH);
1002 syslog(LOG_ERR, "%s", buf);
1003 closelog();
1002#else 1004#else
1003 strncat(bp, "\r\n", 256 - strlen(buf)); 1005 strncat(bp, "\r\n", 256 - strlen(buf));
1004 buf[255] = 0; 1006 buf[255] = 0;
diff --git a/networking/telnetd.c b/networking/telnetd.c
index efb2988b3..724c7cf75 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -1,4 +1,4 @@
1/* $Id: telnetd.c,v 1.11 2004/03/15 08:28:53 andersen Exp $ 1/* $Id: telnetd.c,v 1.12 2004/06/22 10:07:17 andersen Exp $
2 * 2 *
3 * Simple telnet server 3 * Simple telnet server
4 * Bjorn Wesen, Axis Communications AB (bjornw@axis.com) 4 * Bjorn Wesen, Axis Communications AB (bjornw@axis.com)
@@ -269,7 +269,7 @@ make_new_session(int sockfd)
269 pty = getpty(tty_name); 269 pty = getpty(tty_name);
270 270
271 if (pty < 0) { 271 if (pty < 0) {
272 syslog_msg(LOG_USER, LOG_ERR, "All network ports in use!"); 272 syslog(LOG_ERR, "All network ports in use!");
273 return 0; 273 return 0;
274 } 274 }
275 275
@@ -292,7 +292,7 @@ make_new_session(int sockfd)
292 292
293 293
294 if ((pid = fork()) < 0) { 294 if ((pid = fork()) < 0) {
295 syslog_msg(LOG_USER, LOG_ERR, "Can`t forking"); 295 syslog(LOG_ERR, "Can`t forking");
296 } 296 }
297 if (pid == 0) { 297 if (pid == 0) {
298 /* In child, open the child's side of the tty. */ 298 /* In child, open the child's side of the tty. */
@@ -304,7 +304,7 @@ make_new_session(int sockfd)
304 setsid(); 304 setsid();
305 305
306 if (open(tty_name, O_RDWR /*| O_NOCTTY*/) < 0) { 306 if (open(tty_name, O_RDWR /*| O_NOCTTY*/) < 0) {
307 syslog_msg(LOG_USER, LOG_ERR, "Could not open tty"); 307 syslog(LOG_ERR, "Could not open tty");
308 exit(1); 308 exit(1);
309 } 309 }
310 dup(0); 310 dup(0);
@@ -330,7 +330,7 @@ make_new_session(int sockfd)
330 execv(loginpath, (char *const *)argv_init); 330 execv(loginpath, (char *const *)argv_init);
331 331
332 /* NOT REACHED */ 332 /* NOT REACHED */
333 syslog_msg(LOG_USER, LOG_ERR, "execv error"); 333 syslog(LOG_ERR, "execv error");
334 exit(1); 334 exit(1);
335 } 335 }
336 336
@@ -422,6 +422,8 @@ telnetd_main(int argc, char **argv)
422 422
423 argv_init[0] = loginpath; 423 argv_init[0] = loginpath;
424 424
425 openlog(bb_applet_name, 0, LOG_USER);
426
425#ifdef CONFIG_FEATURE_TELNETD_INETD 427#ifdef CONFIG_FEATURE_TELNETD_INETD
426 maxfd = 1; 428 maxfd = 1;
427 sessions = make_new_session(); 429 sessions = make_new_session();
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c
index 94da61658..9f07d6743 100644
--- a/sysklogd/klogd.c
+++ b/sysklogd/klogd.c
@@ -47,8 +47,8 @@ static void klogd_signal(int sig)
47 klogctl(7, NULL, 0); 47 klogctl(7, NULL, 0);
48 klogctl(0, 0, 0); 48 klogctl(0, 0, 0);
49 /* logMessage(0, "Kernel log daemon exiting."); */ 49 /* logMessage(0, "Kernel log daemon exiting."); */
50 syslog_msg(LOG_SYSLOG, LOG_NOTICE, "Kernel log daemon exiting."); 50 syslog(LOG_NOTICE, "Kernel log daemon exiting.");
51 exit(TRUE); 51 exit(EXIT_SUCCESS);
52} 52}
53 53
54static void doKlogd(const char console_log_level) __attribute__ ((noreturn)); 54static void doKlogd(const char console_log_level) __attribute__ ((noreturn));
@@ -59,6 +59,8 @@ static void doKlogd(const char console_log_level)
59 int i, n, lastc; 59 int i, n, lastc;
60 char *start; 60 char *start;
61 61
62 openlog("kernel", 0, LOG_KERN);
63
62 /* Set up sig handlers */ 64 /* Set up sig handlers */
63 signal(SIGINT, klogd_signal); 65 signal(SIGINT, klogd_signal);
64 signal(SIGKILL, klogd_signal); 66 signal(SIGKILL, klogd_signal);
@@ -72,22 +74,17 @@ static void doKlogd(const char console_log_level)
72 if (console_log_level) 74 if (console_log_level)
73 klogctl(8, NULL, console_log_level); 75 klogctl(8, NULL, console_log_level);
74 76
75 syslog_msg(LOG_SYSLOG, LOG_NOTICE, "klogd started: " BB_BANNER); 77 syslog(LOG_NOTICE, "klogd started: " BB_BANNER);
76 78
77 while (1) { 79 while (1) {
78 /* Use kernel syscalls */ 80 /* Use kernel syscalls */
79 memset(log_buffer, '\0', sizeof(log_buffer)); 81 memset(log_buffer, '\0', sizeof(log_buffer));
80 n = klogctl(2, log_buffer, sizeof(log_buffer)); 82 n = klogctl(2, log_buffer, sizeof(log_buffer));
81 if (n < 0) { 83 if (n < 0) {
82 char message[80];
83
84 if (errno == EINTR) 84 if (errno == EINTR)
85 continue; 85 continue;
86 snprintf(message, 79, 86 syslog(LOG_ERR, "klogd: Error return from sys_sycall: %d - %s.\n", errno, strerror(errno));
87 "klogd: Error return from sys_sycall: %d - %s.\n", errno, 87 exit(EXIT_FAILURE);
88 strerror(errno));
89 syslog_msg(LOG_SYSLOG, LOG_ERR, message);
90 exit(1);
91 } 88 }
92 89
93 /* klogctl buffer parsing modelled after code in dmesg.c */ 90 /* klogctl buffer parsing modelled after code in dmesg.c */
@@ -107,7 +104,7 @@ static void doKlogd(const char console_log_level)
107 } 104 }
108 if (log_buffer[i] == '\n') { 105 if (log_buffer[i] == '\n') {
109 log_buffer[i] = '\0'; /* zero terminate this message */ 106 log_buffer[i] = '\0'; /* zero terminate this message */
110 syslog_msg(LOG_KERN, priority, start); 107 syslog(priority, start);
111 start = &log_buffer[i + 1]; 108 start = &log_buffer[i + 1];
112 priority = LOG_INFO; 109 priority = LOG_INFO;
113 } 110 }