Fix as Tizen coding rule 38/55138/1 accepted/tizen/mobile/20151222.223859 accepted/tizen/tv/20151222.223917 accepted/tizen/wearable/20151222.223937 submit/tizen/20151222.090653 submit/tizen_common/20151229.142028 submit/tizen_common/20151229.144031 submit/tizen_common/20151229.154718
authorpr.jung <pr.jung@samsung.com>
Tue, 22 Dec 2015 07:20:13 +0000 (16:20 +0900)
committerpr.jung <pr.jung@samsung.com>
Tue, 22 Dec 2015 07:36:57 +0000 (16:36 +0900)
Change-Id: I4b50e0b86c2a237eacd7da7b9fd0cdaf9b9ecb2c
Signed-off-by: pr.jung <pr.jung@samsung.com>
TC/unit/utc_ApplicationFW___dlog_print_func.c
TC/unit/utc_ApplicationFW___dlog_vprint_func.c
TC/unit/utc_ApplicationFW_dlog_print_func.c
TC/unit/utc_ApplicationFW_dlog_vprint_func.c
src/libdlog/log.c
src/libdlog/logconfig.c
src/libdlog/loglimiter.c
src/logger/logger.c
src/logutil/logutil.c
src/shared/logprint.c

index 589c4f9..66cefff 100755 (executable)
@@ -21,7 +21,7 @@ struct tet_testlist tet_testlist[] = {
        { NULL, 0 }
 };
 
-//static int pid;
+/* static int pid; */
 
 static void startup(void)
 {
@@ -37,10 +37,10 @@ static void cleanup(void)
 static void utc_ApplicationFW___dlog_print_func_01(void)
 {
        int r = 0;
-       
-       r = __dlog_print(LOG_ID_MAIN, DLOG_DEBUG,"DLOG_TEST", "dlog test message for tetware\n");
 
-       if (r<0) {
+       r = __dlog_print(LOG_ID_MAIN, DLOG_DEBUG, "DLOG_TEST", "dlog test message for tetware\n");
+
+       if (r < 0) {
                tet_printf("__dlog_print() failed in positive test case");
                tet_result(TET_FAIL);
                return;
@@ -55,9 +55,9 @@ static void utc_ApplicationFW___dlog_print_func_02(void)
 {
        int r = 0;
 
-       r = __dlog_print( LOG_ID_MAX , DLOG_DEBUG,"DLOG_TEST", "dlog test message for tetware\n");
+       r = __dlog_print(LOG_ID_MAX, DLOG_DEBUG, "DLOG_TEST", "dlog test message for tetware\n");
 
-       if (r>=0) {
+       if (r >= 0) {
                tet_printf("__dlog_print() failed in negative test case");
                tet_result(TET_FAIL);
                return;
index 9e4a30b..5358364 100755 (executable)
@@ -43,10 +43,10 @@ void utc_ApplicationFW___dlog_vprint_func_01(void)
 
        /*      va_start(ap, fmt);*/
 
-       r = __dlog_vprint(LOG_ID_MAIN, DLOG_DEBUG, "DLOG_TEST", buf, ap );
+       r = __dlog_vprint(LOG_ID_MAIN, DLOG_DEBUG, "DLOG_TEST", buf, ap);
        /*      va_end(ap);*/
 
-       if (r<0) {
+       if (r < 0) {
                tet_printf("__dlog_vprint() failed in positive test case");
                tet_result(TET_FAIL);
                return;
@@ -62,12 +62,12 @@ void utc_ApplicationFW___dlog_vprint_func_02(void)
        int r = 0;
        char buf[LOG_BUF_SIZE];
        va_list ap;
-//     va_start(ap, fmt);
+/*     va_start(ap, fmt); */
 
-       r = __dlog_vprint(LOG_ID_MAX, DLOG_DEBUG,"DLOG_TEST", fmt, ap );
-//     va_end(ap);
+       r = __dlog_vprint(LOG_ID_MAX, DLOG_DEBUG, "DLOG_TEST", fmt, ap);
+/*     va_end(ap); */
 
-       if (r>=0) {
+       if (r >= 0) {
                tet_printf("__dlog_vprint() failed in negative test case");
                tet_result(TET_FAIL);
                return;
index 517edc4..f628abc 100755 (executable)
@@ -21,7 +21,7 @@ struct tet_testlist tet_testlist[] = {
        { NULL, 0 }
 };
 
-//static int pid;
+/* static int pid; */
 
 static void startup(void)
 {
@@ -40,7 +40,7 @@ static void utc_ApplicationFW_dlog_print_func_01(void)
 
        r = dlog_print(DLOG_DEBUG, "DLOG_TEST", "dlog test message for tetware\n");
 
-       if (r<0) {
+       if (r < 0) {
                tet_printf("dlog_print() failed in positive test case");
                tet_result(TET_FAIL);
                return;
@@ -57,7 +57,7 @@ static void utc_ApplicationFW_dlog_print_func_02(void)
 
        r = dlog_print(DLOG_UNKNOWN, "DLOG_TEST", "dlog test message for tetware\n");
 
-       if (r>=0) {
+       if (r >= 0) {
                tet_printf("dlog_print() failed in negative test case");
                tet_result(TET_FAIL);
                return;
index eb736a2..ed0029a 100755 (executable)
@@ -43,10 +43,10 @@ void utc_ApplicationFW_dlog_vprint_func_01(void)
 
        /*      va_start(ap, fmt);*/
 
-       r = dlog_vprint(DLOG_DEBUG, "DLOG_TEST", buf, ap );
+       r = dlog_vprint(DLOG_DEBUG, "DLOG_TEST", buf, ap);
        /*      va_end(ap);*/
 
-       if (r<0) {
+       if (r < 0) {
                tet_printf("dlog_vprint() failed in positive test case");
                tet_result(TET_FAIL);
                return;
@@ -62,12 +62,12 @@ void utc_ApplicationFW_dlog_vprint_func_02(void)
        int r = 0;
        char buf[LOG_BUF_SIZE];
        va_list ap;
-//     va_start(ap, fmt);
+/*     va_start(ap, fmt); */
 
-       r = dlog_vprint(DLOG_UNKNOWN, "DLOG_TEST", fmt, ap );
-//     va_end(ap);
+       r = dlog_vprint(DLOG_UNKNOWN, "DLOG_TEST", fmt, ap);
+/*     va_end(ap); */
 
-       if (r>=0) {
+       if (r >= 0) {
                tet_printf("dlog_vprint() failed in negative test case");
                tet_result(TET_FAIL);
                return;
index 061ba68..63e9c7f 100755 (executable)
@@ -98,16 +98,16 @@ static int __write_to_log_sd_journal(log_id_t log_id, log_priority prio, const c
 
        pid_t tid = (pid_t)syscall(SYS_gettid);
 
-       if(!msg)
+       if (!msg)
                return DLOG_ERROR_INVALID_PARAMETER;
 
-       if(strncmp(lid_str, "UNKNOWN", 7) == 0)
+       if (strncmp(lid_str, "UNKNOWN", 7) == 0)
                return DLOG_ERROR_INVALID_PARAMETER;
 
-       if(prio < DLOG_VERBOSE || prio >= DLOG_PRIO_MAX)
+       if (prio < DLOG_VERBOSE || prio >= DLOG_PRIO_MAX)
                return DLOG_ERROR_INVALID_PARAMETER;
 
-       if(!tag)
+       if (!tag)
                tag = "";
 
        struct iovec vec[5];
@@ -189,9 +189,8 @@ static void __configure(void)
        }
 
        if (config.lc_limiter) {
-               if (0 > __log_limiter_initialize()) {
+               if (0 > __log_limiter_initialize())
                        config.lc_limiter = 0;
-               }
        }
 }
 
@@ -208,11 +207,11 @@ static void __dlog_init(void)
        log_fds[LOG_ID_SYSTEM] = open("/dev/"LOG_SYSTEM, O_WRONLY);
        log_fds[LOG_ID_RADIO] = open("/dev/"LOG_RADIO, O_WRONLY);
        log_fds[LOG_ID_APPS] = open("/dev/"LOG_APPS, O_WRONLY);
-       if (log_fds[LOG_ID_MAIN] < 0) {
+       if (log_fds[LOG_ID_MAIN] < 0)
                write_to_log = __write_to_log_null;
-       } else {
+       else
                write_to_log = __write_to_log_kernel;
-       }
+
        if (log_fds[LOG_ID_RADIO] < 0)
                log_fds[LOG_ID_RADIO] = log_fds[LOG_ID_MAIN];
        if (log_fds[LOG_ID_SYSTEM] < 0)
@@ -254,7 +253,7 @@ static int dlog_should_log(log_id_t log_id, const char* tag, int prio)
                        return DLOG_ERROR_NOT_PERMITTED;
                } else if (should_log < 0) {
                        write_to_log(log_id, prio, tag,
-                                    "Your log has been blocked due to limit of log lines per minute.");
+                                       "Your log has been blocked due to limit of log lines per minute.");
                        return DLOG_ERROR_NOT_PERMITTED;
                }
        }
index 6c7eabc..7110fee 100755 (executable)
@@ -48,7 +48,7 @@
 
 
 static int log_config_multiplex_opt(char* opt_str, char* val_str, int prio,
-                                    struct log_config* config)
+                                       struct log_config* config)
 {
        int value = 0;
 
@@ -59,15 +59,14 @@ static int log_config_multiplex_opt(char* opt_str, char* val_str, int prio,
                if (!strncasecmp(ALLOW_STRING, val_str, sizeof(ALLOW_STRING))) {
                        value = __LOG_LIMITER_LIMIT_MAX + 1;
                } else if (!strncasecmp(DENY_STRING, val_str,
-                                                    sizeof(DENY_STRING))) {
+                                               sizeof(DENY_STRING))) {
                        value = 0;
                } else {
                        char* endptr = NULL;
 
                        value = strtoul(val_str, &endptr, 0);
-                       if (*endptr != '\0') {
+                       if (*endptr != '\0')
                                return RET_ERROR;
-                       }
                }
 
                return __log_limiter_add_rule(opt_str, prio, value);
@@ -78,20 +77,20 @@ static int log_config_multiplex_opt(char* opt_str, char* val_str, int prio,
                } else if (isNO(*val_str)) {
                        value = 0;
                } else if (!strncasecmp(ON_STRING, val_str,
-                                       sizeof(ON_STRING))) {
+                                       sizeof(ON_STRING))) {
                        value = 1;
                } else if (!strncasecmp(OFF_STRING, val_str,
-                                       sizeof(OFF_STRING))) {
+                                       sizeof(OFF_STRING))) {
                        value = 0;
                } else {
                        return RET_ERROR;
                }
 
                if (!strncasecmp(LOG_PLATFORM_STRING, opt_str,
-                                sizeof(LOG_PLATFORM_STRING))) {
+                               sizeof(LOG_PLATFORM_STRING))) {
                        config->lc_plog = value;
                } else if (!strncasecmp(LOG_LIMITER_STRING, opt_str,
-                                      sizeof(LOG_LIMITER_STRING))) {
+                                       sizeof(LOG_LIMITER_STRING))) {
                        config->lc_limiter = value;
                } else {
                        return RET_ERROR;
@@ -112,28 +111,24 @@ int __log_config_read(const char* config_file, struct log_config* config)
        int ret = 0;
 
        /* Check input */
-       if (NULL == config_file || NULL == config) {
+       if (NULL == config_file || NULL == config)
                return RET_ERROR;
-       }
 
-       if (NULL == (fconfig = fopen(config_file, "r"))) {
+       if (NULL == (fconfig = fopen(config_file, "r")))
                return RET_ERROR;
-       }
 
        while (1) {
                memset(buf, 0, CONFIG_LINE_MAX_LEN);
                errno = 0;
                if (NULL == fgets(buf, CONFIG_LINE_MAX_LEN, fconfig)) {
-                       if (!errno) {
+                       if (!errno)
                                break;
-                       }
                        goto bailout;
                }
 
                /* We ignore comments and blank lines */
-               if (isCOMMENT(*buf) || isNEWLINE(*buf)) {
+               if (isCOMMENT(*buf) || isNEWLINE(*buf))
                        continue;
-               }
 
                memset(opt, 0, sizeof(opt));
                memset(opt_value, 0, sizeof(opt_value));
@@ -141,22 +136,20 @@ int __log_config_read(const char* config_file, struct log_config* config)
                /* Read configure line, sscanf() should return two tokens,
                 * even for tag filtering rule */
                ret = sscanf(buf, "%[A-z0-9-]\t%[A-z0-9]",
-                                 opt, opt_value);
+                               opt, opt_value);
                if (ret != 2) { /* The line is malformed ? */
                        char c = 0;
                        /* This could be rule with space inside TAG */
                        ret = sscanf(buf, "\"%[]A-z0-9*\x20_+:;/-]\"\t|\t%c\t%[A-z0-9]",
-                                         opt, &c, opt_value);
-                       if (ret != 3) {
+                                       opt, &c, opt_value);
+                       if (ret != 3)
                                goto bailout;
-                       }
                        prio = (int)c;
                }
 
 
-               if (0 > log_config_multiplex_opt(opt, opt_value, prio, config)) {
+               if (0 > log_config_multiplex_opt(opt, opt_value, prio, config))
                        goto bailout;
-               }
        }
 
        fclose(fconfig);
index a0e874e..85c1c51 100755 (executable)
@@ -42,9 +42,9 @@
 
 #define TIME_FRAME                60
 
-struct rule{
+struct rule {
        /* TODO: List element handle, the list could be embedded
-                into structure some day, like kernel lists */
+               into structure some day, like kernel lists */
        struct rule* prev;
 
        unsigned hash;
@@ -77,9 +77,8 @@ static void rules_destroy(struct rule* rlist)
 {
        struct rule* r;
 
-       if (NULL == rlist) {
+       if (NULL == rlist)
                return;
-       }
 
        while ((r = rlist)) {
                rlist = rlist->prev;
@@ -96,11 +95,10 @@ void __log_limiter_rules_purge(void)
 static int rule_compare(struct rule* r1, struct rule* r2)
 {
        if (r1->hash == r2->hash) {
-               if (r1->prio == r2->prio) {
+               if (r1->prio == r2->prio)
                        return strncmp(r1->tag, r2->tag, strlen(r2->tag));
-               } else {
+               else
                        return (r1->prio > r2->prio ? 1 : (-1));
-               }
        }
 
        return (r1->hash > r2->hash ? 1 : (-1));
@@ -109,11 +107,10 @@ static int rule_compare(struct rule* r1, struct rule* r2)
 static int rule_match(struct rule* r1, unsigned key, const char* s, int prio)
 {
        if (r1->hash == key) {
-               if (r1->prio == prio) {
+               if (r1->prio == prio)
                        return strncmp(r1->tag, s, strlen(s));
-               } else {
+               else
                        return (r1->prio > prio ? 1 : (-1));
-               }
        }
 
        return (r1->hash > key ? 1 : (-1));
@@ -136,17 +133,17 @@ static int util_prio_to_char(int prio)
                return pri_table[prio];
        } else {
                switch (prio) {
-                       case 'V': case 'v': case '1':
-                       case 'D': case 'd': case '2':
-                       case 'I': case 'i': case '3':
-                       case 'W': case 'w': case '4':
-                       case 'E': case 'e': case '5':
-                       case 'F': case 'f': case '6':
-                       case 'S': case 's': case '7':
-                       case '*':
-                               return prio;
-
-                       default:
+               case 'V': case 'v': case '1':
+               case 'D': case 'd': case '2':
+               case 'I': case 'i': case '3':
+               case 'W': case 'w': case '4':
+               case 'E': case 'e': case '5':
+               case 'F': case 'f': case '6':
+               case 'S': case 's': case '7':
+               case '*':
+                       return prio;
+
+               default:
                                ;;
                }
        }
@@ -162,13 +159,11 @@ static unsigned util_hash_key(const char* s, int c)
 
        hash = ((hash << 5) + hash) + c;
 
-       if (!s || !s[0]) {
+       if (!s || !s[0])
                goto finish;
-       }
 
-       while ('\0' != (c = *s++)) {
+       while ('\0' != (c = *s++))
                hash = ((hash << 5) + hash) + c;
-       }
 
 finish:
        /* Makes the hash more diverse */
@@ -185,9 +180,8 @@ static struct hashmap* hashmap_create(int size, hash_cmp_func_t cmp_func,
        /* please keep hashmap fill ratio around 50% */
        int internal_size = size << 1;
 
-       if (!cmp_func || !match_func || !size) {
+       if (!cmp_func || !match_func || !size)
                return NULL;
-       }
 
 
        /* Round up the lines counter to next power of two. */
@@ -200,9 +194,9 @@ static struct hashmap* hashmap_create(int size, hash_cmp_func_t cmp_func,
        internal_size++;
 
        hm = malloc(sizeof(struct hashmap) + internal_size * sizeof(void*));
-       if (!hm) {
+       if (!hm)
                return NULL;
-       }
+
        /* Initialize hash field to correct value */
        memset((void*)hm, 0, sizeof(struct hashmap) + internal_size * sizeof(void*));
 
@@ -226,9 +220,8 @@ static void hashmap_add(struct hashmap* hm, struct rule* r)
        unsigned b = (r->hash & HASHMAP_MASK(hm));
 
        while (hm->bucket[b]) {
-               if (!hm->cmp(r, (struct rule*)hm->bucket[b])) {
+               if (!hm->cmp(r, (struct rule*)hm->bucket[b]))
                        break;
-               }
                b = (b + 1) & HASHMAP_MASK(hm);
        }
 
@@ -242,20 +235,17 @@ static struct rule* hashmap_search(struct hashmap* hm, unsigned key,
        unsigned b0 = b;
 
        while (hm->bucket[b]) {
-               if (!hm->match(hm->bucket[b], key, tag, prio)) {
+               if (!hm->match(hm->bucket[b], key, tag, prio))
                        break;
-               }
 
                b = (b + 1) & HASHMAP_MASK(hm);
 
-               if (b0 == b) {
+               if (b0 == b)
                        return NULL;
-               }
        }
 
-       if (!hm->bucket[b]) {
+       if (!hm->bucket[b])
                return NULL;
-       }
 
        return hm->bucket[b];
 }
@@ -267,9 +257,8 @@ int __log_limiter_initialize(void)
        struct rule* rlist = NULL;
 
        /* logconfig.c module had to initialize this correctly */
-       if (NULL == rules_table) {
+       if (NULL == rules_table)
                return (-1);
-       }
 
        /* Count rules in the table */
        hm_size = 0;
@@ -281,11 +270,10 @@ int __log_limiter_initialize(void)
 
        /* Allocate hashmap */
        rules_hashmap = (struct hashmap*) hashmap_create(hm_size,
-                                                        &rule_compare,
-                                                        &rule_match);
-       if (NULL == rules_hashmap || !rules_hashmap->size) {
+                                                       &rule_compare,
+                                                       &rule_match);
+       if (NULL == rules_hashmap || !rules_hashmap->size)
                goto bailout;
-       }
 
        /* Add rule to hashmap */
        rlist = rules_table;
@@ -317,14 +305,13 @@ int __log_limiter_add_rule(const char* tag, int prio, int limit)
 {
        struct rule* r;
 
-       if (!tag) {
+       if (!tag)
                return (-1);
-       }
 
        r = (struct rule*) malloc(sizeof(struct rule));
-       if (NULL == r) {
+       if (NULL == r)
                return (-1);
-       }
+
        memset(r, 0, sizeof(struct rule));
 
        snprintf(r->tag, TAG_REASONABLE_LEN, "%s", tag);
@@ -367,7 +354,7 @@ int __log_limiter_pass_log(const char* tag, int prio)
                           let check general rule *:priority */
                        key = util_hash_key("*", util_prio_to_char(prio));
                        r = hashmap_search(rules_hashmap, key, "*",
-                                                      util_prio_to_char(prio));
+                                                       util_prio_to_char(prio));
                        if (!r) {
                                /* All known paths were exhausted,
                                   use global rule *:* */
@@ -375,25 +362,22 @@ int __log_limiter_pass_log(const char* tag, int prio)
                                r = hashmap_search(rules_hashmap, key, "*", '*');
 
                                /* *:* is not defined, so pass message through */
-                               if (!r) {
+                               if (!r)
                                        return 1;
-                               }
                        }
                }
        }
 
-       if (!r->limit) {
+       if (!r->limit)
                return 0;
-       } else if (__LOG_LIMITER_LIMIT_MAX < r->limit) {
+       else if (__LOG_LIMITER_LIMIT_MAX < r->limit)
                return 1;
-       }
 
        /* Decide, if it should go through or stop */
        now = time(NULL);
 
-       if (0 > now) {
+       if (0 > now)
                return 1;
-       }
 
        if (now - r->start <= TIME_FRAME) {
                if (r->hit >= 0) {
index 8eecbae..4f6228c 100755 (executable)
@@ -367,7 +367,7 @@ static void do_logger(struct log_device *dev)
                                        malloc(sizeof(struct queued_entry));
                                if (entry == NULL) {
                                        _E("failed to malloc queued_entry\n");
-                                       goto exit;//exit(EXIT_FAILURE);
+                                       goto exit; /* exit(EXIT_FAILURE); */
                                }
                                entry->next = NULL;
                                ret = read(pdev->fd, entry->buf,
@@ -382,7 +382,7 @@ static void do_logger(struct log_device *dev)
                                                break;
                                        }
                                        _E("dlogutil read");
-                                       goto exit;//exit(EXIT_FAILURE);
+                                       goto exit;/* exit(EXIT_FAILURE); */
                                } else if (!ret) {
                                        free(entry);
                                        _E("read: Unexpected EOF!\n");
@@ -393,7 +393,7 @@ static void do_logger(struct log_device *dev)
                                        _E("unexpected length. Expected %d, got %d\n",
                                                        entry->entry.len,
                                                        ret - (int)sizeof(struct logger_entry));
-                                       goto exit;//exit(EXIT_FAILURE);
+                                       goto exit;/* exit(EXIT_FAILURE); */
                                }
 
                                entry->entry.msg[entry->entry.len] = '\0';
@@ -886,8 +886,8 @@ static void sig_handler(int signo)
        exit(EXIT_SUCCESS);
 }
 
-static int help(void) {
-
+static int help(void)
+{
        printf("%s [OPTIONS...] \n\n"
                        "Logger, records log messages to files.\n\n"
                        "  -h      Show this help\n"
@@ -898,41 +898,42 @@ static int help(void) {
        return 0;
 }
 
-static int parse_argv(int argc, char *argv[]) {
+static int parse_argv(int argc, char *argv[])
+{
        int ret = 1, option;
 
        while ((option = getopt(argc, argv, "hb:t:")) != -1) {
                switch (option) {
-                       case 't':
-                               if (!isdigit(optarg[0])) {
-                                       ret = -EINVAL;
-                                       printf("Wrong argument!\n");
-                                       help();
-                                       goto exit;
-                               }
-                               min_interval = atoi(optarg);
-                               if (min_interval < 0 || INTERVAL_MAX < min_interval)
-                                       min_interval = 0;
-                               ret = 1;
-                               break;
-                       case 'b':
-                               if (!isdigit(optarg[0])) {
-                                       ret = -EINVAL;
-                                       printf("Wrong argument!\n");
-                                       help();
-                                       goto exit;
-                               }
-                               buffer_size = atoi(optarg);
-                               if (buffer_size < 0 || BUFFER_MAX < buffer_size)
-                                       buffer_size = 0;
-                               ret = 1;
-                               break;
-                       case 'h':
+               case 't':
+                       if (!isdigit(optarg[0])) {
+                               ret = -EINVAL;
+                               printf("Wrong argument!\n");
                                help();
-                               ret = 0;
                                goto exit;
-                       default:
+                       }
+                       min_interval = atoi(optarg);
+                       if (min_interval < 0 || INTERVAL_MAX < min_interval)
+                               min_interval = 0;
+                       ret = 1;
+                       break;
+               case 'b':
+                       if (!isdigit(optarg[0])) {
                                ret = -EINVAL;
+                               printf("Wrong argument!\n");
+                               help();
+                               goto exit;
+                       }
+                       buffer_size = atoi(optarg);
+                       if (buffer_size < 0 || BUFFER_MAX < buffer_size)
+                               buffer_size = 0;
+                       ret = 1;
+                       break;
+               case 'h':
+                       help();
+                       ret = 0;
+                       goto exit;
+               default:
+                       ret = -EINVAL;
                }
        }
 exit:
@@ -1022,9 +1023,9 @@ int main(int argc, char **argv)
                /* 5. attatch the work to device task for logging */
                dev = devices;
                while (dev) {
-                       if (command_list[i].devices[dev->id] == true) {
+                       if (command_list[i].devices[dev->id] == true)
                                work_add_to_device(dev, work);
-                       }
+
                        dev = dev->next;
                }
        }
index bcbd596..5cf033d 100755 (executable)
@@ -50,8 +50,8 @@ static bool g_nonblock = false;
 static int g_tail_lines = 0;
 
 static const char * g_output_filename = NULL;
-static int g_log_rotate_size_kbytes = 0;                   // 0 means "no log rotation"
-static int g_max_rotated_logs = DEFAULT_MAX_ROTATED_LOGS; // 0 means "unbounded"
+static int g_log_rotate_size_kbytes = 0;                   /* 0 means "no log rotation" */
+static int g_max_rotated_logs = DEFAULT_MAX_ROTATED_LOGS; /* 0 means "unbounded" */
 static int g_outfd = -1;
 static off_t g_out_byte_count = 0;
 static int g_dev_count = 0;
@@ -67,9 +67,9 @@ struct queued_entry_t {
 static int cmp(struct queued_entry_t* a, struct queued_entry_t* b)
 {
        int n = a->entry.sec - b->entry.sec;
-       if (n != 0) {
+       if (n != 0)
                return n;
-       }
+
        return a->entry.nsec - b->entry.nsec;
 }
 
@@ -88,15 +88,15 @@ static void enqueue(struct log_device_t* device, struct queued_entry_t* entry)
                device->queue = entry;
        } else {
                struct queued_entry_t** e = &device->queue;
-               while (*e && cmp(entry, *e) >= 0 ) {
+               while (*e && cmp(entry, *e) >= 0)
                        e = &((*e)->next);
-               }
+
                entry->next = *e;
                *e = entry;
        }
 }
 
-static int open_logfile (const char *pathname)
+static int open_logfile(const char *pathname)
 {
        return open(pathname, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
 }
@@ -105,36 +105,33 @@ static void rotate_logs()
 {
        int err;
        int i;
-       char file0[256]={0};
-       char file1[256]={0};
+       char file0[256] = {0};
+       char file1[256] = {0};
 
-       // Can't rotate logs if we're not outputting to a file
-       if (g_output_filename == NULL) {
+       /* Can't rotate logs if we're not outputting to a file */
+       if (g_output_filename == NULL)
                return;
-       }
 
        close(g_outfd);
 
        for (i = g_max_rotated_logs ; i > 0 ; i--) {
                snprintf(file1, 255, "%s.%d", g_output_filename, i);
 
-               if (i - 1 == 0) {
+               if (i - 1 == 0)
                        snprintf(file0, 255, "%s", g_output_filename);
-               } else {
+               else
                        snprintf(file0, 255, "%s.%d", g_output_filename, i - 1);
-               }
 
-               err = rename (file0, file1);
+               err = rename(file0, file1);
 
-               if (err < 0 && errno != ENOENT) {
+               if (err < 0 && errno != ENOENT)
                        perror("while rotating log files");
-               }
        }
 
-       g_outfd = open_logfile (g_output_filename);
+       g_outfd = open_logfile(g_output_filename);
 
        if (g_outfd < 0) {
-               perror ("couldn't open output file");
+               perror("couldn't open output file");
                exit(-1);
        }
 
@@ -152,9 +149,8 @@ static void processBuffer(struct log_device_t* dev, struct logger_entry *buf)
 
        err = log_process_log_buffer(buf, &entry);
 
-       if (err < 0) {
+       if (err < 0)
                goto error;
-       }
 
        if (log_should_print_line(g_logformat, entry.tag, entry.priority)) {
                if (false && g_dev_count > 1) {
@@ -178,11 +174,10 @@ static void processBuffer(struct log_device_t* dev, struct logger_entry *buf)
        g_out_byte_count += bytes_written;
 
        if (g_log_rotate_size_kbytes > 0 && (g_out_byte_count / 1024) >= g_log_rotate_size_kbytes) {
-               if (g_nonblock) {
+               if (g_nonblock)
                        exit(0);
-               } else {
+               else
                        rotate_logs();
-               }
        }
 
 error:
@@ -193,16 +188,17 @@ static void chooseFirst(struct log_device_t* dev, struct log_device_t** firstdev
 {
        for (*firstdev = NULL; dev != NULL; dev = dev->next) {
                if (dev->queue != NULL && (*firstdev == NULL ||
-                                       cmp(dev->queue, (*firstdev)->queue) < 0)) {
+                                               cmp(dev->queue, (*firstdev)->queue) < 0)) {
                        *firstdev = dev;
                }
        }
 }
 
-static void maybePrintStart(struct log_device_t* dev) {
+static void maybePrintStart(struct log_device_t* dev)
+{
        if (!dev->printed) {
                dev->printed = true;
-               if (g_dev_count > 1 ) {
+               if (g_dev_count > 1) {
                        char buf[1024];
                        snprintf(buf, sizeof(buf), "--------- beginning of %s\n", dev->device);
                        if (write(g_outfd, buf, strlen(buf)) < 0) {
@@ -213,7 +209,8 @@ static void maybePrintStart(struct log_device_t* dev) {
        }
 }
 
-static void skipNextEntry(struct log_device_t* dev) {
+static void skipNextEntry(struct log_device_t* dev)
+{
        maybePrintStart(dev);
        struct queued_entry_t* entry = dev->queue;
        dev->queue = entry->next;
@@ -234,33 +231,32 @@ static void read_log_lines(struct log_device_t* devices)
        int max = 0;
        int ret;
        int queued_lines = 0;
-       bool sleep = false; // for exit immediately when log buffer is empty and g_nonblock value is true.
+       bool sleep = false; /* for exit immediately when log buffer is empty and g_nonblock value is true. */
 
        int result;
        fd_set readset;
 
-       for (dev=devices; dev; dev = dev->next) {
-               if (dev->fd > max) {
+       for (dev = devices; dev; dev = dev->next) {
+               if (dev->fd > max)
                        max = dev->fd;
-               }
        }
 
        while (1) {
                do {
-                       struct timeval timeout = { 0, 5000 /* 5ms */ }; // If we oversleep it's ok, i.e. ignore EINTR.
+                       struct timeval timeout = { 0, 5000 /* 5ms */ }; /* If we oversleep it's ok, i.e. ignore EINTR. */
                        FD_ZERO(&readset);
-                       for (dev=devices; dev; dev = dev->next) {
+                       for (dev = devices; dev; dev = dev->next)
                                FD_SET(dev->fd, &readset);
-                       }
+
                        result = select(max + 1, &readset, NULL, NULL, sleep ? NULL : &timeout);
                } while (result == -1 && errno == EINTR);
 
                if (result >= 0) {
-                       for (dev=devices; dev; dev = dev->next) {
+                       for (dev = devices; dev; dev = dev->next) {
                                if (FD_ISSET(dev->fd, &readset)) {
-                                       struct queued_entry_t* entry = (struct queued_entry_t *)malloc(sizeof( struct queued_entry_t));
+                                       struct queued_entry_t* entry = (struct queued_entry_t *)malloc(sizeof(struct queued_entry_t));
                                        if (entry == NULL) {
-                                               fprintf(stderr,"Can't malloc queued_entry\n");
+                                               fprintf(stderr, "Can't malloc queued_entry\n");
                                                exit(-1);
                                        }
                                        entry->next = NULL;
@@ -278,13 +274,11 @@ static void read_log_lines(struct log_device_t* devices)
                                                }
                                                perror("dlogutil read");
                                                exit(EXIT_FAILURE);
-                                       }
-                                       else if (!ret) {
+                                       } else if (!ret) {
                                                free(entry);
                                                fprintf(stderr, "read: Unexpected EOF!\n");
                                                exit(EXIT_FAILURE);
-                                       }
-                                       else if (entry->entry.len != ret - sizeof(struct logger_entry)) {
+                                       } else if (entry->entry.len != ret - sizeof(struct logger_entry)) {
                                                fprintf(stderr, "read: unexpected length. Expected %d, got %d\n",
                                                                entry->entry.len, ret - (int)sizeof(struct logger_entry));
                                                free(entry);
@@ -314,34 +308,33 @@ static void read_log_lines(struct log_device_t* devices)
                                sleep = true;
                                while (true) {
                                        chooseFirst(devices, &dev);
-                                       if (dev == NULL) {
+                                       if (dev == NULL)
                                                break;
-                                       }
-                                       if (g_tail_lines == 0 || queued_lines <= g_tail_lines) {
+
+                                       if (g_tail_lines == 0 || queued_lines <= g_tail_lines)
                                                printNextEntry(dev);
-                                       } else {
+                                       else
                                                skipNextEntry(dev);
-                                       }
+
                                        --queued_lines;
                                }
 
                                /* the caller requested to just dump the log and exit */
-                               if (g_nonblock) {
+                               if (g_nonblock)
                                        exit(0);
-                               }
                        } else {
                                /* print all that aren't the last in their list */
                                sleep = false;
                                while (g_tail_lines == 0 || queued_lines > g_tail_lines) {
                                        chooseFirst(devices, &dev);
-                                       if (dev == NULL || dev->queue->next == NULL) {
+                                       if (dev == NULL || dev->queue->next == NULL)
                                                break;
-                                       }
-                                       if (g_tail_lines == 0) {
+
+                                       if (g_tail_lines == 0)
                                                printNextEntry(dev);
-                                       } else {
+                                       else
                                                skipNextEntry(dev);
-                                       }
+
                                        --queued_lines;
                                }
                        }
@@ -378,10 +371,10 @@ static void setup_output()
        } else {
                struct stat statbuf;
 
-               g_outfd = open_logfile (g_output_filename);
+               g_outfd = open_logfile(g_output_filename);
 
                if (g_outfd < 0) {
-                       perror ("couldn't open output file");
+                       perror("couldn't open output file");
                        exit(-1);
                }
                if (fstat(g_outfd, &statbuf) == -1)
@@ -409,7 +402,7 @@ static int set_log_format(const char * formatString)
 
 static void show_help(const char *cmd)
 {
-       fprintf(stderr,"Usage: %s [options] [filterspecs]\n", cmd);
+       fprintf(stderr, "Usage: %s [options] [filterspecs]\n", cmd);
 
        fprintf(stderr, "options include:\n"
                        "  -s              Set default filter to silent.\n"
@@ -427,7 +420,7 @@ static void show_help(const char *cmd)
                        "                  ('main' (default), 'radio', 'system')");
 
 
-       fprintf(stderr,"\nfilterspecs are a series of \n"
+       fprintf(stderr, "\nfilterspecs are a series of \n"
                        "  <tag>[:priority]\n\n"
                        "where <tag> is a log component tag (or * for all) and priority is:\n"
                        "  V    Verbose\n"
@@ -563,24 +556,20 @@ int main(int argc, char **argv)
                size_t l;
 
                r = sd_journal_get_data(j, "PRIORITY", (const void **)&priority, &l);
-               if (r < 0) {
+               if (r < 0)
                        continue;
-               }
 
                r = sd_journal_get_data(j, "LOG_TAG", (const void **)&log_tag, &l);
-               if (r < 0) {
+               if (r < 0)
                        continue;
-               }
 
                r = sd_journal_get_data(j, "TID", (const void **)&tid, &l);
-               if (r < 0) {
+               if (r < 0)
                        continue;
-               }
 
                r = sd_journal_get_data(j, "MESSAGE", (const void **)&message, &l);
-               if (r < 0) {
+               if (r < 0)
                        continue;
-               }
 
                fprintf(stdout, "%c/%s(%5d): %s\n", pri_table[atoi(priority+9)], log_tag+8, atoi(tid+4), message+8);
        }
@@ -594,24 +583,20 @@ int main(int argc, char **argv)
                        fprintf(stderr, "Couldn't find journal");
                } else if (sd_journal_previous(j) > 0) {
                        r = sd_journal_get_data(j, "PRIORITY", (const void **)&priority, &l);
-                       if (r < 0) {
+                       if (r < 0)
                                continue;
-                       }
 
                        r = sd_journal_get_data(j, "LOG_TAG", (const void **)&log_tag, &l);
-                       if (r < 0) {
+                       if (r < 0)
                                continue;
-                       }
 
                        r = sd_journal_get_data(j, "TID", (const void **)&tid, &l);
-                       if (r < 0) {
+                       if (r < 0)
                                continue;
-                       }
 
                        r = sd_journal_get_data(j, "MESSAGE", (const void **)&message, &l);
-                       if (r < 0) {
+                       if (r < 0)
                                continue;
-                       }
 
                        fprintf(stdout, "%c/%s(%5d): %s\n", pri_table[atoi(priority+9)], log_tag+8, atoi(tid+4), message+8);
 
@@ -654,100 +639,97 @@ int main(int argc, char **argv)
 
                ret = getopt(argc, argv, "cdt:gsf:r:n:v:b:D");
 
-               if (ret < 0) {
+               if (ret < 0)
                        break;
-               }
-
-               switch(ret) {
-                       case 's':
-                               /* default to all silent */
-                               log_add_filter_rule(g_logformat, "*:s");
-                               break;
-
-                       case 'c':
-                               is_clear_log = 1;
-                               mode = O_WRONLY;
-                               break;
 
-                       case 'd':
-                               g_nonblock = true;
-                               break;
-
-                       case 't':
-                               g_nonblock = true;
-                               g_tail_lines = atoi(optarg);
-                               break;
-
-
-                       case 'g':
-                               getLogSize = 1;
-                               break;
-
-                       case 'b': {
-                                                 char *buf;
-                                                 if (asprintf(&buf, LOG_FILE_DIR "%s", optarg) == -1) {
-                                                         fprintf(stderr,"Can't malloc LOG_FILE_DIR\n");
-                                                         exit(-1);
-                                                 }
-
-                                                 dev = log_devices_new(buf);
-                                                 if (dev == NULL) {
-                                                         fprintf(stderr,"Can't add log device: %s\n", buf);
-                                                         exit(-1);
-                                                 }
-                                                 if (devices) {
-                                                         if (log_devices_add_to_tail(devices, dev)) {
-                                                                 fprintf(stderr, "Open log device %s failed\n", buf);
-                                                                 exit(-1);
-                                                         }
-                                                 } else {
-                                                         devices = dev;
-                                                         g_dev_count = 1;
-                                                 }
-                                         }
-                                         break;
+               switch (ret) {
+               case 's':
+                       /* default to all silent */
+                       log_add_filter_rule(g_logformat, "*:s");
+                       break;
 
-                       case 'f':
-                                         /* redirect output to a file */
-                                         g_output_filename = optarg;
+               case 'c':
+                       is_clear_log = 1;
+                       mode = O_WRONLY;
+                       break;
 
-                                         break;
+               case 'd':
+                       g_nonblock = true;
+                       break;
 
-                       case 'r':
-                                         if (!isdigit(optarg[0])) {
-                                                 fprintf(stderr,"Invalid parameter to -r\n");
-                                                 show_help(argv[0]);
-                                                 exit(-1);
-                                         }
-                                         g_log_rotate_size_kbytes = atoi(optarg);
-                                         break;
+               case 't':
+                       g_nonblock = true;
+                       g_tail_lines = atoi(optarg);
+                       break;
 
-                       case 'n':
-                                         if (!isdigit(optarg[0])) {
-                                                 fprintf(stderr,"Invalid parameter to -r\n");
-                                                 show_help(argv[0]);
-                                                 exit(-1);
-                                         }
+               case 'g':
+                       getLogSize = 1;
+                       break;
 
-                                         g_max_rotated_logs = atoi(optarg);
-                                         break;
+               case 'b': {
+                                 char *buf;
+                                 if (asprintf(&buf, LOG_FILE_DIR "%s", optarg) == -1) {
+                                         fprintf(stderr, "Can't malloc LOG_FILE_DIR\n");
+                                         exit(-1);
+                                 }
 
-                       case 'v':
-                                         err = set_log_format (optarg);
-                                         if (err < 0) {
-                                                 fprintf(stderr,"Invalid parameter to -v\n");
-                                                 show_help(argv[0]);
+                                 dev = log_devices_new(buf);
+                                 if (dev == NULL) {
+                                         fprintf(stderr, "Can't add log device: %s\n", buf);
+                                         exit(-1);
+                                 }
+                                 if (devices) {
+                                         if (log_devices_add_to_tail(devices, dev)) {
+                                                 fprintf(stderr, "Open log device %s failed\n", buf);
                                                  exit(-1);
                                          }
-
-                                         has_set_log_format = 1;
-                                         break;
-
-                       default:
-                                         fprintf(stderr,"Unrecognized Option\n");
-                                         show_help(argv[0]);
-                                         exit(-1);
-                                         break;
+                                 } else {
+                                         devices = dev;
+                                         g_dev_count = 1;
+                                 }
+                         }
+                         break;
+
+               case 'f':
+                         /* redirect output to a file */
+                         g_output_filename = optarg;
+                         break;
+
+               case 'r':
+                         if (!isdigit(optarg[0])) {
+                                 fprintf(stderr, "Invalid parameter to -r\n");
+                                 show_help(argv[0]);
+                                 exit(-1);
+                         }
+                         g_log_rotate_size_kbytes = atoi(optarg);
+                         break;
+
+               case 'n':
+                         if (!isdigit(optarg[0])) {
+                                 fprintf(stderr, "Invalid parameter to -r\n");
+                                 show_help(argv[0]);
+                                 exit(-1);
+                         }
+
+                         g_max_rotated_logs = atoi(optarg);
+                         break;
+
+               case 'v':
+                         err = set_log_format (optarg);
+                         if (err < 0) {
+                                 fprintf(stderr, "Invalid parameter to -v\n");
+                                 show_help(argv[0]);
+                                 exit(-1);
+                         }
+
+                         has_set_log_format = 1;
+                         break;
+
+               default:
+                         fprintf(stderr, "Unrecognized Option\n");
+                         show_help(argv[0]);
+                         exit(-1);
+                         break;
                }
        }
 
@@ -760,7 +742,7 @@ int main(int argc, char **argv)
        if (!devices) {
                devices = log_devices_new("/dev/"LOGGER_LOG_MAIN);
                if (devices == NULL) {
-                       fprintf(stderr,"Can't add log device: %s\n", LOGGER_LOG_MAIN);
+                       fprintf(stderr, "Can't add log device: %s\n", LOGGER_LOG_MAIN);
                        exit(-1);
                }
                g_dev_count = 1;
@@ -771,22 +753,21 @@ int main(int argc, char **argv)
                /* only add this if it's available */
                if (0 == access("/dev/"LOGGER_LOG_SYSTEM, accessmode)) {
                        if (log_devices_add_to_tail(devices, log_devices_new("/dev/"LOGGER_LOG_SYSTEM))) {
-                               fprintf(stderr,"Can't add log device: %s\n", LOGGER_LOG_SYSTEM);
+                               fprintf(stderr, "Can't add log device: %s\n", LOGGER_LOG_SYSTEM);
                                exit(-1);
                        }
                }
                if (0 == access("/dev/"LOGGER_LOG_APPS, accessmode)) {
                        if (log_devices_add_to_tail(devices, log_devices_new("/dev/"LOGGER_LOG_APPS))) {
-                               fprintf(stderr,"Can't add log device: %s\n", LOGGER_LOG_APPS);
+                               fprintf(stderr, "Can't add log device: %s\n", LOGGER_LOG_APPS);
                                exit(-1);
                        }
                }
 
        }
 
-       if (g_log_rotate_size_kbytes != 0 && g_output_filename == NULL)
-       {
-               fprintf(stderr,"-r requires -f as well\n");
+       if (g_log_rotate_size_kbytes != 0 && g_output_filename == NULL) {
+               fprintf(stderr, "-r requires -f as well\n");
                show_help(argv[0]);
                exit(-1);
        }
@@ -794,12 +775,12 @@ int main(int argc, char **argv)
        setup_output();
 
 
-       if (has_set_log_format == 0) {
+       if (has_set_log_format == 0)
                err = set_log_format("brief");
-       }
-       fprintf(stderr,"arc = %d, optind = %d ,Kb %d, rotate %d\n", argc, optind,g_log_rotate_size_kbytes,g_max_rotated_logs);
 
-       if(argc == optind ) {
+       fprintf(stderr, "arc = %d, optind = %d ,Kb %d, rotate %d\n", argc, optind, g_log_rotate_size_kbytes, g_max_rotated_logs);
+
+       if (argc == optind) {
                /* Add from environment variable
                char *env_tags_orig = getenv("DLOG_TAGS");*/
                log_add_filter_string(g_logformat, "*:d");
@@ -809,7 +790,7 @@ int main(int argc, char **argv)
                        err = log_add_filter_string(g_logformat, argv[i]);
 
                        if (err < 0) {
-                               fprintf (stderr, "Invalid filter expression '%s'\n", argv[i]);
+                               fprintf(stderr, "Invalid filter expression '%s'\n", argv[i]);
                                show_help(argv[0]);
                                exit(-1);
                        }
@@ -857,13 +838,11 @@ int main(int argc, char **argv)
                dev = dev->next;
        }
 
-       if (getLogSize) {
+       if (getLogSize)
                return 0;
-       }
 
-       if (is_clear_log) {
+       if (is_clear_log)
                return 0;
-       }
 
        read_log_lines(devices);
 
index 9215b4c..9a8a696 100755 (executable)
@@ -53,9 +53,8 @@ static FilterInfo * filterinfo_new(const char *tag, log_priority pri)
 
 static void filterinfo_free(FilterInfo *p_info)
 {
-       if (p_info == NULL) {
+       if (p_info == NULL)
                return;
-       }
 
        free(p_info->mTag);
        p_info->mTag = NULL;
@@ -65,18 +64,17 @@ static void filterinfo_free(FilterInfo *p_info)
  * Note: also accepts 0-9 priorities
  * returns DLOG_UNKNOWN if the character is unrecognized
  */
-static log_priority filter_char_to_pri (char c)
+static log_priority filter_char_to_pri(char c)
 {
        log_priority pri;
 
        c = tolower(c);
 
        if (c >= '0' && c <= '9') {
-               if (c >= ('0'+DLOG_SILENT)) {
+               if (c >= ('0'+DLOG_SILENT))
                        pri = DLOG_VERBOSE;
-               } else {
+               else
                        pri = (log_priority)(c - '0');
-               }
        } else if (c == 'v') {
                pri = DLOG_VERBOSE;
        } else if (c == 'd') {
@@ -128,15 +126,12 @@ static log_priority filter_pri_for_tag(log_format *p_format, const char *tag)
 {
        FilterInfo *p_curFilter;
 
-       for (p_curFilter = p_format->filters; p_curFilter != NULL; p_curFilter = p_curFilter->p_next )
-       {
-               if (0 == strcmp(tag, p_curFilter->mTag))
-               {
-                       if (p_curFilter->mPri == DLOG_DEFAULT) {
+       for (p_curFilter = p_format->filters; p_curFilter != NULL; p_curFilter = p_curFilter->p_next) {
+               if (0 == strcmp(tag, p_curFilter->mTag)) {
+                       if (p_curFilter->mPri == DLOG_DEFAULT)
                                return p_format->global_pri;
-                       } else {
+                       else
                                return p_curFilter->mPri;
-                       }
                }
        }
        return p_format->global_pri;
@@ -149,9 +144,9 @@ void dump_filters(log_format *p_format)
 
        for (p_fi = p_format->filters ; p_fi != NULL ; p_fi = p_fi->p_next) {
                char cPri = filter_pri_to_char(p_fi->mPri);
-               if (p_fi->mPri == DLOG_DEFAULT) {
+               if (p_fi->mPri == DLOG_DEFAULT)
                        cPri = filter_pri_to_char(p_format->global_pri);
-               }
+
                fprintf(stderr, "%s:%c\n", p_fi->mTag, cPri);
        }
 
@@ -163,7 +158,7 @@ void dump_filters(log_format *p_format)
  * returns 1 if this log line should be printed based on its priority
  * and tag, and 0 if it should not
  */
-int log_should_print_line (log_format *p_format, const char *tag, log_priority pri)
+int log_should_print_line(log_format *p_format, const char *tag, log_priority pri)
 {
        return pri >= filter_pri_for_tag(p_format, tag);
 }
@@ -197,9 +192,9 @@ void log_format_free(log_format *p_format)
        free(p_format);
 }
 
-void log_set_print_format(log_format *p_format,log_print_format format)
+void log_set_print_format(log_format *p_format, log_print_format format)
 {
-       p_format->format=format;
+       p_format->format = format;
 }
 
 /**
@@ -248,35 +243,31 @@ int log_add_filter_rule(log_format *p_format,
 
        tagNameLength = strcspn(filterExpression, ":");
 
-       if (tagNameLength == 0) {
+       if (tagNameLength == 0)
                goto error;
-       }
 
-       if(filterExpression[tagNameLength] == ':') {
+       if (filterExpression[tagNameLength] == ':') {
                pri = filter_char_to_pri(filterExpression[tagNameLength+1]);
 
-               if (pri == DLOG_UNKNOWN) {
+               if (pri == DLOG_UNKNOWN)
                        goto error;
-               }
        }
 
-       if(0 == strncmp("*", filterExpression, tagNameLength)) {
+       if (0 == strncmp("*", filterExpression, tagNameLength)) {
                /* This filter expression refers to the global filter
                 * The default level for this is DEBUG if the priority
                 * is unspecified
                 */
-               if (pri == DLOG_DEFAULT) {
+               if (pri == DLOG_DEFAULT)
                        pri = DLOG_DEBUG;
-               }
 
                p_format->global_pri = pri;
        } else {
                /* for filter expressions that don't refer to the global
                 * filter, the default is verbose if the priority is unspecified
                 */
-               if (pri == DLOG_DEFAULT) {
+               if (pri == DLOG_DEFAULT)
                        pri = DLOG_VERBOSE;
-               }
 
                char *tagName;
                tagName = strndup(filterExpression, tagNameLength);
@@ -306,26 +297,25 @@ error:
 int log_add_filter_string(log_format *p_format,
                const char *filterString)
 {
-       char *filterStringCopy = strdup (filterString);
+       char *filterStringCopy = strdup(filterString);
        char *p_cur = filterStringCopy;
        char *p_ret;
        int err;
 
        while (NULL != (p_ret = strsep(&p_cur, " \t,"))) {
                /* ignore whitespace-only entries */
-               if(p_ret[0] != '\0') {
+               if (p_ret[0] != '\0') {
                        err = log_add_filter_rule(p_format, p_ret);
 
-                       if (err < 0) {
+                       if (err < 0)
                                goto error;
-                       }
                }
        }
 
-       free (filterStringCopy);
+       free(filterStringCopy);
        return 0;
 error:
-       free (filterStringCopy);
+       free(filterStringCopy);
        return -1;
 }
 
@@ -403,7 +393,7 @@ int log_process_log_buffer(struct logger_entry *buf, log_entry *entry)
  * If return value != defaultBuffer, caller must call free()
  * Returns NULL on malloc error
  */
-char *log_format_log_line (
+char *log_format_log_line(
                log_format *p_format,
                char *defaultBuffer,
                size_t defaultBufferSize,
@@ -486,7 +476,7 @@ char *log_format_log_line (
                prefixLen = snprintf(prefixBuf, sizeof(prefixBuf),
                                "%s.%03ld%s %5d %5d %c %-8s: ", timeBuf,
                                entry->tv_nsec / 1000000, tzBuf, (int)entry->pid,
-                               (int)entry->tid, priChar, entry->tag);
+                               (int)entry->tid, priChar, entry->tag);
                strcpy(suffixBuf, "\n");
                suffixLen = 1;
                break;
@@ -513,9 +503,9 @@ char *log_format_log_line (
         * possibly causing heap corruption.  To avoid this we double check and
         * set the length at the maximum (size minus null byte)
         */
-       if(prefixLen >= sizeof(prefixBuf))
+       if (prefixLen >= sizeof(prefixBuf))
                prefixLen = sizeof(prefixBuf) - 1;
-       if(suffixLen >= sizeof(suffixBuf))
+       if (suffixLen >= sizeof(suffixBuf))
                suffixLen = sizeof(suffixBuf) - 1;
 
        /* the following code is tragically unreadable */
@@ -552,9 +542,8 @@ char *log_format_log_line (
        } else {
                ret = (char *)malloc(bufferSize);
 
-               if (ret == NULL) {
+               if (ret == NULL)
                        return ret;
-               }
        }
 
        ret[0] = '\0';       /* to start strcat off */
@@ -593,9 +582,8 @@ char *log_format_log_line (
                }
        }
 
-       if (p_outLength != NULL) {
+       if (p_outLength != NULL)
                *p_outLength = p - ret;
-       }
 
        return ret;
 }
@@ -639,9 +627,8 @@ int log_print_log_line(
        }
 
 done:
-       if (outBuffer != defaultBuffer) {
+       if (outBuffer != defaultBuffer)
                free(outBuffer);
-       }
 
        return ret;
 }
@@ -660,41 +647,41 @@ void logprint_run_tests()
 
        tag = "random";
 
-       log_add_filter_rule(p_format,"*:i");
+       log_add_filter_rule(p_format, "*:i");
 
-       assert (DLOG_INFO == filter_pri_for_tag(p_format, "random"));
+       assert(DLOG_INFO == filter_pri_for_tag(p_format, "random"));
        assert(log_should_print_line(p_format, tag, DLOG_DEBUG) == 0);
        log_add_filter_rule(p_format, "*");
-       assert (DLOG_DEBUG == filter_pri_for_tag(p_format, "random"));
+       assert(DLOG_DEBUG == filter_pri_for_tag(p_format, "random"));
        assert(log_should_print_line(p_format, tag, DLOG_DEBUG) > 0);
        log_add_filter_rule(p_format, "*:v");
-       assert (DLOG_VERBOSE == filter_pri_for_tag(p_format, "random"));
+       assert(DLOG_VERBOSE == filter_pri_for_tag(p_format, "random"));
        assert(log_should_print_line(p_format, tag, DLOG_DEBUG) > 0);
        log_add_filter_rule(p_format, "*:i");
-       assert (DLOG_INFO == filter_pri_for_tag(p_format, "random"));
+       assert(DLOG_INFO == filter_pri_for_tag(p_format, "random"));
        assert(log_should_print_line(p_format, tag, DLOG_DEBUG) == 0);
 
        log_add_filter_rule(p_format, "random");
-       assert (DLOG_VERBOSE == filter_pri_for_tag(p_format, "random"));
+       assert(DLOG_VERBOSE == filter_pri_for_tag(p_format, "random"));
        assert(log_should_print_line(p_format, tag, DLOG_DEBUG) > 0);
        log_add_filter_rule(p_format, "random:v");
-       assert (DLOG_VERBOSE == filter_pri_for_tag(p_format, "random"));
+       assert(DLOG_VERBOSE == filter_pri_for_tag(p_format, "random"));
        assert(log_should_print_line(p_format, tag, DLOG_DEBUG) > 0);
        log_add_filter_rule(p_format, "random:d");
-       assert (DLOG_DEBUG == filter_pri_for_tag(p_format, "random"));
+       assert(DLOG_DEBUG == filter_pri_for_tag(p_format, "random"));
        assert(log_should_print_line(p_format, tag, DLOG_DEBUG) > 0);
        log_add_filter_rule(p_format, "random:w");
-       assert (DLOG_WARN == filter_pri_for_tag(p_format, "random"));
+       assert(DLOG_WARN == filter_pri_for_tag(p_format, "random"));
        assert(log_should_print_line(p_format, tag, DLOG_DEBUG) == 0);
 
        log_add_filter_rule(p_format, "crap:*");
-       assert (DLOG_VERBOSE== filter_pri_for_tag(p_format, "crap"));
+       assert(DLOG_VERBOSE == filter_pri_for_tag(p_format, "crap"));
        assert(log_should_print_line(p_format, "crap", DLOG_VERBOSE) > 0);
 
        /* invalid expression */
        err = log_add_filter_rule(p_format, "random:z");
-       assert (err < 0);
-       assert (DLOG_WARN == filter_pri_for_tag(p_format, "random"));
+       assert(err < 0);
+       assert(DLOG_WARN == filter_pri_for_tag(p_format, "random"));
        assert(log_should_print_line(p_format, tag, DLOG_DEBUG) == 0);
 
        /* Issue #550946 */