From: Hyejin Kim Date: Thu, 3 Sep 2015 06:51:18 +0000 (+0900) Subject: syslogd : add the buffering option to keep logs in memory buffer X-Git-Tag: accepted/tizen/mobile/20150903.110754^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=34f25eaca12559a6edbb101b59247ba8b1009625;p=platform%2Fupstream%2Ftoybox.git syslogd : add the buffering option to keep logs in memory buffer Change-Id: Ia6f475fa1e6bef4b867694a398f6f15d34480d6e --- 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); }