{ NULL, 0 }
};
-//static int pid;
+/* static int pid; */
static void startup(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;
{
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;
/* 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;
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;
{ NULL, 0 }
};
-//static int pid;
+/* static int pid; */
static void startup(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;
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;
/* 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;
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;
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];
}
if (config.lc_limiter) {
- if (0 > __log_limiter_initialize()) {
+ if (0 > __log_limiter_initialize())
config.lc_limiter = 0;
- }
}
}
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)
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;
}
}
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;
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);
} 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;
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));
/* 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);
#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;
{
struct rule* r;
- if (NULL == rlist) {
+ if (NULL == rlist)
return;
- }
while ((r = rlist)) {
rlist = rlist->prev;
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));
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));
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:
;;
}
}
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 */
/* 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. */
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*));
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);
}
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];
}
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;
/* 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;
{
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);
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 *:* */
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) {
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,
break;
}
_E("dlogutil read");
- goto exit;//exit(EXIT_FAILURE);
+ goto exit;/* exit(EXIT_FAILURE); */
} else if (!ret) {
free(entry);
_E("read: Unexpected EOF!\n");
_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';
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"
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:
/* 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;
}
}
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;
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;
}
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);
}
{
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);
}
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) {
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:
{
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) {
}
}
-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;
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;
}
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);
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;
}
}
} 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)
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"
" ('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"
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);
}
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);
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;
}
}
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;
/* 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);
}
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");
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);
}
dev = dev->next;
}
- if (getLogSize) {
+ if (getLogSize)
return 0;
- }
- if (is_clear_log) {
+ if (is_clear_log)
return 0;
- }
read_log_lines(devices);
static void filterinfo_free(FilterInfo *p_info)
{
- if (p_info == NULL) {
+ if (p_info == NULL)
return;
- }
free(p_info->mTag);
p_info->mTag = NULL;
* 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') {
{
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;
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);
}
* 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);
}
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;
}
/**
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);
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;
}
* 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,
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;
* 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 */
} 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;
}
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 */