retval = logfile_open(&reader->file);
if (retval < 0)
goto cleanup;
- } else {
- // we have got no file path nor dlogutil connection to write to - unable to proceed
- retval = wr ? 0 : -EINVAL;
- if (retval < 0)
- goto cleanup;
-
+ } else if (wr) {
int write_fd = -1, read_fd = -1;
if (create_fifo_fds(wr->fd_entity.fd, &write_fd, &read_fd) < 0)
goto cleanup;
set_write_fd_entity(&reader->fd_entity, write_fd);
- assert(wr);
retval = send_pipe(wr->fd_entity.fd, read_fd);
- close(read_fd);
+ if (read_fd > 0)
+ close(read_fd);
if (retval)
goto cleanup;
+ } else {
+ retval = -EINVAL;
}
cleanup:
/* recycle for further usage */
assert(events);
assert(size);
- *size = 16U;
- *events = malloc(*size * sizeof **events);
- return !*events ? -ENOMEM : 0;
+ static const size_t default_size = 16U;
+ typeof(*events) ev = malloc(default_size * sizeof *ev);
+ if (!ev)
+ return -ENOMEM;
+
+ *events = ev;
+ *size = default_size;
+ return 0;
}
/**
if (nfds < 0 && errno == EINTR)
continue;
- if (nfds < 0)
- return -errno;
+ if (nfds < 0) {
+ r = -errno;
+ break;
+ }
for (int i = 0; i < nfds; i++) {
struct fd_entity* entity = (struct fd_entity*) events[i].data.ptr;
switch (p_info->type) {
case FILTER_TAG_AND_PRIO:
- return filterinfo_new(p_info->tnp.tag, p_info->tnp.pri, p_info->tnp.exactPri, p_info->tnp.prefix, FILTERINFO_PID_NONE, FILTERINFO_TID_NONE);
+ return filterinfo_new(p_info->tnp.tag, p_info->tnp.pri, p_info->tnp.prefix, p_info->tnp.exactPri, FILTERINFO_PID_NONE, FILTERINFO_TID_NONE);
case FILTER_PID:
return filterinfo_new(NULL, 0, false, false, p_info->pid, FILTERINFO_TID_NONE);
case FILTER_TID:
#else
ptm = localtime((const time_t*)&time_t_temp);
#endif
+ if (!ptm)
+ return NULL;
strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", ptm);
time_t_temp = (time_t)entry->sec_recv_real;
#else
ptm = localtime((const time_t*)&time_t_temp);
#endif
+ if (!ptm)
+ return NULL;
+
strftime(recvTimeBuf, sizeof(recvTimeBuf), "%m-%d %H:%M:%S", ptm);
strftime(tzBuf, sizeof(tzBuf), "%z", ptm);
le->tag_len = i - 1; \
break; \
} \
- if (le->tag_len == -1) \
- ; /* ignore for now */ \
+ if (le->tag_len == -1) { \
+ /* ignore for now */ \
+ } \
payload_size--; /* there's priority at first byte which is not a part of a message */ \
le->len = sizeof *le + payload_size; \
le->pid = xle->pid; \
entry.header.tid = 0;
entry.header.pid = 0;
entry.header.priority = priority;
- strncpy(entry.msg, tag, strlen(tag));
- entry.msg[strlen(tag)] = '\0'; /* tag delimiter */
- entry.msg[strlen(tag) + 1] = '\0'; /* empty msg */
+ strncpy(entry.msg, tag, strlen(tag) + 1);
+ entry.msg[strlen(tag) + 1] = '\0'; // second NULL terminator: empty message
entry.header.len = sizeof(struct logger_entry) + strlen(tag) + 2;
if (expected != log_should_print_line(p_format, &entry.header)) {
log_add_filter_rule(p_format, "crap:*");
- const size_t taglen = strlen("crap");
+ static const size_t taglen = sizeof "crap" - 1;
entry.header.priority = DLOG_VERBOSE;
strncpy(entry.msg, "crap", taglen);