summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toys/pending/syslogd.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/toys/pending/syslogd.c b/toys/pending/syslogd.c
index 450bd72..fd0a355 100644
--- a/toys/pending/syslogd.c
+++ b/toys/pending/syslogd.c
@@ -5,14 +5,14 @@
*
* No Standard
-USE_SYSLOGD(NEWTOY(syslogd,">0l#<1>8=8R:b#<0>99=1s#<0=200m#<0>71582787=20O:p:f:a:nSKLD", TOYFLAG_SBIN|TOYFLAG_STAYROOT))
+USE_SYSLOGD(NEWTOY(syslogd,">0l#<1>8=8R:b#<0>99=1B#<0>99=0s#<0=2000m#<0>71582787=20O:p:f:a:nSKLD", TOYFLAG_SBIN|TOYFLAG_STAYROOT))
config SYSLOGD
bool "syslogd"
- default n
+ default y
help
usage: syslogd [-a socket] [-O logfile] [-f config file] [-m interval]
- [-p socket] [-s SIZE] [-b N] [-R HOST] [-l N] [-nSLKD]
+ [-p socket] [-s SIZE] [-b N] [-B N][-R HOST] [-l N] [-nSLKD]
System logging utility
@@ -27,6 +27,7 @@ config SYSLOGD
-L Log locally and via network (default is network only if -R)"
-s SIZE Max size (KB) before rotation (default:200KB, 0=off)
-b N rotated logs to keep (default:1, max=99, 0=purge)
+ -B N Set number of logs to keep logs in memory buffer before write (default:0, max=99, 0=purge)
-K Log to kernel printk buffer (use dmesg to read it)
-l N Log only messages more urgent than prio(default:8 max:8 min:1)
-D Drop duplicates
@@ -54,6 +55,12 @@ struct logfile {
struct sockaddr_in saddr;
};
+// Log buffer
+struct logbuffer {
+ int len;
+ char buf[1024];
+};
+
GLOBALS(
char *socket;
char *config_file;
@@ -61,6 +68,7 @@ GLOBALS(
char *logfile;
long interval;
long rot_size;
+ long buf_count;
long rot_count;
char *remote_log;
long log_prio;
@@ -278,7 +286,9 @@ static void open_logfiles(void)
//write to file with rotation
static int write_rotate(struct logfile *tf, int len)
{
- int size, isreg;
+ int size, isreg, idx;
+ static int buf_idx = 0;
+ static struct logbuffer buffer[100];
struct stat statf;
isreg = (!fstat(tf->logfd, &statf) && S_ISREG(statf.st_mode));
size = statf.st_size;
@@ -308,6 +318,18 @@ static int write_rotate(struct logfile *tf, int len)
ftruncate(tf->logfd, 0);
}
}
+ if (TT.buf_count && (toys.optflags & FLAG_B)) {
+ if (buf_idx < TT.buf_count) {
+ memcpy(buffer[buf_idx].buf, toybuf, len);
+ buffer[buf_idx].buf[len + 1] = '\0';
+ buffer[buf_idx].len = len;
+ buf_idx++;
+ return len;
+ } else {
+ for (idx = 0; idx < TT.buf_count; idx++) write(tf->logfd, buffer[idx].buf, buffer[idx].len);
+ buf_idx = 0;
+ }
+ }
return write(tf->logfd, toybuf, len);
}