And return the actual thing through a parameter.
This is the Tizen API style.
Change-Id: Ibf4056a3d3a70c4c27de0b9bf5534c4bb575628c
src_tests_fd_info_SOURCES = src/tests/fd_info.c src/shared/fd_info.c
src_tests_fd_info_CFLAGS = $(check_CFLAGS)
-src_tests_fd_info_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sort_vector_push,--wrap=malloc,--wrap=free,--wrap=close,--wrap=dlogutil_entry_get_ts,--wrap=log_should_print_line
+src_tests_fd_info_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sort_vector_push,--wrap=malloc,--wrap=free,--wrap=close,--wrap=dlogutil_entry_get_timestamp,--wrap=log_should_print_line
src_tests_fdi_logger_SOURCES = src/tests/fdi_logger.c src/shared/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c
src_tests_fdi_logger_CFLAGS = $(check_CFLAGS)
src_tests_log_file_SOURCES = src/tests/log_file.c src/shared/log_file.c
src_tests_log_file_CFLAGS = $(check_CFLAGS)
-src_tests_log_file_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=strdup,--wrap=free,--wrap=memcpy,--wrap=snprintf,--wrap=open,--wrap=open64,--wrap=fstat,--wrap=fstat64,--wrap=rename,--wrap=dlogutil_entry_get_ts,--wrap=log_print_log_line,--wrap=dlogutil_entry_get_tag,--wrap=isatty
+src_tests_log_file_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=strdup,--wrap=free,--wrap=memcpy,--wrap=snprintf,--wrap=open,--wrap=open64,--wrap=fstat,--wrap=fstat64,--wrap=rename,--wrap=dlogutil_entry_get_timestamp,--wrap=log_print_log_line,--wrap=dlogutil_entry_get_tag,--wrap=isatty
src_tests_queued_entry_SOURCES = src/tests/queued_entry.c src/shared/queued_entry.c src/shared/queued_entry_timestamp.c src/shared/parsers.c src/shared/translate_syslog.c src/shared/logconfig.c src/shared/logcommon.c
src_tests_queued_entry_CFLAGS = $(check_CFLAGS)
*
* Finds the beginning of a log tag in entry's payload and returns it
*/
-const char* dlogutil_entry_get_tag(const dlogutil_entry_s *entry);
+int dlogutil_entry_get_tag(const dlogutil_entry_s *entry, const char **tag);
/**
* Returns pointer to log entry message
*
* Finds the beginning of a log message in entry's payload and returns it
*/
-const char* dlogutil_entry_get_msg(const dlogutil_entry_s *entry);
+int dlogutil_entry_get_message(const dlogutil_entry_s *entry, const char **msg);
/**
* Formats a log message into a buffer
void add_recv_timestamp(dlogutil_entry_s *le);
void copy_recv_timestamp(dlogutil_entry_s *le);
bool log_entry_is_earlier(const dlogutil_sorting_order_e sort_by, const dlogutil_entry_s *lhs, const dlogutil_entry_s *rhs);
-struct timespec dlogutil_entry_get_ts(const dlogutil_entry_s *le, dlogutil_sorting_order_e stamp_type);
+int dlogutil_entry_get_timestamp(const dlogutil_entry_s *entry, dlogutil_sorting_order_e order, struct timespec *ts);
clockid_t get_proper_clock(dlogutil_sorting_order_e sort_by);
#endif /* _QUEUED_ENTRY_TIMESTAMP_H */
int r;
if (IS_VECTOR_SIZE_SORTABLE(logs->size)) {
- struct timespec ts = dlogutil_entry_get_ts(temp, logs->sort_by);
+ struct timespec ts;
+ r = dlogutil_entry_get_timestamp(temp, logs->sort_by, &ts);
+ if (r != TIZEN_ERROR_NONE)
+ return r;
/* check if new entry is newer than util's start moment */
if (ts.tv_sec > logs->start.tv_sec || (ts.tv_sec == logs->start.tv_sec && ts.tv_nsec > logs->start.tv_nsec))
int written_bytes = 0;
- struct timespec ts = dlogutil_entry_get_ts(e, sort_by);
+ struct timespec ts;
+ if (dlogutil_entry_get_timestamp(e, sort_by, &ts) != TIZEN_ERROR_NONE)
+ return 1;
if (ts.tv_sec < file->prev_sec || (ts.tv_sec == file->prev_sec && ts.tv_nsec < file->prev_nsec)) {
struct dlogutil_entry_with_msg msg;
memcpy(&msg, e, sizeof *e);
- int r = snprintf(msg.msg, sizeof msg.msg, "%s%c%s", dlogutil_entry_get_tag(e), '\0', "INFO: Following log entry could not be sorted and is out of order.");
+ const char *tag;
+ if (dlogutil_entry_get_tag(e, &tag) != TIZEN_ERROR_NONE)
+ return 1;
+ int r = snprintf(msg.msg, sizeof msg.msg, "%s%c%s", tag, '\0', "INFO: Following log entry could not be sorted and is out of order.");
if (r < 0) {
ERR("unable to format out-of-order message %m");
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
+#include <tizen.h>
#include <logprint.h>
const char *tag;
log_priority prio;
- tag = dlogutil_entry_get_tag(entry);
/* mark empty-tagged messages and make it easy to catch an application that does that */
- if (!tag || !strlen(tag))
+ if (dlogutil_entry_get_tag(entry, &tag) == TIZEN_ERROR_NO_DATA || !tag || !strlen(tag))
tag = "DLOG_ERROR_NOTAG";
prio = (log_priority)entry->priority;
* @brief Return pointer to log entry tag
* @details Finds the beginning of a log tag in entry's payload and returns it
* @param[in] entry The log entry
- * @return Pointer to log tag
+ * @param[out] tag The log tag
+ * @return An error code
+ * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_NO_DATA No valid tag was found
*/
-const char* dlogutil_entry_get_tag(const dlogutil_entry_s *entry)
+int dlogutil_entry_get_tag(const dlogutil_entry_s *entry, const char **tag)
{
assert(entry);
+ assert(tag);
- if (entry->len - (int) sizeof(dlogutil_entry_s) < 2)
- return NULL;
- if (((const char *)entry)[entry->len - 1] != '\0')
- return NULL;
+ if (entry->len - (int) sizeof(dlogutil_entry_s) < 2
+ || ((const char *)entry)[entry->len - 1] != '\0') {
+ *tag = NULL;
+ return TIZEN_ERROR_NO_DATA;
+ }
- return entry->msg;
+ *tag = entry->msg;
+ return TIZEN_ERROR_NONE;
}
/**
* @brief Return pointer to log entry message
* @details Finds the beginning of a log message in entry's payload and returns it
* @param[in] entry The log entry
- * @return Pointer to log message
+ * @param[out] msg The log message
+ * @return An error code
+ * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_NO_DATA No valid message was found
*/
-const char* dlogutil_entry_get_msg(const dlogutil_entry_s *entry)
+int dlogutil_entry_get_message(const dlogutil_entry_s *entry, const char **msg)
{
assert(entry);
+ assert(msg);
- if (entry->len - (int) sizeof(dlogutil_entry_s) < 2)
- return NULL;
- if (((const char *)entry)[entry->len - 1] != '\0')
- return NULL;
+ if (entry->len - (int) sizeof(dlogutil_entry_s) < 2
+ || ((const char *)entry)[entry->len - 1] != '\0') {
+ *msg = NULL;
+ return TIZEN_ERROR_NO_DATA;
+ }
- return entry->msg + entry->tag_len + 1 /* NULL delimiter */;
+ *msg = entry->msg + entry->tag_len + 1 /* NULL delimiter */;
+ return TIZEN_ERROR_NONE;
}
dlogutil_sorting_order_e get_format_sorting(log_print_format format)
priChar = filter_pri_to_char((log_priority)entry->priority);
- tag = dlogutil_entry_get_tag(entry);
/* mark empty-tagged messages and make it easy to catch an application that does that */
- if (!tag || !strlen(tag))
+ if (dlogutil_entry_get_tag(entry, &tag) == TIZEN_ERROR_NO_DATA || !tag || !strlen(tag))
tag = "DLOG_ERROR_NOTAG";
- msg = dlogutil_entry_get_msg(entry) ?: "DLOG_ERROR_NOMSG";
+ if (dlogutil_entry_get_message(entry, &msg) == TIZEN_ERROR_NO_DATA || !msg)
+ msg = "DLOG_ERROR_NOMSG";
/*
* JSON is formatted separately. This is because it's so vastly different
continue;
const dlogutil_entry_s *const le = fdi->ops->peek_entry(fdi);
- struct timespec current_ts = dlogutil_entry_get_ts(le, sort_by);
+ struct timespec current_ts;
+ if (dlogutil_entry_get_timestamp(le, sort_by, ¤t_ts) != TIZEN_ERROR_NONE)
+ return fdi; // the timestampless log is always the best choice to flush ASAP
if (best_fdi && ((current_ts.tv_sec > best_ts.tv_sec) || (current_ts.tv_sec == best_ts.tv_sec && current_ts.tv_nsec > best_ts.tv_nsec)))
continue;
return l_sec < r_sec || (l_sec == r_sec && l_nsec < r_nsec);
}
-struct timespec dlogutil_entry_get_ts(const dlogutil_entry_s *le, dlogutil_sorting_order_e stamp_type)
+int dlogutil_entry_get_timestamp(const dlogutil_entry_s *le, dlogutil_sorting_order_e stamp_type, struct timespec *ts)
{
assert(le);
+ assert(ts);
struct timespec ret;
default: assert(false); // LCOV_EXCL_LINE
}
- return ret;
+ *ts = ret;
+
+ return (ret.tv_sec == 0 && ret.tv_nsec == -1) ? TIZEN_ERROR_NO_DATA : TIZEN_ERROR_NONE;
}
clockid_t get_proper_clock(dlogutil_sorting_order_e sort_by)
if (sort_vector_empty(logs))
return 0;
- struct timespec now, oldest = dlogutil_entry_get_ts(sort_vector_back(logs), logs->sort_by);
+ struct timespec now, oldest;
+ if (dlogutil_entry_get_timestamp(sort_vector_back(logs), logs->sort_by, &oldest) != TIZEN_ERROR_NONE)
+ return -1; // report negative age to flush the invalid log immediately
clock_gettime(get_proper_clock(logs->sort_by), &now);
diff_s = now.tv_sec - oldest.tv_sec;
if (timeout != -1) {
- struct timespec log_ts = dlogutil_entry_get_ts(e, stamp_type);
+ struct timespec log_ts;
+ if (dlogutil_entry_get_timestamp(e, stamp_type, &log_ts) != TIZEN_ERROR_NONE)
+ goto apply_callback; // flush timestampless logs immediately since waiting won't help
long s = reference_ts.tv_sec - log_ts.tv_sec;
long ns = reference_ts.tv_nsec - log_ts.tv_nsec;
return false;
}
+apply_callback:
*callback_ret = callback(e, userdata);
return true;
}
return fail_extract ? NULL : (dlogutil_entry_s *) 0xBADFEEL;
}
-struct timespec __wrap_dlogutil_entry_get_ts(const dlogutil_entry_s *le, dlogutil_sorting_order_e stamp_type)
+int __wrap_dlogutil_entry_get_timestamp(const dlogutil_entry_s *le, dlogutil_sorting_order_e stamp_type, struct timespec *ts)
{
assert(le == (dlogutil_entry_s *)0xBADFEEL);
- return (struct timespec) {
+ *ts = (struct timespec) {
.tv_sec = 1,
.tv_nsec = 1,
};
+ return 0;
}
static struct fd_info *expected_destroyee;
assert(expected->header.pid == lem.header.pid);
assert(expected->header.tid == lem.header.tid);
- const char *const tag_expected = dlogutil_entry_get_tag(&expected->header);
- const char *const tag_actual = dlogutil_entry_get_tag(&lem.header);
- const char *const msg_expected = dlogutil_entry_get_msg(&expected->header);
- const char *const msg_actual = dlogutil_entry_get_msg(&lem.header);
+ const char *tag_expected;
+ const char *tag_actual;
+ const char *msg_expected;
+ const char *msg_actual;
+ assert(!dlogutil_entry_get_tag(&expected->header, &tag_expected));
+ assert(!dlogutil_entry_get_tag(&lem.header, &tag_actual));
+ assert(!dlogutil_entry_get_message(&expected->header, &msg_expected));
+ assert(!dlogutil_entry_get_message(&lem.header, &msg_actual));
assert(tag_expected);
assert(tag_actual);
assert(msg_expected);
return -1;
}
-struct timespec __wrap_dlogutil_entry_get_ts(const dlogutil_entry_s *le, dlogutil_sorting_order_e stamp_type)
+int __wrap_dlogutil_entry_get_timestamp(const dlogutil_entry_s *le, dlogutil_sorting_order_e stamp_type, struct timespec *ts)
{
assert(stamp_type == DLOGUTIL_SORT_SENT_MONO);
assert(le == (dlogutil_entry_s *) 0xBA5EBALL);
- return (struct timespec) {
+ *ts = (struct timespec) {
.tv_sec = 3333,
.tv_nsec = 9999,
};
+ return 0;
}
-char *__wrap_dlogutil_entry_get_tag(const dlogutil_entry_s *entry)
+int __wrap_dlogutil_entry_get_tag(const dlogutil_entry_s *entry, const char **tag)
{
assert(entry == (dlogutil_entry_s *) 0xBA5EBALL);
- return "";
+ *tag = "";
+ return 0;
}
static bool custom_memcpy;
void check_invalid_input()
{
const dlogutil_entry_s entry = { .len = 1 };
- assert(!dlogutil_entry_get_msg(&entry));
- assert(!dlogutil_entry_get_tag(&entry));
+ const char *data;
+
+ assert(dlogutil_entry_get_message(&entry, &data) == TIZEN_ERROR_NO_DATA);
+ assert(!data);
+
+ assert(dlogutil_entry_get_tag(&entry, &data) == TIZEN_ERROR_NO_DATA);
+ assert(!data);
dlogutil_filter_options_s *const filter = log_filter_new();
assert(filter);
.sec_recv_real = 7,
.nsec_recv_real = 8,
};
- ts = dlogutil_entry_get_ts(&le, DLOGUTIL_SORT_SENT_MONO);
+ assert(!dlogutil_entry_get_timestamp(&le, DLOGUTIL_SORT_SENT_MONO, &ts));
assert(ts.tv_sec == le. sec_sent_mono);
assert(ts.tv_nsec == le.nsec_sent_mono);
- ts = dlogutil_entry_get_ts(&le, DLOGUTIL_SORT_RECV_REAL);
+ assert(!dlogutil_entry_get_timestamp(&le, DLOGUTIL_SORT_RECV_REAL, &ts));
assert(ts.tv_sec == le. sec_recv_real);
assert(ts.tv_nsec == le.nsec_recv_real);
- ts = dlogutil_entry_get_ts(&le, DLOGUTIL_SORT_SENT_REAL);
+ assert(!dlogutil_entry_get_timestamp(&le, DLOGUTIL_SORT_SENT_REAL, &ts));
assert(ts.tv_sec == le. sec_sent_real);
assert(ts.tv_nsec == le.nsec_sent_real);
- ts = dlogutil_entry_get_ts(&le, DLOGUTIL_SORT_RECV_MONO);
+ assert(!dlogutil_entry_get_timestamp(&le, DLOGUTIL_SORT_RECV_MONO, &ts));
assert(ts.tv_sec == le. sec_recv_mono);
assert(ts.tv_nsec == le.nsec_recv_mono);
assert(sle->pid == 678);
assert(sle->priority == DLOG_FATAL);
- const char *tag = dlogutil_entry_get_tag(sle);
- const char *msg = dlogutil_entry_get_msg(sle);
+ const char *tag, *msg;
+ assert(!dlogutil_entry_get_tag(sle, &tag));
+ assert(!dlogutil_entry_get_message(sle, &msg));
assert(tag);
assert(msg); // Can never be triggered, but SVACE complains without this check
assert(!strcmp("SYSLOG_USER", tag));
assert(sle->pid == 0);
assert(sle->priority == DLOG_FATAL);
- tag = dlogutil_entry_get_tag(sle);
- msg = dlogutil_entry_get_msg(sle);
+ assert(!dlogutil_entry_get_tag(sle, &tag));
+ assert(!dlogutil_entry_get_message(sle, &msg));
assert(tag);
assert(msg); // Same as above
assert(!strcmp("SYSLOG_USER", tag));