* @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
* @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
#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 */
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_ */
#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
#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.
*
*/
-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
*
*/
-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
* 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
*/
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
*
*/
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
#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 {
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;
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)) {
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) {
-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"
);
}
-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"
/* 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;
}
}
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 {
log_format* default_format;
};
-static int parse_permissions (const char * str)
+static int parse_permissions(const char * str)
{
int ret, parsed;
char * parse_safety;
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;
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;
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;
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)
++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;
}
{
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 };
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)
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;
}
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) {
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);
}
}
ret = -1;
cleanup:
- close (epoll_fd);
+ close(epoll_fd);
reader->current = from;
return ret;
}
}
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);
}
}
-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;
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;
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;
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;
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;
}
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]);
}
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);
log_config_read(&conf);
- *server = logger_create (&conf);
+ *server = logger_create(&conf);
if (!(*server))
return EINVAL;
static void show_help(const char *cmd)
{
- fprintf ( stderr,
+ fprintf(stderr,
"Usage: %s [options] [filterspecs]"
#ifdef DLOG_BACKEND_PIPE
" [ < filename.raw ]"
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))) &&
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:
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);
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;
}
}
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;
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);
{
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)
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;
}
if (ns < 0) {
ns += 1000000000;
- -- s;
+ --s;
}
if (sort_timeout < (s*1000 + ns/1000000)) {
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;
}
} 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
}
}
-int handle_file (char const * filename)
+int handle_file(char const * filename)
{
fd_set readfds;
int endian, version;
return 0;
if (endian != ENDIANNESS_CHECK) {
- fprintf (stderr, "Unsupported endianness!\n");
+ fprintf(stderr, "Unsupported endianness!\n");
return 0;
}
return 0;
if (version != PIPE_FILE_FORMAT_VERSION) {
- fprintf (stderr, "Obsolete file format version!\n");
+ fprintf(stderr, "Obsolete file format version!\n");
return 0;
}
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}
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;
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;
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);
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) {
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);
{
int r = -1;
struct log_conf_entry* e = config->begin;
- while(e) {
+ while (e) {
if (!(r = func(e->key, e->value)))
break;
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);
}
tagNameLength = strcspn(filterExpression, ":");
- if (tagNameLength == 0) {
+ if (tagNameLength == 0)
goto error;
- }
if (filterExpression[tagNameLength] == ':') {
pri = filter_char_to_pri(filterExpression[tagNameLength+1]);
/* 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);
} else {
ret = (char *)malloc(bufferSize);
- if (ret == NULL) {
+ if (ret == NULL)
return ret;
- }
}
ret[0] = '\0'; /* to start strcat off */
}
}
- if (p_outLength != NULL) {
+ if (p_outLength != NULL)
*p_outLength = p - ret;
- }
return ret;
}
}
done:
- if (outBuffer != defaultBuffer) {
+ if (outBuffer != defaultBuffer)
free(outBuffer);
- }
return ret;
}
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;
}
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);