aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Sutter <phil.sutter@viprinet.com>2015-03-22 17:36:20 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2015-03-22 17:37:20 +0100
commit92edab1aa6eae45ac8fa0cec8c8df9a47f547300 (patch)
tree738a5d864011189939847bceb8620af6371d4e62
parent6d8ea1d50ec6088c51a61ab3e9f849b7845dce6b (diff)
downloadbusybox-w32-92edab1aa6eae45ac8fa0cec8c8df9a47f547300.tar.gz
busybox-w32-92edab1aa6eae45ac8fa0cec8c8df9a47f547300.tar.bz2
busybox-w32-92edab1aa6eae45ac8fa0cec8c8df9a47f547300.zip
logread: implement dumpfollow mode of operation
This is basically a combination of the default (dump mode) and -f (follow mode). Specifying -F makes logread first dump the log buffer and then immediately start following it. function old new delta packed_usage 30412 30443 +31 logread_main 491 497 +6 Signed-off-by: Phil Sutter <phil.sutter@viprinet.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--sysklogd/logread.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/sysklogd/logread.c b/sysklogd/logread.c
index bea73d932..da4a4d4df 100644
--- a/sysklogd/logread.c
+++ b/sysklogd/logread.c
@@ -10,10 +10,11 @@
10 */ 10 */
11 11
12//usage:#define logread_trivial_usage 12//usage:#define logread_trivial_usage
13//usage: "[-f]" 13//usage: "[-fF]"
14//usage:#define logread_full_usage "\n\n" 14//usage:#define logread_full_usage "\n\n"
15//usage: "Show messages in syslogd's circular buffer\n" 15//usage: "Show messages in syslogd's circular buffer\n"
16//usage: "\n -f Output data as log grows" 16//usage: "\n -f Output data as log grows"
17//usage: "\n -F Same as -f, but dump buffer first"
17 18
18#include "libbb.h" 19#include "libbb.h"
19#include <sys/ipc.h> 20#include <sys/ipc.h>
@@ -83,7 +84,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
83 unsigned cur; 84 unsigned cur;
84 int log_semid; /* ipc semaphore id */ 85 int log_semid; /* ipc semaphore id */
85 int log_shmid; /* ipc shared memory id */ 86 int log_shmid; /* ipc shared memory id */
86 smallint follow = getopt32(argv, "f"); 87 int follow = getopt32(argv, "fF");
87 88
88 INIT_G(); 89 INIT_G();
89 90
@@ -106,7 +107,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
106 /* Max possible value for tail is shbuf->size - 1 */ 107 /* Max possible value for tail is shbuf->size - 1 */
107 cur = shbuf->tail; 108 cur = shbuf->tail;
108 109
109 /* Loop for logread -f, one pass if there was no -f */ 110 /* Loop for -f or -F, one pass otherwise */
110 do { 111 do {
111 unsigned shbuf_size; 112 unsigned shbuf_size;
112 unsigned shbuf_tail; 113 unsigned shbuf_tail;
@@ -129,7 +130,12 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
129 printf("cur:%u tail:%u size:%u\n", 130 printf("cur:%u tail:%u size:%u\n",
130 cur, shbuf_tail, shbuf_size); 131 cur, shbuf_tail, shbuf_size);
131 132
132 if (!follow) { 133 if (!(follow & 1)) { /* not -f */
134 /* if -F, "convert" it to -f, so that we dont
135 * dump the entire buffer on each iteration
136 */
137 follow >>= 1;
138
133 /* advance to oldest complete message */ 139 /* advance to oldest complete message */
134 /* find NUL */ 140 /* find NUL */
135 cur += strlen(shbuf_data + cur); 141 cur += strlen(shbuf_data + cur);
@@ -142,7 +148,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
142 cur++; 148 cur++;
143 if (cur >= shbuf_size) /* last byte in buffer? */ 149 if (cur >= shbuf_size) /* last byte in buffer? */
144 cur = 0; 150 cur = 0;
145 } else { /* logread -f */ 151 } else { /* -f */
146 if (cur == shbuf_tail) { 152 if (cur == shbuf_tail) {
147 sem_up(log_semid); 153 sem_up(log_semid);
148 fflush_all(); 154 fflush_all();