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 *
*/
-#include <sys/poll.h>
+//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: "[-tttv] [-r C] [-R CHARS] [-l MATCHLEN] [-b BUFLEN] DIR..."
+//usage:#define svlogd_full_usage "\n\n"
+//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""nNUM - number of files to retain"
+/*usage: "\n""NNUM - min number files to retain" - confusing */
+/*usage: "\n""tSEC - rotate file if it get SEC seconds old" - confusing */
+//usage: "\n""!PROG - process rotated log with PROG"
+/*usage: "\n""uIPADDR - send log over UDP" - unsupported */
+/*usage: "\n""UIPADDR - send log over UDP and DONT log" - unsupported */
+/*usage: "\n""pPFX - prefix each line with PFX" - unsupported */
+//usage: "\n""+,-PATTERN - (de)select line for logging"
+//usage: "\n""E,ePATTERN - (de)select line for stderr"
+
#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)
unsigned nearest_rotate;
void* (*memRchr)(const void *, int, size_t);
+ char *shell;
smallint exitasap;
smallint rotateasap;
#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),
/* vfork'ed child trashes this byte, save... */
sv_ch = ld->fnsave[26];
+ if (!G.shell)
+ G.shell = xstrdup(get_shell_name());
+
while ((pid = vfork()) == -1)
pause2cannot("vfork for processor", ld->name);
if (!pid) {
fd = xopen("newstate", O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT);
xmove_fd(fd, 5);
-// getenv("SHELL")?
- execl(DEFAULT_SHELL, DEFAULT_SHELL_SHORT_NAME, "-c", ld->processor, (char*) NULL);
+ execl(G.shell, G.shell, "-c", ld->processor, (char*) NULL);
bb_perror_msg_and_die(FATAL"can't %s processor %s", "run", ld->name);
}
ld->fnsave[26] = sv_ch; /* ...restore */
while (fchdir(ld->fddir) == -1)
pause2cannot("change directory, want remove old logfile",
- ld->name);
+ ld->name);
oldest[0] = 'A';
oldest[1] = oldest[27] = '\0';
while (!(d = opendir(".")))
pause2cannot("open directory, want remove old logfile",
- ld->name);
+ ld->name);
errno = 0;
while ((f = readdir(d)))
if ((f->d_name[0] == '@') && (strlen(f->d_name) == 27)) {
ld->inst = new;
break;
case 's': {
- static const struct suffix_mult km_suffixes[] = {
- { "k", 1024 },
- { "m", 1024*1024 },
- { "", 0 }
- };
ld->sizemax = xatou_sfx(&s[1], km_suffixes);
break;
}
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;
}
/* Search for '\n' (in fact, np already holds the result) */
linelen = stdin_cnt;
if (np) {
- print_to_nl: /* NB: starting from here lineptr may point
+ print_to_nl:
+ /* NB: starting from here lineptr may point
* farther out into line[] */
linelen = np - lineptr + 1;
}
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);