From c780ef730c7383e9f3de167893f53f650da07558 Mon Sep 17 00:00:00 2001 From: Sooyoung Ha Date: Sun, 1 Nov 2015 19:49:53 +0900 Subject: [PATCH] debug: fix a bug about reading debugch name 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 --- tizen/src/util/new_debug_ch.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tizen/src/util/new_debug_ch.c b/tizen/src/util/new_debug_ch.c index acb21a0..073a4b0 100644 --- a/tizen/src/util/new_debug_ch.c +++ b/tizen/src/util/new_debug_ch.c @@ -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); } -- 2.7.4