mirror of
https://github.com/sheumann/hush.git
synced 2025-01-11 23:29:51 +00:00
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>
This commit is contained in:
parent
6d8ea1d50e
commit
92edab1aa6
@ -10,10 +10,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//usage:#define logread_trivial_usage
|
//usage:#define logread_trivial_usage
|
||||||
//usage: "[-f]"
|
//usage: "[-fF]"
|
||||||
//usage:#define logread_full_usage "\n\n"
|
//usage:#define logread_full_usage "\n\n"
|
||||||
//usage: "Show messages in syslogd's circular buffer\n"
|
//usage: "Show messages in syslogd's circular buffer\n"
|
||||||
//usage: "\n -f Output data as log grows"
|
//usage: "\n -f Output data as log grows"
|
||||||
|
//usage: "\n -F Same as -f, but dump buffer first"
|
||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
@ -83,7 +84,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
unsigned cur;
|
unsigned cur;
|
||||||
int log_semid; /* ipc semaphore id */
|
int log_semid; /* ipc semaphore id */
|
||||||
int log_shmid; /* ipc shared memory id */
|
int log_shmid; /* ipc shared memory id */
|
||||||
smallint follow = getopt32(argv, "f");
|
int follow = getopt32(argv, "fF");
|
||||||
|
|
||||||
INIT_G();
|
INIT_G();
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
/* Max possible value for tail is shbuf->size - 1 */
|
/* Max possible value for tail is shbuf->size - 1 */
|
||||||
cur = shbuf->tail;
|
cur = shbuf->tail;
|
||||||
|
|
||||||
/* Loop for logread -f, one pass if there was no -f */
|
/* Loop for -f or -F, one pass otherwise */
|
||||||
do {
|
do {
|
||||||
unsigned shbuf_size;
|
unsigned shbuf_size;
|
||||||
unsigned shbuf_tail;
|
unsigned shbuf_tail;
|
||||||
@ -129,7 +130,12 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
printf("cur:%u tail:%u size:%u\n",
|
printf("cur:%u tail:%u size:%u\n",
|
||||||
cur, shbuf_tail, shbuf_size);
|
cur, shbuf_tail, shbuf_size);
|
||||||
|
|
||||||
if (!follow) {
|
if (!(follow & 1)) { /* not -f */
|
||||||
|
/* if -F, "convert" it to -f, so that we dont
|
||||||
|
* dump the entire buffer on each iteration
|
||||||
|
*/
|
||||||
|
follow >>= 1;
|
||||||
|
|
||||||
/* advance to oldest complete message */
|
/* advance to oldest complete message */
|
||||||
/* find NUL */
|
/* find NUL */
|
||||||
cur += strlen(shbuf_data + cur);
|
cur += strlen(shbuf_data + cur);
|
||||||
@ -142,7 +148,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
cur++;
|
cur++;
|
||||||
if (cur >= shbuf_size) /* last byte in buffer? */
|
if (cur >= shbuf_size) /* last byte in buffer? */
|
||||||
cur = 0;
|
cur = 0;
|
||||||
} else { /* logread -f */
|
} else { /* -f */
|
||||||
if (cur == shbuf_tail) {
|
if (cur == shbuf_tail) {
|
||||||
sem_up(log_semid);
|
sem_up(log_semid);
|
||||||
fflush_all();
|
fflush_all();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user