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
+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,
*/
/* Busyboxed by Denys Vlasenko <vda.linux@googlemail.com> */
-/* TODO: depends on runit_lib.c - review and reduce/eliminate */
/*
Config files
-*: *: pid *
*/
+//config:config SVLOGD
+//config: bool "svlogd (15 kb)"
+//config: default y
+//config: help
+//config: svlogd continuously reads log data from its standard input, optionally
+//config: filters log messages, and writes the data to one or more automatically
+//config: rotated logs.
+
+//applet:IF_SVLOGD(APPLET(svlogd, BB_DIR_USR_SBIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_SVLOGD) += svlogd.o
+
//usage:#define svlogd_trivial_usage
-//usage: "[-ttv] [-r C] [-R CHARS] [-l MATCHLEN] [-b BUFLEN] DIR..."
+//usage: "[-tttv] [-r C] [-R CHARS] [-l MATCHLEN] [-b BUFLEN] DIR..."
//usage:#define svlogd_full_usage "\n\n"
-//usage: "Continuously read log data from stdin and write to rotated log files in DIRs"
+//usage: "Read log data from stdin and write to rotated log files in DIRs"
//usage: "\n"
//usage: "\n""DIR/config file modifies behavior:"
//usage: "\n""sSIZE - when to rotate logs"
//usage: "\n""+,-PATTERN - (de)select line for logging"
//usage: "\n""E,ePATTERN - (de)select line for stderr"
-#include <sys/poll.h>
#include <sys/file.h>
#include "libbb.h"
+#include "common_bufsiz.h"
#include "runit_lib.h"
#define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0)
#define blocked_sigset (G.blocked_sigset)
#define fl_flag_0 (G.fl_flag_0 )
#define dirn (G.dirn )
+#define line bb_common_bufsiz1
#define INIT_G() do { \
+ setup_common_bufsiz(); \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
linemax = 1000; \
/*buflen = 1024;*/ \
replace = ""; \
} while (0)
-#define line bb_common_bufsiz1
-
#define FATAL "fatal: "
#define WARNING "warning: "
/*** ex fmt_ptime.[ch] ***/
/* NUL terminated */
-static void fmt_time_human_30nul(char *s)
+static void fmt_time_human_30nul(char *s, char dt_delim)
{
struct tm *ptm;
struct timeval tv;
gettimeofday(&tv, NULL);
ptm = gmtime(&tv.tv_sec);
- sprintf(s, "%04u-%02u-%02u_%02u:%02u:%02u.%06u000",
+ sprintf(s, "%04u-%02u-%02u%c%02u:%02u:%02u.%06u000",
(unsigned)(1900 + ptm->tm_year),
(unsigned)(ptm->tm_mon + 1),
(unsigned)(ptm->tm_mday),
+ dt_delim,
(unsigned)(ptm->tm_hour),
(unsigned)(ptm->tm_min),
(unsigned)(ptm->tm_sec),
case '!':
if (s[1]) {
free(ld->processor);
- ld->processor = wstrdup(s);
+ ld->processor = wstrdup(&s[1]);
}
break;
}
}
if (opt & 2) if (!repl) repl = '_'; // -R
if (opt & 4) { // -l
- linemax = xatou_range(l, 0, BUFSIZ-26);
+ linemax = xatou_range(l, 0, COMMON_BUFSIZE-26);
if (linemax == 0)
- linemax = BUFSIZ-26;
+ linemax = COMMON_BUFSIZE-26;
if (linemax < 256)
linemax = 256;
}
if (timestamp) {
if (timestamp == 1)
fmt_time_bernstein_25(stamp);
- else /* 2: */
- fmt_time_human_30nul(stamp);
+ else /* 2+: */
+ fmt_time_human_30nul(stamp, timestamp == 2 ? '_' : 'T');
printlen += 26;
printptr -= 26;
memcpy(printptr, stamp, 25);