Hi,

I attach the ubuntu patches against klogd.c and klogd.8 for your reference.

Also included is the ubuntu klogd initscript.

Andras

-- 
                 Andras Korn <korn at chardonnay.math.bme.hu>
                 <http://chardonnay.math.bme.hu/~korn/> QOTD:
               Growing old is mandatory, growing up is optional!
--- sysklogd-1.4.1.orig/klogd.c
+++ sysklogd-1.4.1/klogd.c
@@ -20,6 +20,13 @@
 */
 
 /*
+ * Thu Nov 25 16:48:39 CET 2004:  Martin Pitt
+ *      Added option -P to give alternative location of /proc/kmsg ("-" for
+ *      stdin). This allows to run klogd entirely without root privileges.
+ *
+ *      Added support for macro PIDFILE_DIR which is used as pid file directory
+ *      instead of _PATH_VARRUN.
+ *
  * Steve Lord ([EMAIL PROTECTED]) 7th Nov 92
  *
  * Modified to check for kernel info by Dr. G.W. Wettstein 02/17/93.
@@ -279,7 +286,9 @@
 #define LOG_LINE_LENGTH 1000
 
 #ifndef TESTING
-#if defined(FSSTND)
+#if defined(PIDFILE_DIR)
+static char    *PidFile = PIDFILE_DIR "klogd.pid";
+#elif defined(FSSTND)
 static char    *PidFile = _PATH_VARRUN "klogd.pid";
 #else
 static char    *PidFile = "/etc/klogd.pid";
@@ -303,6 +312,8 @@
 
 static FILE *output_file = (FILE *) 0;
 
+static char     *kmsg_file = NULL; /* NULL means default /proc/kmsg */
+
 static enum LOGSRC {none, proc, kernel} logsrc;
 
 int debugging = 0;
@@ -524,6 +535,22 @@
                ksyslog(6, NULL, 0);
        }
 
+        /* Do we read kernel messages from a pipe? */
+        if ( kmsg_file ) {
+                if ( !strcmp(kmsg_file, "-") )
+                        kmsg = fileno(stdin);
+                else {
+                        if ( (kmsg = open(kmsg_file, O_RDONLY)) < 0 )
+                        {
+                                fprintf(stderr, "klogd: Cannot open kmsg file, 
" \
+                                        "%d - %s.\n", errno, strerror(errno));
+                                ksyslog(7, NULL, 0);
+                                exit(1);
+                        }
+                }
+                return proc;
+        }
+
        /*
         * First do a stat to determine whether or not the proc based
         * file system is available to get kernel messages from.
@@ -994,7 +1021,7 @@
        chdir ("/");
 #endif
        /* Parse the command-line. */
-       while ((ch = getopt(argc, argv, "c:df:iIk:nopsvx2")) != EOF)
+       while ((ch = getopt(argc, argv, "c:df:iIk:nopP:svx2")) != EOF)
                switch((char)ch)
                {
                    case '2':           /* Print lines with symbols twice. */
@@ -1028,6 +1055,9 @@
                    case 'p':
                        SetParanoiaLevel(1);    /* Load symbols on oops. */
                        break;  
+                    case 'P':           /* Alternative kmsg file path */
+                        kmsg_file = strdup(optarg);
+                        break;
                    case 's':           /* Use syscall interface. */
                        use_syscall = 1;
                        break;
@@ -1039,7 +1069,6 @@
                        break;
                }
 
-
        /* Set console logging level. */
        if ( log_level != (char *) 0 )
        {
--- sysklogd-1.4.1.orig/klogd.8
+++ sysklogd-1.4.1/klogd.8
@@ -21,6 +21,9 @@
 .RB [ " \-n " ]
 .RB [ " \-o " ]
 .RB [ " \-p " ]
+.RB [ " \-P "
+.I path
+]
 .RB [ " \-s " ]
 .RB [ " \-k "
 .I fname
@@ -58,18 +61,23 @@
 is started and controlled by 
 .BR init (8).
 .TP
-.B "-o"
+.B "\-o"
 Execute in 'one\-shot' mode.  This causes \fBklogd\fP to read and log
 all the messages that are found in the kernel message buffers.  After
 a single read and log cycle the daemon exits.
 .TP
-.B "-p"
+.B "\-p"
 Enable paranoia.  This option controls when klogd loads kernel module symbol
 information.  Setting this switch causes klogd to load the kernel module
 symbol information whenever an Oops string is detected in the kernel message
 stream.
 .TP
-.B "-s"
+.BI "\-P " path
+Use \fIpath\fR instead of /proc/kmsg as the source of the kernel message.
+Specify "-" to read from standard input.  This allows klogd to run entirely
+without root privileges.
+.TP
+.B "\-s"
 Force \fBklogd\fP to use the system call interface to the kernel message
 buffers.
 .TP
@@ -100,10 +108,15 @@
 .I /proc
 file system and the syscall (sys_syslog) interface, although
 ultimately they are one and the same.  Klogd is designed to choose
-whichever source of information is the most appropriate.  It does this
-by first checking for the presence of a mounted 
+whichever source of information is the most appropriate.  If the
+.B \-P
+switch is used,
+.B klogd
+opens the specified path as the source of kernel log information.  Otherwise
+.B klogd
+checks for the presence of a mounted 
 .I /proc
-file system.  If this is found the 
+file system and if this is found the 
 .I /proc/kmsg
 file is used as the source of kernel log
 information.  If the proc file system is not mounted 
@@ -321,7 +334,7 @@
 .B klogd
 to reload the module symbol information whenever a protection fault
 is detected.  Caution should be used before invoking the program in
-\'paranoid\' mode.  The stability of the kernel and the operating
+\&'paranoid\&' mode.  The stability of the kernel and the operating
 environment is always under question when a protection fault occurs.
 Since the klogd daemon must execute system calls in order to read the
 module symbol information there is the possibility that the system may
--- sysklogd-1.4.1.orig/debian/rc.klogd
+++ sysklogd-1.4.1/debian/rc.klogd
@@ -0,0 +1,68 @@
+#! /bin/sh
+# /etc/init.d/klogd: start the kernel log daemon.
+
+### BEGIN INIT INFO
+# Provides:             klogd
+# Required-Start:       $time syslog
+# Required-Stop:        $time syslog
+# Default-Start:        2 3 4 5
+# Default-Stop:         S 0 1 6
+# Short-Description:    kernel logger
+### END INIT INFO
+
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+pidfile=/var/run/klogd/klogd.pid
+kmsgpipe=/var/run/klogd/kmsg
+kmsgpidfile=/var/run/klogd/kmsgpipe.pid
+binpath=/sbin/klogd
+
+test -f $binpath || exit 0
+. /lib/lsb/init-functions
+
+#  Use KLOGD="-k /boot/System.map-$(uname -r)" to specify System.map
+#
+KLOGD="-P $kmsgpipe"
+
+test ! -r /etc/default/klogd || . /etc/default/klogd
+
+. /lib/lsb/init-functions
+
+case "$1" in
+  start)
+    log_begin_msg "Starting kernel log..."
+
+    # create klog-writeable pid and fifo directory
+    mkdir -p /var/run/klogd
+    chown klog:klog /var/run/klogd
+    mkfifo -m 700 $kmsgpipe
+    chown klog:klog $kmsgpipe
+
+    # shovel /proc/kmsg to pipe readable by klogd user
+    start-stop-daemon --start --pidfile $kmsgpidfile --exec /bin/dd -b -m -- 
bs=1 if=/proc/kmsg of=$kmsgpipe
+
+    # start klogd as non-root with reading from kmsgpipe
+    start-stop-daemon --start --quiet --chuid klog --exec $binpath -- $KLOGD
+    log_end_msg $?
+    ;;
+  stop)
+    log_begin_msg "Stopping kernel log..."
+    start-stop-daemon --stop --retry TERM/1/TERM/1/TERM/4/KILL --quiet 
--oknodo --exec $binpath --pidfile $pidfile
+
+    # stop kmsgpipe
+    start-stop-daemon --stop --quiet --oknodo --pidfile $kmsgpidfile
+    rm -f $kmsgpidfile $kmsgpipe
+
+    log_end_msg $?
+    ;;
+  restart|force-reload)
+    $0 stop
+    sleep 1
+    $0 start
+    ;;
+  *)
+    log_success_msg "Usage: /etc/init.d/klogd 
{start|stop|restart|force-reload}"
+    exit 1
+esac
+
+exit 0

Reply via email to