From 5e4b3f95cf50faf85ef60a894ee4e3ad8ca2dc81 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Mon, 5 Nov 2012 12:45:02 +0800 Subject: [PATCH] Fix: '-g' conflicts with '-c' option and update help info Check options conflict and exit gracefully if conflict occurred. Before applying this patch $ dlogutil -g -c arc = 3, optind = 3 ,Kb 0, rotate 4 ioctl: Bad file descriptor After applying this patch, it prints help info and exit. Change-Id: I9133398d6f67cad6aadb6224beddd75ed06ef0dc Signed-off-by: Chengwei Yang --- logutil.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/logutil.c b/logutil.c index d9d369f..92f2da4 100755 --- a/logutil.c +++ b/logutil.c @@ -402,11 +402,11 @@ static void show_help(const char *cmd) " -r [] Rotate log every kbytes. (16 if unspecified). Requires -f\n" " -n Sets max number of rotated logs to , default 4\n" " -v Sets the log print format, where is one of:\n\n" - " brief process tag thread raw time threadtime long\n\n" - " -c clear (flush) the entire log and exit\n" + " brief(by default) process tag thread raw time threadtime long\n\n" + " -c clear (flush) the entire log and exit, conflicts with '-g'\n" " -d dump the log and then exit (don't block)\n" " -t print only the most recent lines (implies -d)\n" - " -g get the size of the log's ring buffer and exit\n" + " -g get the size of the log's ring buffer and exit, conflicts with '-c'\n" " -b request alternate ring buffer\n" " ('main' (default), 'radio', 'system')"); @@ -422,11 +422,7 @@ static void show_help(const char *cmd) " F Fatal\n" " S Silent (supress all output)\n" "\n'*' means '*:D' and by itself means :V\n" - "If no filterspec is found, filter defaults to '*:I'\n" - "\nIf not specified with -v, format is set defaults to \"brief\"\n\n"); - - - + "If no filterspec is found, filter defaults to '*:I'\n\n"); } @@ -652,6 +648,12 @@ int main(int argc, char **argv) } } + /* get log size conflicts with write mode */ + if (getLogSize && mode != O_RDONLY) { + show_help(argv[0]); + exit(-1); + } + if (!devices) { devices = log_devices_new("/dev/"LOGGER_LOG_MAIN); if (devices == NULL) { -- 2.7.4