dlogutil : add "-d" option when the backend is journal 92/73892/3 accepted/tizen/common/20160616.151640 accepted/tizen/ivi/20160616.002553 accepted/tizen/mobile/20160616.002528 accepted/tizen/tv/20160616.002517 accepted/tizen/wearable/20160616.002524 submit/tizen/20160615.070756
authorKichan Kwon <k_c.kwon@samsung.com>
Fri, 10 Jun 2016 03:15:58 +0000 (12:15 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Fri, 10 Jun 2016 06:40:00 +0000 (15:40 +0900)
- "-d" : print log and exit (non-blocking)

- "-v" is ignored because of crash-worker issue

Change-Id: I81ae7854b1f9bbbc5e107a198f880b2ef577103f
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/logutil/logutil_journal.c

index 0def4e2..4cb4d6a 100755 (executable)
@@ -17,6 +17,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include "dlog.h"
 
@@ -26,6 +27,7 @@ int main (int argc, char **argv)
 {
        int r;
        sd_journal *j;
+       int no_wait = 0;
 
        static const char pri_table[DLOG_PRIO_MAX] = {
                [LOG_DEBUG] = 'D',
@@ -42,6 +44,28 @@ int main (int argc, char **argv)
                return 1;
        }
 
+       for (;;) {
+               int ret;
+
+               ret = getopt(argc, argv, "dv:");
+
+               if (ret < 0)
+                       break;
+
+               switch (ret) {
+               case 'd':
+                       no_wait = 1;
+                       break;
+               /* Ignore this option */
+               case 'v':
+                       break;
+               default:
+                       printf("Unrecognized Option\n");
+                       exit(-1);
+                       break;
+               };
+       }
+
        fprintf(stderr, "read\n");
        SD_JOURNAL_FOREACH(j) {
                const char *priority, *log_tag, *tid,  *message;
@@ -73,6 +97,11 @@ int main (int argc, char **argv)
                fprintf(stdout, "%c/%s(%5d): %s\n", pri_table[prio_idx], log_tag+8, atoi(tid+4), message+8);
        }
 
+       if (no_wait) {
+               sd_journal_close(j);
+               return 0;
+       }
+
        fprintf(stderr, "wait\n");
        for (;;) {
                const char *log_tag, *priority, *tid, *message;