char msg[]; /* the entry's payload */
};
-int create_pipe_message(void * buf, int prio, char const * tag, char const * msg);
+void create_pipe_message(void * buf, int prio, char const * tag, char const * msg);
int parse_kmsg_message(char * buffer, int prime, int buffer_size);
#endif /* _QUEUED_ENTRY_H */
char buf[LOG_MAX_SIZE];
struct logger_entry* le = (struct logger_entry*)buf;
- if (log_id >= LOG_ID_MAX
- || prio < DLOG_VERBOSE
- || prio >= DLOG_PRIO_MAX
- || !msg)
- return DLOG_ERROR_INVALID_PARAMETER;
-
if (!tag)
tag = "";
- if ((ret = create_pipe_message(buf, prio, tag, msg)))
- return ret;
+ if (log_id >= LOG_ID_MAX ||
+ prio < DLOG_VERBOSE ||
+ prio >= DLOG_PRIO_MAX ||
+ !msg ||
+ strlen(tag) + strlen(msg) + sizeof(struct logger_entry) + 2 >= LOG_MAX_SIZE)
+ return DLOG_ERROR_INVALID_PARAMETER;
+
+ create_pipe_message(buf, prio, tag, msg);
if (pipe_fd[log_id] < 0 && !__reconnect_pipe(log_id))
return -1;
return -1;
ret = write(pipe_fd[log_id], buf, le->len);
if (was_ebadf) {
- if ((ret = create_pipe_message(buf, DLOG_FATAL, "LIBDLOG", "libdlog's internal state has been destroyed! The user application closed libdlog's file descriptor.")))
- return ret;
+ create_pipe_message(buf, DLOG_FATAL, "LIBDLOG", "libdlog's internal state has been destroyed! The user application closed libdlog's file descriptor.");
ret = write(pipe_fd[log_id], buf, le->len);
}
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
+#include <assert.h>
/**
* @brief Create pipe message
* @param[in] prio Priority level
* @param[in] tag Log tag
* @param[in] msg Log message contents
- * @return 0 on success, error value on failure
- * @retval DLOG_ERROR_INVALID_PARAMETER Invalid data
*/
-int create_pipe_message(void * buf, int prio, char const * tag, char const * msg)
+void create_pipe_message(void * buf, int prio, char const * tag, char const * msg)
{
+ assert(buf);
+ assert(msg);
+ assert(tag);
+ assert(prio >= DLOG_VERBOSE);
+ assert(prio < DLOG_PRIO_MAX);
+ assert(strlen(tag) + strlen(msg) + sizeof(struct logger_entry) + 2 < LOG_MAX_SIZE);
+
struct logger_entry * le = (struct logger_entry *) buf;
struct timespec ts;
int msg_l = strlen(msg) + 1;
int len = 1 + msg_l + tag_l + sizeof(struct logger_entry);
- if (len > LOG_MAX_SIZE)
- return DLOG_ERROR_INVALID_PARAMETER;
-
clock_gettime(CLOCK_MONOTONIC, &ts);
le->sec = ts.tv_sec;
memcpy(le->msg + 1, tag, tag_l);
memcpy(le->msg + 1 + tag_l, msg, msg_l);
le->len += le->len % 2;
-
- return 0;
}
/**