diff -Naur busybox.orig/include/applets.h busybox/include/applets.h --- busybox.orig/include/applets.h 2008-06-28 12:58:39 +0000 +++ busybox/include/applets.h 2008-07-01 20:52:36 +0000 @@ -324,6 +324,7 @@ USE_SHA1SUM(APPLET_ODDNAME(sha1sum, md5_sha1_sum, _BB_DIR_USR_BIN, _BB_SUID_NEVER, sha1sum)) USE_SLATTACH(APPLET(slattach, _BB_DIR_SBIN, _BB_SUID_NEVER)) USE_SLEEP(APPLET_NOFORK(sleep, sleep, _BB_DIR_BIN, _BB_SUID_NEVER, sleep)) +USE_SOCKLOG(APPLET(socklog, _BB_DIR_SBIN, _BB_SUID_NEVER)) USE_SOFTLIMIT(APPLET_ODDNAME(softlimit, chpst, _BB_DIR_USR_BIN, _BB_SUID_NEVER, softlimit)) USE_SORT(APPLET_NOEXEC(sort, sort, _BB_DIR_USR_BIN, _BB_SUID_NEVER, sort)) USE_SPLIT(APPLET(split, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) diff -Naur busybox.orig/include/usage.h busybox/include/usage.h --- busybox.orig/include/usage.h 2008-07-01 18:37:40 +0000 +++ busybox/include/usage.h 2008-07-01 20:52:36 +0000 @@ -3577,6 +3577,11 @@ "$ sleep 1d 3h 22m 8s\n" \ "[98528 second delay results]\n") +#define socklog_trivial_usage \ + "[-rRU] [unix|inet|ucspi] [args]" +#define socklog_full_usage "\n\n" \ + "[-rRU] [unix|inet|ucspi] [args]" + #define sort_trivial_usage \ "[-nru" \ USE_FEATURE_SORT_BIG("gMcszbdfimSTokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR") \ diff -Naur busybox.orig/runit/Config.in busybox/runit/Config.in --- busybox.orig/runit/Config.in 2008-02-17 06:50:59 +0000 +++ busybox/runit/Config.in 2008-07-01 21:02:21 +0000 @@ -20,6 +20,13 @@ a directory, in the services directory dir, up to a limit of 1000 subdirectories, and restarts a runsv process if it terminates. +config SOCKLOG + bool "socklog" + default n + help + socklog reads lines from /dev/log, UDP socket or stdin, optionally + prepends the lines and dumps the result to stdout. + config SV bool "sv" default n diff -Naur busybox.orig/runit/Kbuild busybox/runit/Kbuild --- busybox.orig/runit/Kbuild 2008-02-17 06:50:59 +0000 +++ busybox/runit/Kbuild 2008-07-01 20:52:36 +0000 @@ -15,3 +15,5 @@ lib-$(CONFIG_ENVUIDGID) += chpst.o lib-$(CONFIG_SETUIDGID) += chpst.o lib-$(CONFIG_SOFTLIMIT) += chpst.o + +lib-$(CONFIG_SOCKLOG) += socklog.o diff -Naur busybox.orig/runit/socklog.c busybox/runit/socklog.c --- busybox.orig/runit/socklog.c 1970-01-01 00:00:00 +0000 +++ busybox/runit/socklog.c 2008-07-01 20:59:39 +0000 @@ -0,0 +1,80 @@ +/* +Copyright (c) 2001-2005, Gerrit Pape +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* + * Busybox version of Gerrit Pape's http://smarden.org/socklog/ + * + * Busyboxed by Vladimir Dronnikov +*/ + +/* +socklog -rRU [unix] [path] +socklog -rR inet [ip [port]] +socklog -rR ucspi [ENV] [ENV] ... +*/ + +#include "libbb.h" + +int socklog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int socklog_main(int argc ATTRIBUTE_UNUSED, char **argv) +{ +#define buf bb_common_bufsiz1 + + unsigned opts; + + opts = getopt32(argv, "rRU"); // FIXME: ignored. Request for features, please! + argv += optind; + + // FIXME: /dev/log... from jurassic park, I fancy? + if (!*argv) { + if (!freopen("/dev/log", "r", stdin)) + bb_perror_msg_and_die("open %s", "/dev/log"); + } else if ('i' == *argv[0]) { + char *host = (*++argv) ? *argv : (char *)"127.0.0.1"; + unsigned port = (*++argv) ? xatou_range(*argv, 1, 65535) : 514; + xmove_fd(create_and_bind_dgram_or_die(host, port), STDIN_FILENO); + } + /* else assume ucspi */ + + // point to prefix + argv++; + + // dump lines read from stdin optionally prefixing them + // N.B. COMMON_BUFSIZE is enough long + // FIXME: translate facilities et al. from kernel number to human readable from + while (fgets(buf, sizeof(buf)-1, stdin) != 0) { +/* for (char **var = argv; *var; var++) { + char *val = getenv(*var); + if (val && *val) + printf("%s: ", val); + }*/ + printf("%s: %s", *argv, buf); // \n included + fflush(stdout); // if sed had an option to flush there would be no need in socklog :^) + } + + return EXIT_SUCCESS; +}