diff options
author | Hyejin Kim <hyejin0906.kim@samsung.com> | 2015-09-03 15:51:18 +0900 |
---|---|---|
committer | Hyejin Kim <hyejin0906.kim@samsung.com> | 2015-09-02 23:52:31 -0700 |
commit | 34f25eaca12559a6edbb101b59247ba8b1009625 (patch) | |
tree | 7447f7b2c82fcf7a9f232561dd1deb71b0db56ad | |
parent | b7d6e1f0e1a5df95e2950beaf9269932f895269a (diff) | |
download | toybox-34f25eaca12559a6edbb101b59247ba8b1009625.tar.gz toybox-34f25eaca12559a6edbb101b59247ba8b1009625.tar.bz2 toybox-34f25eaca12559a6edbb101b59247ba8b1009625.zip |
syslogd : add the buffering option to keep logs in memory buffersubmit/tizen/20150903.070527accepted/tizen/wearable/20150903.111041accepted/tizen/tv/20150903.110912accepted/tizen/mobile/20150903.110754
Change-Id: Ia6f475fa1e6bef4b867694a398f6f15d34480d6e
-rw-r--r-- | toys/pending/syslogd.c | 30 |
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); } |