Apply Tizen coding rule 43/79843/3 accepted/tizen/common/20160714.152718 accepted/tizen/ivi/20160714.053925 accepted/tizen/mobile/20160714.053906 accepted/tizen/tv/20160714.053909 accepted/tizen/wearable/20160714.053917 submit/tizen/20160714.000744
authorKichan Kwon <k_c.kwon@samsung.com>
Wed, 13 Jul 2016 07:53:10 +0000 (16:53 +0900)
committerKunhoon Baik <knhoon.baik@samsung.com>
Wed, 13 Jul 2016 23:58:30 +0000 (08:58 +0900)
Change-Id: I1997e9d87fbb870e4b666f1f52756d585d6f5fc2
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
18 files changed:
include/dlog-internal.h
include/logcommon.h
include/logconfig.h
include/logpipe.h
include/logprint.h
include/queued_entry.h
src/libdlog/log_pipe.c
src/logctrl/logctrl.c
src/logctrl/logctrl_doc.h
src/logger/logger.c
src/logger/logger_pipe.c
src/logutil/logutil_doc.h
src/logutil/logutil_kmsg_logger.c
src/logutil/logutil_pipe.c
src/shared/logconfig.c
src/shared/logprint.c
src/shared/queued_entry.c
tests/test_libdlog.c

index 7f7456a..f7f0ff7 100755 (executable)
@@ -359,7 +359,7 @@ static inline int __dlog_no_print(const char *fmt __attribute__((unused)), ...)
  * @internal
  * @brief     Send log.
  * @details   Use LOG(), SLOG(), RLOG() family
- *            not to use __dlog_print() directly
+ *                       not to use __dlog_print() directly
  * @remarks   Must not use this API directly. use macros instead.
  * @param[in] log_id log device id
  * @param[in] prio priority
@@ -383,7 +383,7 @@ int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ..
  * @internal
  * @brief     Send log with va_list.
  * @details   Use LOG_VA(), SLOG_VA(), RLOG_VA() family
-              not to use __dlog_vprint() directly
*                       not to use __dlog_vprint() directly
  * @remarks   Must not use this API directly. use macros instead.
  * @param[in] log_id log device id
  * @param[in] prio priority
index 21d66e3..533fb78 100644 (file)
@@ -42,9 +42,9 @@
 
 #define gettid() syscall(SYS_gettid)
 
-char * log_name_by_id (log_id_t id);
-log_id_t log_id_by_name (const char *name);
+char * log_name_by_id(log_id_t id);
+log_id_t log_id_by_name(const char *name);
 
-void syslog_critical_failure (const char * message);
+void syslog_critical_failure(const char * message);
 int recv_file_descriptor(int socket);
 #endif /* _LOGCOMMON_H */
index 4533630..305ab06 100755 (executable)
@@ -35,19 +35,19 @@ struct log_config {
        struct log_conf_entry *last;
 };
 
-const char * get_config_filename (config_type type);
+const char *get_config_filename(config_type type);
 
-int log_config_set (struct log_config* config, const char* key, const char* value);
-const char* log_config_get (struct log_config* config, const char* key);
-int log_config_read (struct log_config* config);
-int log_config_read_file (struct log_config* config, char const* filename);
+int log_config_set(struct log_config* config, const char* key, const char* value);
+const char* log_config_get(struct log_config* config, const char* key);
+int log_config_read(struct log_config* config);
+int log_config_read_file(struct log_config* config, char const* filename);
 int log_config_write(struct log_config* config, char const* filename);
-void log_config_free (struct log_config* config);
+void log_config_free(struct log_config* config);
 
-void log_config_print_out (struct log_config* config);
-int log_config_print_key (struct log_config* config, const char* key);
-void log_config_push (struct log_config* config, const char* key, const char* value);
-int log_config_remove (struct log_config* config, const char* key);
-int log_config_foreach (struct log_config* config, int (*func)(const char* key, const char* value));
+void log_config_print_out(struct log_config* config);
+int log_config_print_key(struct log_config* config, const char* key);
+void log_config_push(struct log_config* config, const char* key, const char* value);
+int log_config_remove(struct log_config* config, const char* key);
+int log_config_foreach(struct log_config* config, int (*func)(const char* key, const char* value));
 
 #endif /* _LOGCONFIG_H_ */
index 3c16418..990d15d 100644 (file)
@@ -25,7 +25,7 @@
 #define DLOG_CTRL_REQ_PIPE {sizeof(struct dlog_control_msg), DLOG_REQ_PIPE, 0}
 
 enum {
-       DLOG_REQ_PIPE=1,
+       DLOG_REQ_PIPE = 1,
        DLOG_REQ_CLEAR,
        DLOG_REQ_HANDLE_LOGUTIL,
        DLOG_REQ_MAX
index fbf97da..b04b46a 100755 (executable)
@@ -31,37 +31,36 @@ extern "C" {
 #endif
 
 typedef enum {
-    FORMAT_OFF = 0,
-    FORMAT_BRIEF,
-    FORMAT_PROCESS,
-    FORMAT_TAG,
-    FORMAT_THREAD,
-    FORMAT_RAW,
-    FORMAT_TIME,
-    FORMAT_THREADTIME,
-    FORMAT_KERNELTIME,
-    FORMAT_LONG,
+       FORMAT_OFF = 0,
+       FORMAT_BRIEF,
+       FORMAT_PROCESS,
+       FORMAT_TAG,
+       FORMAT_THREAD,
+       FORMAT_RAW,
+       FORMAT_TIME,
+       FORMAT_THREADTIME,
+       FORMAT_KERNELTIME,
+       FORMAT_LONG,
 } log_print_format;
 
 typedef struct log_format_t log_format;
 
 typedef struct log_entry_t {
-    time_t tv_sec;
-    long tv_nsec;
-    log_priority priority;
-    pid_t pid;
-    pthread_t tid;
-    char * tag;
-    size_t messageLen;
-    char * message;
+       time_t tv_sec;
+       long tv_nsec;
+       log_priority priority;
+       pid_t pid;
+       pthread_t tid;
+       char * tag;
+       size_t messageLen;
+       char * message;
 } log_entry;
 
 log_format *log_format_new();
 
 void log_format_free(log_format *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);
 
 /**
  * Returns a deep copy of the passed object.
@@ -83,9 +82,7 @@ log_print_format log_format_from_string(const char *s);
  *
  */
 
-int log_add_filter_rule(log_format *p_format,
-        const char *filterExpression);
-
+int log_add_filter_rule(log_format *p_format, const char *filterExpression);
 
 /**
  * filterString: a whitespace-separated set of filter expressions
@@ -97,17 +94,14 @@ int log_add_filter_rule(log_format *p_format,
  *
  */
 
-int log_add_filter_string(log_format *p_format,
-        const char *filterString);
-
+int log_add_filter_string(log_format *p_format, const char *filterString);
 
 /**
  * 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);
-
+               log_format *p_format, const char *tag, log_priority pri);
 
 /**
  * Splits a wire-format buffer into an log_entry
@@ -116,8 +110,7 @@ int log_should_print_line(
  * Returns 0 on success and -1 on invalid wire format (entry will be
  * in unspecified state)
  */
-int log_process_log_buffer(struct logger_entry *entry_raw,
-                                 log_entry *entry);
+int log_process_log_buffer(struct logger_entry *entry_raw, log_entry *entry);
 
 /**
  * Formats a log message into a buffer
@@ -128,12 +121,11 @@ int log_process_log_buffer(struct logger_entry *entry_raw,
  */
 
 char *log_format_log_line(
-    log_format *p_format,
-    char *defaultBuffer,
-    size_t defaultBufferSize,
-    const log_entry *p_line,
-    size_t *p_outLength);
-
+               log_format *p_format,
+               char *defaultBuffer,
+               size_t defaultBufferSize,
+               const log_entry *p_line,
+               size_t *p_outLength);
 
 /**
  * Either print or do not print log line, based on filter
@@ -142,9 +134,9 @@ char *log_format_log_line(
  *
  */
 int log_print_log_line(
-    log_format *p_format,
-    int fd,
-    const log_entry *entry);
+               log_format *p_format,
+               int fd,
+               const log_entry *entry);
 
 /**
  * logprint test furction
index 292efb3..6d20e94 100644 (file)
@@ -54,13 +54,13 @@ int cmp(struct queued_entry_t* a, struct queued_entry_t* b);
 #include <dlog_ioctl.h>
 
 struct logger_entry {
-    uint16_t    len;    /* length of the payload */
-    uint16_t    padding;/* padding for alignment */
-    int32_t     pid;    /* generating process's pid */
-    int32_t     tid;    /* generating process's tid */
-    int32_t     sec;    /* seconds since Epoch */
-    int32_t     nsec;   /* nanoseconds */
-    char        msg[];  /* the entry's payload */
+       uint16_t    len;    /* length of the payload */
+       uint16_t    padding;/* padding for alignment */
+       int32_t     pid;    /* generating process's pid */
+       int32_t     tid;    /* generating process's tid */
+       int32_t     sec;    /* seconds since Epoch */
+       int32_t     nsec;   /* nanoseconds */
+       char        msg[];  /* the entry's payload */
 };
 
 struct queued_entry_t {
index 360fd2c..6d418e2 100644 (file)
@@ -117,7 +117,7 @@ static int __write_to_log_pipe(log_id_t log_id, log_priority prio, const char *t
 void __dlog_init_backend()
 {
        const char * conf_val;
-       char conf_key [MAX_CONF_KEY_LEN];
+       char conf_key[MAX_CONF_KEY_LEN];
        struct log_config conf;
        int i;
 
index 3c622a2..b59fa3a 100644 (file)
@@ -20,7 +20,7 @@ int validate(struct options o)
        int valid = 1;
 
        if (!o.has_key && !o.print_all && !o.help) {
-               printf ("Having either -i, -p, or -k is mandatory!\n");
+               printf("Having either -i, -p, or -k is mandatory!\n");
                valid = 0;
        }
        if (o.has_key && !(o.should_get || o.should_set || o.should_clear)) {
@@ -28,7 +28,7 @@ int validate(struct options o)
                valid = 0;
        }
        if ((o.has_key + o.print_all + o.help) > 1) {
-               printf ("-i, -p and -k preclude each other!\n");
+               printf("-i, -p and -k preclude each other!\n");
                valid = 0;
        }
        if (o.should_set + o.should_get + o.should_clear > 1) {
index 1d5eb7a..3ca9044 100644 (file)
@@ -1,6 +1,6 @@
-void print_help ()
+void print_help()
 {
-       printf ("dlogctrl - provides control over dlog configuration. Options:\n"
+       printf("dlogctrl - provides control over dlog configuration. Options:\n"
                "\t-p        Precludes -kh. Prints all entries in the config.\n"
                "\t-k key    Precludes -ph and requires one of -gs.  Specifies a config key.\n"
                "\t-g        Requires -k, precludes -cs. Gets and prints the value of the entry assigned to the key.\n"
@@ -11,9 +11,9 @@ void print_help ()
        );
 }
 
-void print_extended_help ()
+void print_extended_help()
 {
-       printf ("Important entries:\n"
+       printf("Important entries:\n"
                "\tplog: enable platform logging, ie. whether any logging happens at all. Values are 0 or 1.\n"
                "\tlimiter: enable log limiting. Values are 0 or 1.\n\n"
                "Limiter rules:\n"
index 03317a5..b037a69 100755 (executable)
@@ -906,9 +906,8 @@ 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 71ee2cb..f462ce5 100644 (file)
@@ -133,7 +133,7 @@ struct reader {
        struct reader*     next;
        struct reader*     prev;
        int                partial_log_size;
-       char               partial_log [LOG_MAX_SIZE];
+       char               partial_log[LOG_MAX_SIZE];
 };
 
 struct log_buffer {
@@ -174,7 +174,7 @@ struct logger {
        log_format*         default_format;
 };
 
-static int parse_permissions (const char * str)
+static int parse_permissions(const char * str)
 {
        int ret, parsed;
        char * parse_safety;
@@ -182,8 +182,8 @@ static int parse_permissions (const char * str)
        if (!str)
                return S_IWUSR | S_IWGRP | S_IWOTH; // 0222: everyone can write
 
-       parsed = strtol (str, & parse_safety, 8); // note, rights are octal
-       if (parse_safety != (str + strlen (str)))
+       parsed = strtol(str, & parse_safety, 8); // note, rights are octal
+       if (parse_safety != (str + strlen(str)))
                return 0;
 
        ret = 0;
@@ -205,7 +205,7 @@ static int parse_permissions (const char * str)
        return ret;
 }
 
-static int change_owners (const char * file, const char * user, const char * group)
+static int change_owners(const char * file, const char * user, const char * group)
 {
        uid_t uid = -1;
        gid_t gid = -1;
@@ -213,21 +213,21 @@ static int change_owners (const char * file, const char * user, const char * gro
        struct group  * grp = NULL;
 
        if (user)
-               pwd = getpwnam (user);
+               pwd = getpwnam(user);
 
        if (pwd)
                uid = pwd->pw_uid;
 
        if (group)
-               grp = getgrnam (group);
+               grp = getgrnam(group);
 
        if (grp)
                gid = grp->gr_gid;
 
-       return! chown (file, uid, gid); // ideally would be fchown, but that is broken
+       return !chown(file, uid, gid); // ideally would be fchown, but that is broken
 }
 
-static int listen_fd_create (const char* path, int permissions)
+static int listen_fd_create(const char* path, int permissions)
 {
        struct sockaddr_un server_addr;
        int sd;
@@ -245,7 +245,7 @@ static int listen_fd_create (const char* path, int permissions)
                goto failure;
 
        if (permissions)
-               if (chmod (path, permissions) < 0) // ideally, fchmod would be used, but that does not work
+               if (chmod(path, permissions) < 0) // ideally, fchmod would be used, but that does not work
                        goto failure;
 
        if (listen(sd, MAX_CONNECTION_Q) < 0)
@@ -375,17 +375,17 @@ static void buffer_append(const struct logger_entry* entry, struct log_buffer* b
        ++b->lines;
 }
 
-static void add_misc_file_info (int fd)
+static void add_misc_file_info(int fd)
 {
        const int32_t version = PIPE_FILE_FORMAT_VERSION;
        const int32_t endian = 0x12345678;
        int r;
 
-       r = write (fd, &endian, 4);
+       r = write(fd, &endian, 4);
        if (r <= 0)
                return;
 
-       r = write (fd, &version, 4);
+       r = write(fd, &version, 4);
        if (r <= 0)
                return;
 }
@@ -394,7 +394,7 @@ static int print_out_logs(struct reader* reader, struct log_buffer* buffer)
 {
        int r, ret = 0;
        struct logger_entry* ple;
-       char tmp [LOG_MAX_SIZE];
+       char tmp[LOG_MAX_SIZE];
        int priority;
        char * tag;
        struct epoll_event ev = { .events = EPOLLOUT, .data.fd = reader->file.fd };
@@ -402,17 +402,17 @@ static int print_out_logs(struct reader* reader, struct log_buffer* buffer)
        int from = reader->current;
        int is_file = 0;
 
-       epoll_fd = epoll_create1 (0);
-       r = epoll_ctl (epoll_fd, EPOLL_CTL_ADD, reader->file.fd, &ev);
+       epoll_fd = epoll_create1(0);
+       r = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, reader->file.fd, &ev);
        if (r == -1 && errno == EPERM)
                is_file = 1;
 
        if (reader->partial_log_size) {
-               if (!is_file && epoll_wait (epoll_fd, &ev, 1, 0) < 1)
+               if (!is_file && epoll_wait(epoll_fd, &ev, 1, 0) < 1)
                        goto cleanup;
 
                do {
-                       r = write (reader->file.fd, reader->partial_log, reader->partial_log_size);
+                       r = write(reader->file.fd, reader->partial_log, reader->partial_log_size);
                } while (r < 0 && errno == EINTR);
 
                if (r <= 0)
@@ -420,7 +420,7 @@ static int print_out_logs(struct reader* reader, struct log_buffer* buffer)
 
                if (r < reader->partial_log_size) {
                        reader->partial_log_size -= r;
-                       memmove (reader->partial_log, reader->partial_log + r, reader->partial_log_size);
+                       memmove(reader->partial_log, reader->partial_log + r, reader->partial_log_size);
                        goto cleanup;
                }
 
@@ -446,11 +446,11 @@ static int print_out_logs(struct reader* reader, struct log_buffer* buffer)
                if (!log_should_print_line(reader->file.format, tag, priority))
                        continue;
 
-               if (!is_file && epoll_wait (epoll_fd, &ev, 1, 0) < 1)
+               if (!is_file && epoll_wait(epoll_fd, &ev, 1, 0) < 1)
                        goto cleanup;
 
                do {
-                       r = write (reader->file.fd, ple, ple->len);
+                       r = write(reader->file.fd, ple, ple->len);
                } while (r < 0 && errno == EINTR);
 
                if (r < 0) {
@@ -463,11 +463,11 @@ static int print_out_logs(struct reader* reader, struct log_buffer* buffer)
 
                if (r < ple->len) {
                        reader->partial_log_size = ple->len - r;
-                       memcpy (reader->partial_log, ple + r, reader->partial_log_size);
+                       memcpy(reader->partial_log, ple + r, reader->partial_log_size);
                        goto cleanup;
                } else if ((reader->file.rotate_size_kbytes > 0) && ((reader->file.size / 1024) >= reader->file.rotate_size_kbytes)) {
                        rotate_logs(&reader->file);
-                       add_misc_file_info (reader->file.fd);
+                       add_misc_file_info(reader->file.fd);
                }
        }
 
@@ -477,7 +477,7 @@ static int print_out_logs(struct reader* reader, struct log_buffer* buffer)
                ret = -1;
 
 cleanup:
-       close (epoll_fd);
+       close(epoll_fd);
        reader->current = from;
        return ret;
 }
@@ -640,7 +640,7 @@ static int parse_command_line(const char* cmdl, struct logger* server, struct wr
        }
 
        if (reader->file.path != NULL) {
-               int file_already_exists = !access (reader->file.path, F_OK);
+               int file_already_exists = !access(reader->file.path, F_OK);
                reader->file.fd = open(reader->file.path, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
                if (!file_already_exists)
                        add_misc_file_info(reader->file.fd);
@@ -898,7 +898,7 @@ static void service_all_readers(struct logger* server, int time_elapsed)
        }
 }
 
-static struct logger* logger_create (struct log_config *conf)
+static struct logger* logger_create(struct log_config *conf)
 {
        struct logger* l = calloc(1, sizeof(struct logger));
        int i = 0;
@@ -929,24 +929,24 @@ static struct logger* logger_create (struct log_config *conf)
                conf_value = log_config_get(conf, conf_key);
                if (!conf_value)
                        goto err5;
-               strncpy (l->socket_ctl[i].path, conf_value, sizeof(l->socket_ctl[i].path));
+               strncpy(l->socket_ctl[i].path, conf_value, sizeof(l->socket_ctl[i].path));
 
                snprintf(conf_key, MAX_CONF_KEY_LEN, "%s_ctl_sock_rights", log_name_by_id(i));
                conf_value = log_config_get(conf, conf_key);
 
-               permissions = parse_permissions (conf_value);
+               permissions = parse_permissions(conf_value);
                if (!permissions)
                        goto err5;
 
                if ((l->socket_ctl[i].fd = listen_fd_create(l->socket_ctl[i].path, permissions)) < 0)
                        goto err5;
 
-               snprintf (conf_key, MAX_CONF_KEY_LEN, "%s_ctl_sock_owner", log_name_by_id (i));
-               conf_value  = log_config_get (conf, conf_key);
-               snprintf (conf_key, MAX_CONF_KEY_LEN, "%s_ctl_sock_group", log_name_by_id (i));
-               conf_value2 = log_config_get (conf, conf_key);
+               snprintf(conf_key, MAX_CONF_KEY_LEN, "%s_ctl_sock_owner", log_name_by_id(i));
+               conf_value = log_config_get(conf, conf_key);
+               snprintf(conf_key, MAX_CONF_KEY_LEN, "%s_ctl_sock_group", log_name_by_id(i));
+               conf_value2 = log_config_get(conf, conf_key);
 
-               if (!change_owners (l->socket_ctl[i].path, conf_value, conf_value2))
+               if (!change_owners(l->socket_ctl[i].path, conf_value, conf_value2))
                        goto err6;
 
                l->socket_ctl[i]._entity.type = ENTITY_CONTROL;
@@ -954,30 +954,30 @@ static struct logger* logger_create (struct log_config *conf)
                l->socket_ctl[i].event.events = EPOLLIN;
                l->socket_ctl[i].is_control = 1;
 
-               add_fd_loop (l->epollfd, l->socket_ctl[i].fd, &l->socket_ctl[i].event);
+               add_fd_loop(l->epollfd, l->socket_ctl[i].fd, &l->socket_ctl[i].event);
 
-               snprintf (conf_key, MAX_CONF_KEY_LEN, "%s_write_sock", log_name_by_id (i));
-               conf_value = log_config_get (conf, conf_key);
+               snprintf(conf_key, MAX_CONF_KEY_LEN, "%s_write_sock", log_name_by_id(i));
+               conf_value = log_config_get(conf, conf_key);
                if (!conf_value)
                        goto err6;
                strncpy(l->socket_wr[i].path, conf_value, sizeof(l->socket_wr[i].path));
 
-               snprintf (conf_key, MAX_CONF_KEY_LEN, "%s_write_sock_rights", log_name_by_id (i));
-               conf_value = log_config_get (conf, conf_key);
+               snprintf(conf_key, MAX_CONF_KEY_LEN, "%s_write_sock_rights", log_name_by_id(i));
+               conf_value = log_config_get(conf, conf_key);
 
-               permissions = parse_permissions (conf_value);
+               permissions = parse_permissions(conf_value);
                if (!permissions)
                        goto err6;
 
                if ((l->socket_wr[i].fd = listen_fd_create(l->socket_wr[i].path, permissions)) < 0)
                        goto err6;
 
-               snprintf (conf_key, MAX_CONF_KEY_LEN, "%s_write_sock_owner", log_name_by_id (i));
-               conf_value  = log_config_get (conf, conf_key);
-               snprintf (conf_key, MAX_CONF_KEY_LEN, "%s_write_sock_group", log_name_by_id (i));
-               conf_value2 = log_config_get (conf, conf_key);
+               snprintf(conf_key, MAX_CONF_KEY_LEN, "%s_write_sock_owner", log_name_by_id(i));
+               conf_value = log_config_get(conf, conf_key);
+               snprintf(conf_key, MAX_CONF_KEY_LEN, "%s_write_sock_group", log_name_by_id(i));
+               conf_value2 = log_config_get(conf, conf_key);
 
-               if (!change_owners (l->socket_ctl[i].path, conf_value, conf_value2))
+               if (!change_owners(l->socket_ctl[i].path, conf_value, conf_value2))
                        goto err7;
 
                l->socket_wr[i]._entity.type = ENTITY_CONTROL;
@@ -985,14 +985,14 @@ static struct logger* logger_create (struct log_config *conf)
                l->socket_wr[i].event.events = EPOLLIN;
                l->socket_wr[i].is_control = 0;
 
-               add_fd_loop (l->epollfd, l->socket_wr[i].fd, &l->socket_wr[i].event);
+               add_fd_loop(l->epollfd, l->socket_wr[i].fd, &l->socket_wr[i].event);
 
-               snprintf (conf_key, MAX_CONF_KEY_LEN, "%s_size", log_name_by_id(i));
-               conf_value = log_config_get (conf, conf_key);
+               snprintf(conf_key, MAX_CONF_KEY_LEN, "%s_size", log_name_by_id(i));
+               conf_value = log_config_get(conf, conf_key);
                if (!conf_value)
                        goto err7;
 
-               size = atoi (conf_value);
+               size = atoi(conf_value);
 
                if (!(l->buffers[i] = buffer_create(i, size)))
                        goto err7;
@@ -1004,22 +1004,22 @@ static struct logger* logger_create (struct log_config *conf)
        return l;
 
 err7:
-       close (l->socket_wr[i].fd);
+       close(l->socket_wr[i].fd);
 err6:
-       close (l->socket_ctl[i].fd);
+       close(l->socket_ctl[i].fd);
 err5:
        while (i--) {
-               close (l->socket_ctl[i].fd);
-               close (l->socket_wr[i].fd);
-               buffer_free (&l->buffers[i]);
+               close(l->socket_ctl[i].fd);
+               close(l->socket_wr[i].fd);
+               buffer_free(&l->buffers[i]);
        }
-       free (l->readers);
+       free(l->readers);
 err4:
-       free (l->buffers);
+       free(l->buffers);
 err3:
-       log_format_free (l->default_format);
+       log_format_free(l->default_format);
 err2:
-       close (l->epollfd);
+       close(l->epollfd);
 err1:
        free(l);
        return NULL;
@@ -1050,8 +1050,8 @@ static void logger_free(struct logger* l)
        }
 
        for (j = 0; j < LOG_ID_MAX; j++) {
-               close (l->socket_ctl[j].fd);
-               close (l->socket_wr[j].fd);
+               close(l->socket_ctl[j].fd);
+               close(l->socket_wr[j].fd);
                buffer_free(&l->buffers[j]);
        }
 
@@ -1155,7 +1155,7 @@ static int do_logger(struct logger* server)
        const int max_events = 1024;
        struct epoll_event events[1024];
 
-       for(;;) {
+       for (;;) {
                gettimeofday(&tv1, NULL);
                time_left = logger_get_timeout(server);
                nfds = epoll_wait(server->epollfd, events, max_events, time_left);
@@ -1190,7 +1190,7 @@ static int parse_configs(struct logger** server)
 
        log_config_read(&conf);
 
-       *server = logger_create (&conf);
+       *server = logger_create(&conf);
        if (!(*server))
                return EINVAL;
 
index 710b509..e4f7671 100644 (file)
@@ -1,6 +1,6 @@
 static void show_help(const char *cmd)
 {
-       fprintf ( stderr,
+       fprintf(stderr,
                "Usage: %s [options] [filterspecs]"
 #ifdef DLOG_BACKEND_PIPE
                " [ < filename.raw ]"
index 0f3ac51..5b1a4c2 100755 (executable)
@@ -83,9 +83,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 ((!ignore_time_reversal || (start_sec < entry.tv_sec) ||
                ((start_sec == entry.tv_sec) && (start_nsec < entry.tv_nsec))) &&
@@ -115,11 +114,10 @@ static void processBuffer(struct log_device_t* dev, struct logger_entry *buf)
        g_log_file.size += bytes_written;
 
        if (g_log_file.rotate_size_kbytes > 0 && (g_log_file.size / 1024) >= g_log_file.rotate_size_kbytes) {
-               if (g_nonblock) {
+               if (g_nonblock)
                        exit(0);
-               } else if (g_log_file.path) {
+               else if (g_log_file.path)
                        rotate_logs(&g_log_file);
-               }
        }
 
 error:
@@ -177,18 +175,16 @@ static void read_log_lines(struct log_device_t* devices)
        fd_set readset;
 
        for (dev = devices; dev; dev = dev->next) {
-               if (dev->fd > max) {
+               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.
                        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);
 
@@ -238,34 +234,29 @@ 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;
                                }
                        }
@@ -400,7 +391,7 @@ void set_dlog_time_history(void)
        int fd = open(START_TIME_PATH, (O_WRONLY | O_TRUNC | O_CREAT), 0777);
        int dlogutil_pid = getpid();
 
-       if( fd < 0 ) {
+       if (fd < 0) {
                printf("\n[dlogutil][%d][%s:%d] error to open (errno:%d)\n",
                                dlogutil_pid, __func__, __LINE__, errno);
                return;
@@ -408,7 +399,7 @@ void set_dlog_time_history(void)
 
        snprintf(buf, START_TIME_BUF_SIZE, "%d %d", start_sec, start_nsec);
        size = strlen(buf);
-       if(write(fd, buf, size) < 0)
+       if (write(fd, buf, size) < 0)
                printf("\n[dlogutil][%d][%s:%d] error to write (errno:%d)\n",
                                dlogutil_pid, __func__, __LINE__, errno);
        close(fd);
@@ -427,7 +418,7 @@ void get_dlog_time_history()
 {
        char buf[START_TIME_BUF_SIZE] = {0,};
        struct sigaction act;
-       int fd = open(START_TIME_PATH, ( O_RDONLY ), 0777);
+       int fd = open(START_TIME_PATH, (O_RDONLY), 0777);
        int dlogutil_pid = getpid();
 
        if (fd < 0 && errno != ENOENT)
index 2187b64..de64574 100644 (file)
@@ -57,22 +57,22 @@ static int sort_timeout = 1000; // ms
 static log_format * log_fmt;
 
 static struct sorting_vector {
-       struct logger_entry * data [SORT_BUFFER_SIZE];
+       struct logger_entry *data[SORT_BUFFER_SIZE];
        int size;
        int last_processed;
 } logs;
 
-static void push_log (struct logger_entry * p)
+static void push_log(struct logger_entry * p)
 {
        int i;
        log_entry entry;
 
-       log_process_log_buffer (p, & entry);
-       if (!log_should_print_line (log_fmt, entry.tag, entry.priority))
+       log_process_log_buffer(p, &entry);
+       if (!log_should_print_line(log_fmt, entry.tag, entry.priority))
                return;
 
        if ((logs.size + 1) % SORT_BUFFER_SIZE == logs.last_processed) {
-               free (logs.data [logs.last_processed]);
+               free(logs.data[logs.last_processed]);
                logs.last_processed = (logs.last_processed + 1) % SORT_BUFFER_SIZE;
        }
 
@@ -178,7 +178,7 @@ static int process_log(struct logger_entry *e, const struct timespec *now)
 
        if (ns < 0) {
                ns += 1000000000;
-               -- s;
+               --s;
        }
 
        if (sort_timeout < (s*1000 + ns/1000000)) {
@@ -203,13 +203,14 @@ static void handle_pipe(int pipe_fd, int dump)
        struct epoll_event ev = { .events = EPOLLIN, .data.fd = pipe_fd };
 
        epollfd = epoll_create1(0);
-       r = epoll_ctl (epollfd, EPOLL_CTL_ADD, pipe_fd, &ev);
+
+       r = epoll_ctl(epollfd, EPOLL_CTL_ADD, pipe_fd, &ev);
        if (r == -1 && errno == EPERM)
                is_file = 1;
 
-       clock_gettime (CLOCK_MONOTONIC, &start_time);
+       clock_gettime(CLOCK_MONOTONIC, &start_time);
 
-       fcntl (pipe_fd, F_SETFL, fcntl (pipe_fd, F_GETFL, 0) | O_NONBLOCK);
+       fcntl(pipe_fd, F_SETFL, fcntl(pipe_fd, F_GETFL, 0) | O_NONBLOCK);
 
        for (;;) {
                struct logger_entry *e;
@@ -230,7 +231,7 @@ static void handle_pipe(int pipe_fd, int dump)
                        }
                } else
                        while (!filled && logs.last_processed != logs.size)
-                               if (process_log (logs.data[logs.last_processed], &now)) {
+                               if (process_log(logs.data[logs.last_processed], &now)) {
                                        free(logs.data[logs.last_processed]);
                                        logs.last_processed = (logs.last_processed + 1) % SORT_BUFFER_SIZE;
                                } else
@@ -281,7 +282,7 @@ static void handle_pipe(int pipe_fd, int dump)
        }
 }
 
-int handle_file (char const * filename)
+int handle_file(char const * filename)
 {
        fd_set readfds;
        int endian, version;
@@ -308,7 +309,7 @@ int handle_file (char const * filename)
                return 0;
 
        if (endian != ENDIANNESS_CHECK) {
-               fprintf (stderr, "Unsupported endianness!\n");
+               fprintf(stderr, "Unsupported endianness!\n");
                return 0;
        }
 
@@ -317,7 +318,7 @@ int handle_file (char const * filename)
                return 0;
 
        if (version != PIPE_FILE_FORMAT_VERSION) {
-               fprintf (stderr, "Obsolete file format version!\n");
+               fprintf(stderr, "Obsolete file format version!\n");
                return 0;
        }
 
@@ -338,13 +339,13 @@ int main(int argc, char ** argv)
        int dump = 0;
        int into_file = 0;
        int silence = 0;
-       char conf_key [MAX_CONF_KEY_LEN];
+       char conf_key[MAX_CONF_KEY_LEN];
 
-       log_fmt = log_format_new ();
-       log_set_print_format (log_fmt, FORMAT_KERNELTIME);
+       log_fmt = log_format_new();
+       log_set_print_format(log_fmt, FORMAT_KERNELTIME);
 
        while (1) {
-               static struct option long_options [] = {
+               static struct option long_options[] = {
                        {"dumpfile", required_argument, 0, 0},
                        {"help", no_argument, 0, 'h'},
                        {0, 0, 0, 0}
@@ -359,21 +360,21 @@ int main(int argc, char ** argv)
                case 0:
                        switch (long_option_id) {
                        case 0:
-                               strncpy (file_input_name, optarg, MAX_CONF_VAL_LEN);
+                               strncpy(file_input_name, optarg, MAX_CONF_VAL_LEN);
                                break;
                        case 1:
-                               show_help (argv[0]);
+                               show_help(argv[0]);
                                return 1;
                        }
                        break;
                case 'h':
-                       show_help (argv[0]);
+                       show_help(argv[0]);
                        return 1;
                case 'd':
                        dump = -1;
                        break;
                case 't':
-                       dump = atoi (optarg);
+                       dump = atoi(optarg);
                        break;
                case 'c':
                        should_clear = 1;
@@ -388,7 +389,7 @@ int main(int argc, char ** argv)
                        into_file = 1;
                        break;
                case 'v':
-                       log_set_print_format (log_fmt, log_format_from_string (optarg));
+                       log_set_print_format(log_fmt, log_format_from_string(optarg));
                        break;
                case 's':
                        silence = 1;
@@ -411,23 +412,23 @@ int main(int argc, char ** argv)
        logs.size = 0;
        logs.last_processed = 0;
 
-       if (strlen(buffer_name) && (((buf_id = log_id_by_name (buffer_name)) < 0) || (buf_id >= LOG_ID_MAX))) {
-               printf ("There is no buffer \"%s\"\n", buffer_name);
+       if (strlen(buffer_name) && (((buf_id = log_id_by_name(buffer_name)) < 0) || (buf_id >= LOG_ID_MAX))) {
+               printf("There is no buffer \"%s\"\n", buffer_name);
                return 1;
        }
 
        log_config_read(&conf);
 
-       conf_value = log_config_get (&conf, "util_sorting_time_window");
+       conf_value = log_config_get(&conf, "util_sorting_time_window");
        if (conf_value)
-               sort_timeout = strtol (conf_value, NULL, 10);
+               sort_timeout = strtol(conf_value, NULL, 10);
        if (sort_timeout <= 0)
                sort_timeout = 1000;
 
        if (should_getsize)
                return do_getsize(&conf);
 
-       snprintf (conf_key, sizeof(conf_key), "%s_ctl_sock", log_name_by_id (buf_id));
+       snprintf(conf_key, sizeof(conf_key), "%s_ctl_sock", log_name_by_id(buf_id));
 
        if ((sock_path = log_config_get(&conf, conf_key)) == NULL) {
                printf("Error: dlog config is broken, lacks the \"%s\" entry\n", conf_key);
@@ -436,7 +437,7 @@ int main(int argc, char ** argv)
 
        log_config_free(&conf);
 
-       if (strlen (file_input_name) > 0 && handle_file (file_input_name))
+       if (strlen(file_input_name) > 0 && handle_file(file_input_name))
                return 0;
 
        if ((sock_fd = connect_sock(sock_path)) < 0) {
index fbe351a..9652ad1 100644 (file)
@@ -144,7 +144,7 @@ int log_config_write(struct log_config* config, char const * filename)
 
        e = config->begin;
 
-       fprintf (file, "# This file has been autogenerated by dlogctrl\n");
+       fprintf(file, "# This file has been autogenerated by dlogctrl\n");
 
        while (e) {
                r = fprintf(file, "%s=%s\n", e->key, e->value);
@@ -226,7 +226,7 @@ int log_config_foreach(struct log_config* config, int (*func)(const char* key, c
 {
        int r = -1;
        struct log_conf_entry* e = config->begin;
-       while(e) {
+       while (e) {
                if (!(r = func(e->key, e->value)))
                        break;
 
index fd1b18f..55f7d2c 100755 (executable)
@@ -144,9 +144,8 @@ 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);
-               }
                _E("%s:%c\n", p_fi->mTag, cPri);
        }
 
@@ -274,9 +273,8 @@ int log_add_filter_rule(log_format *p_format,
 
        tagNameLength = strcspn(filterExpression, ":");
 
-       if (tagNameLength == 0) {
+       if (tagNameLength == 0)
                goto error;
-       }
 
        if (filterExpression[tagNameLength] == ':') {
                pri = filter_char_to_pri(filterExpression[tagNameLength+1]);
@@ -298,9 +296,8 @@ int log_add_filter_rule(log_format *p_format,
                /* 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);
@@ -621,9 +618,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 */
@@ -662,9 +658,8 @@ char *log_format_log_line(
                }
        }
 
-       if (p_outLength != NULL) {
+       if (p_outLength != NULL)
                *p_outLength = p - ret;
-       }
 
        return ret;
 }
@@ -708,9 +703,8 @@ int log_print_log_line(
        }
 
 done:
-       if (outBuffer != defaultBuffer) {
+       if (outBuffer != defaultBuffer)
                free(outBuffer);
-       }
 
        return ret;
 }
index 684356e..de0d08e 100644 (file)
@@ -240,9 +240,9 @@ int read_queued_entry_from_dev(int fd, struct queued_entry_t *entry, uint32_t fo
 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;
 }
 
index e3c801c..7cd8ae2 100644 (file)
@@ -34,9 +34,8 @@ int main(int argc, char **argv)
                LOGE("%s", huge_buffer);
 
                // check garbage data
-               for (i = 0; i < LOG_MAX_SIZE; ++i) {
+               for (i = 0; i < LOG_MAX_SIZE; ++i)
                        buffer[i] = rand() & 255;
-               }
 
                LOGE("%s", buffer);