debug: fix a bug about reading debugch name
authorSooyoung Ha <yoosah.ha@samsung.com>
Sun, 1 Nov 2015 10:49:53 +0000 (19:49 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 6 Nov 2015 13:18:28 +0000 (22:18 +0900)
The legacy code designed that DEBUGCH file always has a newline
character end of it, code tried to remove(means changed it to null char)
the last char. But surely, DEBUGCH file might not have the newline, it
could cause the unexpected behavior. So I add the newline check code.

Change-Id: Id5eb667adcdeef7fa3920069afc1e936100107ce
Signed-off-by: Sooyoung Ha <yoosah.ha@samsung.com>
tizen/src/util/new_debug_ch.c

index acb21a0..073a4b0 100644 (file)
@@ -139,6 +139,8 @@ static void parse_options(const char *str)
     char *opt, *next, *options;
     unsigned int i;
 
+    fprintf(stdout, "Enabled debug channels: [%s]\n", str);
+
     if (!(options = g_strdup(str))) {
         return;
     }
@@ -237,6 +239,7 @@ static void debug_init(void)
         debug = getenv("DEBUGCH");
     } else {
         if ((tmp = (char *)malloc(1024 + 1)) == NULL){
+            fprintf(stderr, "failed to malloc()\n");
             nb_debug_options = -1;
             fclose(fp);
             return;
@@ -252,9 +255,17 @@ static void debug_init(void)
             nb_debug_options = -1;
             return;
         }
+        /*
+         * Announcement
+         * This code designed that calls fgets() only once.
+         * So if you want to use DEBUGCH file for debuging,
+         * you should make it to single line, comma separated, no blank space.
+         */
         const char* str = fgets(tmp, 1024, fp);
         if (str) {
-            tmp[strlen(tmp) - 1] = 0;
+            if (tmp[strlen(tmp) - 1] == '\n') {
+                tmp[strlen(tmp) - 1] = '\0';
+            }
             debug = tmp;
         }
 
@@ -265,6 +276,7 @@ static void debug_init(void)
         if (!g_strcmp0(debug, "help")) {
             debug_usage();
         }
+        fprintf(stdout, "DEBUGCH has enabled.\n");
         parse_options(debug);
     }