Patch from Bastian Blank:
authorEric Andersen <andersen@codepoet.org>
Tue, 22 Jun 2004 10:07:17 +0000 (10:07 -0000)
committerEric Andersen <andersen@codepoet.org>
Tue, 22 Jun 2004 10:07:17 +0000 (10:07 -0000)
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

include/libbb.h
init/init.c
libbb/Makefile.in
libbb/syslog_msg_with_name.c
loginutils/getty.c
networking/telnetd.c
sysklogd/klogd.c

index 17a5940caa56e9c02021e6dc5d95b21592d28951..c52e65555e16a1f116516ed78415de9d120b2cfd 100644 (file)
@@ -249,9 +249,6 @@ extern int vdprintf(int d, const char *format, va_list ap);
 int nfsmount(const char *spec, const char *node, int *flags,
             char **extra_opts, char **mount_opts, int running_bg);
 
-void syslog_msg_with_name(const char *name, int facility, int pri, const char *msg);
-void syslog_msg(int facility, int pri, const char *msg);
-
 /* Include our own copy of struct sysinfo to avoid binary compatability
  * problems with Linux 2.4, which changed things.  Grumble, grumble. */
 struct sysinfo {
index 588e4e75cd85b404928aba381de8f0da29b16993..11ebc6bf96f0254c38afef21c001fa9b2c26cb46 100644 (file)
@@ -229,7 +229,9 @@ static void message(int device, const char *fmt, ...)
        /* Log the message to syslogd */
        if (device & LOG) {
                /* don`t out "\r\n" */
-               syslog_msg(LOG_DAEMON, LOG_INFO, msg + 1);
+               openlog(bb_applet_name, 0, LOG_DAEMON);
+               syslog(LOG_INFO, "%s", msg);
+               closelog();
        }
 
        msg[l++] = '\n';
index eff3224b1e1a707908c68384db7fffce2a873411..f993b21ea114bf0a78da777015626198394bb4bc 100644 (file)
@@ -41,7 +41,7 @@ LIBBB_SRC:= \
        read_package_field.c recursive_action.c remove_file.c \
        restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
        safe_strncpy.c setup_environment.c simplify_path.c syscalls.c \
-       syslog_msg_with_name.c trim.c u_signal_names.c vdprintf.c verror_msg.c \
+       trim.c u_signal_names.c vdprintf.c verror_msg.c \
        vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c \
        xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
        get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
index ac472dbdae58a6926da163bbefc26a6db0a9a442..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,45 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <sys/syslog.h>
-#include "libbb.h"
-
-void syslog_msg_with_name(const char *name, int facility, int pri, const char *msg)
-{
-       openlog(name, 0, facility);
-       syslog(pri, "%s", msg);
-       closelog();
-}
-
-void syslog_msg(int facility, int pri, const char *msg)
-{
-       syslog_msg_with_name(bb_applet_name, facility, pri, msg);
-}
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
index 0e475e4c0c10c6644a2682647ca06ab09c0679e3..b211733eed34bd69e6646c12b387d052907f245b 100644 (file)
@@ -998,7 +998,9 @@ static void error(const char *fmt, ...)
        va_end(va_alist);
 
 #ifdef USE_SYSLOG
-       syslog_msg(LOG_AUTH, LOG_ERR, buf);
+       openlog(bb_applet_name, 0, LOG_AUTH);
+       syslog(LOG_ERR, "%s", buf);
+       closelog();
 #else
        strncat(bp, "\r\n", 256 - strlen(buf));
        buf[255] = 0;
index efb2988b30b8978c4a17b07413073f2057e7790e..724c7cf75fc6318cae8e6201e31981ba453c7828 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: telnetd.c,v 1.11 2004/03/15 08:28:53 andersen Exp $
+/* $Id: telnetd.c,v 1.12 2004/06/22 10:07:17 andersen Exp $
  *
  * Simple telnet server
  * Bjorn Wesen, Axis Communications AB (bjornw@axis.com)
@@ -269,7 +269,7 @@ make_new_session(int sockfd)
        pty = getpty(tty_name);
 
        if (pty < 0) {
-               syslog_msg(LOG_USER, LOG_ERR, "All network ports in use!");
+               syslog(LOG_ERR, "All network ports in use!");
                return 0;
        }
 
@@ -292,7 +292,7 @@ make_new_session(int sockfd)
 
 
        if ((pid = fork()) < 0) {
-               syslog_msg(LOG_USER, LOG_ERR, "Can`t forking");
+               syslog(LOG_ERR, "Can`t forking");
        }
        if (pid == 0) {
                /* In child, open the child's side of the tty.  */
@@ -304,7 +304,7 @@ make_new_session(int sockfd)
                setsid();
 
                if (open(tty_name, O_RDWR /*| O_NOCTTY*/) < 0) {
-                       syslog_msg(LOG_USER, LOG_ERR, "Could not open tty");
+                       syslog(LOG_ERR, "Could not open tty");
                        exit(1);
                        }
                dup(0);
@@ -330,7 +330,7 @@ make_new_session(int sockfd)
                execv(loginpath, (char *const *)argv_init);
 
                /* NOT REACHED */
-               syslog_msg(LOG_USER, LOG_ERR, "execv error");
+               syslog(LOG_ERR, "execv error");
                exit(1);
        }
 
@@ -422,6 +422,8 @@ telnetd_main(int argc, char **argv)
 
        argv_init[0] = loginpath;
 
+       openlog(bb_applet_name, 0, LOG_USER);
+
 #ifdef CONFIG_FEATURE_TELNETD_INETD
        maxfd = 1;
        sessions = make_new_session();
index 94da61658fa6a1b0c8df851ddc26f30bfefc95f9..9f07d67435691e5af65672cc082acc9f4d5c8b5a 100644 (file)
@@ -47,8 +47,8 @@ static void klogd_signal(int sig)
        klogctl(7, NULL, 0);
        klogctl(0, 0, 0);
        /* logMessage(0, "Kernel log daemon exiting."); */
-       syslog_msg(LOG_SYSLOG, LOG_NOTICE, "Kernel log daemon exiting.");
-       exit(TRUE);
+       syslog(LOG_NOTICE, "Kernel log daemon exiting.");
+       exit(EXIT_SUCCESS);
 }
 
 static void doKlogd(const char console_log_level) __attribute__ ((noreturn));
@@ -59,6 +59,8 @@ static void doKlogd(const char console_log_level)
        int i, n, lastc;
        char *start;
 
+       openlog("kernel", 0, LOG_KERN);
+
        /* Set up sig handlers */
        signal(SIGINT, klogd_signal);
        signal(SIGKILL, klogd_signal);
@@ -72,22 +74,17 @@ static void doKlogd(const char console_log_level)
        if (console_log_level)
                klogctl(8, NULL, console_log_level);
 
-       syslog_msg(LOG_SYSLOG, LOG_NOTICE, "klogd started: " BB_BANNER);
+       syslog(LOG_NOTICE, "klogd started: " BB_BANNER);
 
        while (1) {
                /* Use kernel syscalls */
                memset(log_buffer, '\0', sizeof(log_buffer));
                n = klogctl(2, log_buffer, sizeof(log_buffer));
                if (n < 0) {
-                       char message[80];
-
                        if (errno == EINTR)
                                continue;
-                       snprintf(message, 79,
-                                        "klogd: Error return from sys_sycall: %d - %s.\n", errno,
-                                        strerror(errno));
-                       syslog_msg(LOG_SYSLOG, LOG_ERR, message);
-                       exit(1);
+                       syslog(LOG_ERR, "klogd: Error return from sys_sycall: %d - %s.\n", errno, strerror(errno));
+                       exit(EXIT_FAILURE);
                }
 
                /* klogctl buffer parsing modelled after code in dmesg.c */
@@ -107,7 +104,7 @@ static void doKlogd(const char console_log_level)
                        }
                        if (log_buffer[i] == '\n') {
                                log_buffer[i] = '\0';   /* zero terminate this message */
-                               syslog_msg(LOG_KERN, priority, start);
+                               syslog(priority, start);
                                start = &log_buffer[i + 1];
                                priority = LOG_INFO;
                        }