Enable returning TIZEN_ERROR_INVALID_PARAMETERS on invalid params instead of assertin... 09/223209/9
authorMateusz Majewski <m.majewski2@samsung.com>
Mon, 27 Jan 2020 11:26:57 +0000 (12:26 +0100)
committerMateusz Majewski <m.majewski2@samsung.com>
Wed, 5 Feb 2020 06:59:55 +0000 (07:59 +0100)
Change-Id: I9754699e774b4b3de8a166063bb9b44b52c3bf06

include/dlogutil.h
include/logcommon.h
src/libdlogutil/lib.c
src/shared/logprint.c
src/shared/queued_entry_timestamp.c

index 979ac2a..3fe1f32 100644 (file)
@@ -77,6 +77,7 @@ typedef struct dlogutil_entry dlogutil_entry_s;
  * @param[out] tid TID of the log sender
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER One of the pointers was NULL
  * @retval TIZEN_ERROR_NO_DATA TID missing or not applicable
  */
 int dlogutil_entry_get_tid(const dlogutil_entry_s *entry, pid_t *tid);
@@ -90,6 +91,7 @@ int dlogutil_entry_get_tid(const dlogutil_entry_s *entry, pid_t *tid);
  * @param[out] pid PID of the log sender
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER One of the pointers was NULL
  * @retval TIZEN_ERROR_NO_DATA PID missing or not applicable
  */
 int dlogutil_entry_get_pid(const dlogutil_entry_s *entry, pid_t *pid);
@@ -104,6 +106,7 @@ int dlogutil_entry_get_pid(const dlogutil_entry_s *entry, pid_t *pid);
  * @param[out] tag Log tag
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER One of the pointers was NULL
  * @retval TIZEN_ERROR_NO_DATA The tag is missing
  */
 int dlogutil_entry_get_tag(const dlogutil_entry_s *entry, const char **tag);
@@ -118,6 +121,7 @@ int dlogutil_entry_get_tag(const dlogutil_entry_s *entry, const char **tag);
  * @param[out] msg Log message
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER One of the pointers was NULL
  * @retval TIZEN_ERROR_NO_DATA The message is missing
  */
 int dlogutil_entry_get_message(const dlogutil_entry_s *entry, const char **msg);
@@ -132,6 +136,8 @@ int dlogutil_entry_get_message(const dlogutil_entry_s *entry, const char **msg);
  * @param[out] ts Timestamp of the entry
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid value of order
+ * @retval TIZEN_ERROR_INVALID_PARAMETER One of the pointers was NULL
  * @retval TIZEN_ERROR_NO_DATA The timestamp is missing
  * @see dlogutil_get_traits()
  */
@@ -144,6 +150,7 @@ int dlogutil_entry_get_timestamp(const dlogutil_entry_s *entry, dlogutil_sorting
  * @param[out] prio Log priority
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER One of the pointers was NULL
  * @retval TIZEN_ERROR_NO_DATA The priority is missing
  */
 int dlogutil_entry_get_priority(const dlogutil_entry_s *entry, log_priority *prio);
@@ -178,6 +185,7 @@ void dlogutil_filter_options_destroy(dlogutil_filter_options_s *filter);
  * @param[in] tid The TID value
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  * @retval TIZEN_ERROR_OUT_OF_MEMORY Out of memory
  */
 int dlogutil_filter_options_set_tid(dlogutil_filter_options_s *filter, pid_t tid);
@@ -189,6 +197,7 @@ int dlogutil_filter_options_set_tid(dlogutil_filter_options_s *filter, pid_t tid
  * @param[in] pid The PID value.
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  * @retval TIZEN_ERROR_OUT_OF_MEMORY Out of memory
  */
 int dlogutil_filter_options_set_pid(dlogutil_filter_options_s *filter, pid_t pid);
@@ -201,6 +210,7 @@ int dlogutil_filter_options_set_pid(dlogutil_filter_options_s *filter, pid_t pid
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
  * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid syntax of the filterspec
+ * @retval TIZEN_ERROR_INVALID_PARAMETER One of the pointers was NULL
  * @retval TIZEN_ERROR_OUT_OF_MEMORY Out of memory
  */
 int dlogutil_filter_options_set_filterspec(dlogutil_filter_options_s *filter, const char *query);
@@ -234,6 +244,7 @@ void dlogutil_sorting_options_destroy(dlogutil_sorting_options_s *sorting);
  * @param[in] sorting A handle to the settings struct
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  * @see dlogutil_sorting_options_enable_sorting()
  * @see dlogutil_sorting_options_enable_sorting_with_size()
  */
@@ -246,6 +257,7 @@ int dlogutil_sorting_options_disable_sorting(dlogutil_sorting_options_s *sorting
  * @param[in] sorting A handle to the settings struct
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  * @see dlogutil_sorting_options_disable_sorting()
  * @see dlogutil_sorting_options_enable_sorting_with_size()
  */
@@ -261,6 +273,8 @@ int dlogutil_sorting_options_enable_sorting(dlogutil_sorting_options_s *sorting)
  * @param[in] entry_count How many logs to keep at a given time. At least 1
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER Zero size
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  * @see dlogutil_sorting_options_disable_sorting()
  * @see dlogutil_sorting_options_enable_sorting()
  */
@@ -278,6 +292,7 @@ int dlogutil_sorting_options_enable_sorting_with_size(dlogutil_sorting_options_s
  * @param[in] sort_by Which timestamp type to sort by. #DLOGUTIL_SORT_DEFAULT is allowed
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  */
 int dlogutil_sorting_options_set_sort_by(dlogutil_sorting_options_s *sorting, dlogutil_sorting_order_e sort_by);
 
@@ -318,6 +333,8 @@ static const unsigned int DLOGUTIL_MAX_DUMP_SIZE = UINT_MAX;
  * @param[in] filter Filter settings. Can be NULL, in which case we let everything through
  * @return An error code, or the callback return value
  * @retval TIZEN_ERROR_NONE Should never happen
+ * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid buffer selection
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The callback pointer was NULL
  * @retval Other Either an arbitrary Tizen error code, or the callback return value
  * @see #dlogutil_entry_cb
  * @see dlogutil_get_logs_dump()
@@ -377,6 +394,8 @@ int dlogutil_get_logs_continuous(int buffers, dlogutil_entry_cb callback, void *
  * @param[in] filter Filter settings. Can be NULL, in which case we let everything through
  * @return An error code, or the callback return value
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid buffer selection
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The callback pointer was NULL
  * @retval Other Either an arbitrary Tizen error code, or the callback return value
  * @see #dlogutil_entry_cb
  * @see dlogutil_get_logs_continuous()
@@ -425,6 +444,8 @@ int dlogutil_get_logs_dump(int buffers, unsigned int entry_count, dlogutil_entry
  * @param[in] buffer A single buffer to be cleared
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid buffer
+ * @retval TIZEN_ERROR_INVALID_PARAMETER More than one buffer
  * @retval Other An arbitrary Tizen error code
  */
 int dlogutil_buffer_clear(dlogutil_buffer_e buffer);
@@ -437,6 +458,9 @@ int dlogutil_buffer_clear(dlogutil_buffer_e buffer);
  * @param[out] name The name of the passed buffer
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid buffer
+ * @retval TIZEN_ERROR_INVALID_PARAMETER More than one buffer
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  * @retval Other An arbitrary Tizen error code
  */
 int dlogutil_buffer_get_name(dlogutil_buffer_e buffer, const char **name);
@@ -452,6 +476,9 @@ int dlogutil_buffer_get_name(dlogutil_buffer_e buffer, const char **name);
  * @param[out] size The size in entries of the passed buffer
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid buffer
+ * @retval TIZEN_ERROR_INVALID_PARAMETER More than one buffer
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  * @retval Other An arbitrary Tizen error code
  */
 int dlogutil_buffer_get_size(dlogutil_buffer_e buffer, unsigned int *size);
@@ -470,6 +497,9 @@ int dlogutil_buffer_get_size(dlogutil_buffer_e buffer, unsigned int *size);
  * @param[out] type The default timestamp type of the passed buffer
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid buffer
+ * @retval TIZEN_ERROR_INVALID_PARAMETER More than one buffer
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  * @retval Other An arbitrary Tizen error code
  */
 int dlogutil_buffer_get_default_ts_type(dlogutil_buffer_e buffer, dlogutil_sorting_order_e *type);
@@ -489,7 +519,9 @@ int dlogutil_buffer_get_default_ts_type(dlogutil_buffer_e buffer, dlogutil_sorti
  * @param[out] available Whether the given timestamp type is guaranteed to be available
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
- * @retval TIZEN_INVALID_PARAMETER Invalid parameter
+ * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid buffer
+ * @retval TIZEN_ERROR_INVALID_PARAMETER More than one buffer
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  */
 int dlogutil_buffer_check_ts_type_available(dlogutil_buffer_e buffer, dlogutil_sorting_order_e type, bool *available);
 
index faf04b1..6435b4b 100644 (file)
@@ -149,6 +149,8 @@ static inline int fd_clear_flags(int fd, int mask)
 int str_ends_with(const char *str, const char *suffix);
 char *create_glued_string(char const *const *strings, int n);
 
+#define CHECK_PARAM(param) if (!(param)) return TIZEN_ERROR_INVALID_PARAMETER;
+
 #ifdef __cplusplus
 }
 #endif
index 6e82d9a..76556eb 100644 (file)
 #include <logretrieve.h>
 #include <privilege.h>
 #include <tizen.h>
+#include <logcommon.h>
 
 EXPORT_API int dlogutil_entry_get_tid(const dlogutil_entry_s *e, pid_t *tid)
 {
-       assert(e);
-       assert(tid);
+       CHECK_PARAM(e);
+       CHECK_PARAM(tid);
 
        *tid = e->tid;
        if (e->tid == 0)
@@ -35,8 +36,8 @@ EXPORT_API int dlogutil_entry_get_tid(const dlogutil_entry_s *e, pid_t *tid)
 
 EXPORT_API int dlogutil_entry_get_pid(const dlogutil_entry_s *e, pid_t *pid)
 {
-       assert(e);
-       assert(pid);
+       CHECK_PARAM(e);
+       CHECK_PARAM(pid);
 
        *pid = e->pid;
        if (e->pid == 0)
@@ -47,8 +48,8 @@ EXPORT_API int dlogutil_entry_get_pid(const dlogutil_entry_s *e, pid_t *pid)
 
 EXPORT_API int dlogutil_entry_get_priority(const dlogutil_entry_s *e, log_priority *prio)
 {
-       assert(e);
-       assert(prio);
+       CHECK_PARAM(e);
+       CHECK_PARAM(prio);
 
        *prio = e->priority;
        return TIZEN_ERROR_NONE;
@@ -101,7 +102,7 @@ EXPORT_API void dlogutil_sorting_options_destroy(dlogutil_sorting_options_s *sor
 
 EXPORT_API int dlogutil_sorting_options_disable_sorting(dlogutil_sorting_options_s *sorting)
 {
-       assert(sorting);
+       CHECK_PARAM(sorting);
 
        sorting->logs_size = 0;
        return TIZEN_ERROR_NONE;
@@ -109,7 +110,7 @@ EXPORT_API int dlogutil_sorting_options_disable_sorting(dlogutil_sorting_options
 
 EXPORT_API int dlogutil_sorting_options_enable_sorting(dlogutil_sorting_options_s *sorting)
 {
-       assert(sorting);
+       CHECK_PARAM(sorting);
 
        if (sorting->logs_size == 0)
                sorting->logs_size = DEFAULT_SORT_BUFFER_SIZE;
@@ -118,8 +119,8 @@ EXPORT_API int dlogutil_sorting_options_enable_sorting(dlogutil_sorting_options_
 
 EXPORT_API int dlogutil_sorting_options_enable_sorting_with_size(dlogutil_sorting_options_s *sorting, unsigned int entry_count)
 {
-       assert(sorting);
-       assert(entry_count > 0);
+       CHECK_PARAM(sorting);
+       CHECK_PARAM(entry_count > 0);
 
        sorting->logs_size = entry_count;
        return TIZEN_ERROR_NONE;
@@ -127,7 +128,7 @@ EXPORT_API int dlogutil_sorting_options_enable_sorting_with_size(dlogutil_sortin
 
 EXPORT_API int dlogutil_sorting_options_set_sort_by(dlogutil_sorting_options_s *sorting, dlogutil_sorting_order_e sort_by)
 {
-       assert(sorting);
+       CHECK_PARAM(sorting);
 
        sorting->sort_by = sort_by;
        return TIZEN_ERROR_NONE;
@@ -152,7 +153,7 @@ EXPORT_API int dlogutil_sorting_options_set_sort_by(dlogutil_sorting_options_s *
 static int dlogutil_get_logs_internal(int buffers, unsigned int mode, dlogutil_entry_cb callback, void *data,
        dlogutil_sorting_options_s *sorting, dlogutil_filter_options_s *filter)
 {
-       assert(callback);
+       CHECK_PARAM(callback);
 
        /* KMSG lacks some timestamps so we have trouble sorting
         * it with core buffers, thus mixing them is not supported
@@ -225,6 +226,8 @@ EXPORT_API int dlogutil_buffer_clear(dlogutil_buffer_e buffer)
 
 EXPORT_API int dlogutil_buffer_get_name(dlogutil_buffer_e buffer, const char **name)
 {
+       CHECK_PARAM(name);
+
        COMMON_INIT_SINGLE
 
        *name = fdi_ptrs[0]->name;
@@ -233,6 +236,8 @@ EXPORT_API int dlogutil_buffer_get_name(dlogutil_buffer_e buffer, const char **n
 
 EXPORT_API int dlogutil_buffer_get_size(dlogutil_buffer_e buffer, unsigned int *size)
 {
+       CHECK_PARAM(size);
+
        COMMON_INIT_SINGLE
 
        return fdi_ptrs[0]->ops->getsize(fdi_ptrs[0], size);
@@ -240,6 +245,8 @@ EXPORT_API int dlogutil_buffer_get_size(dlogutil_buffer_e buffer, unsigned int *
 
 EXPORT_API int dlogutil_buffer_get_default_ts_type(dlogutil_buffer_e buffer, dlogutil_sorting_order_e *type)
 {
+       CHECK_PARAM(type);
+
        COMMON_INIT_SINGLE
 
        *type = get_proper_sort_by(DLOGUTIL_SORT_DEFAULT, is_pipe, &conf, &(bool){ false });
@@ -248,6 +255,8 @@ EXPORT_API int dlogutil_buffer_get_default_ts_type(dlogutil_buffer_e buffer, dlo
 
 EXPORT_API int dlogutil_buffer_check_ts_type_available(dlogutil_buffer_e buffer, dlogutil_sorting_order_e type, bool *available)
 {
+       CHECK_PARAM(available);
+
        COMMON_INIT_SINGLE
 
        switch (type) {
index aaaf031..fc23eec 100644 (file)
@@ -24,6 +24,7 @@
 #include <tizen.h>
 
 #include <logprint.h>
+#include <logcommon.h>
 
 /**
  * @addtogroup SHARED_FUNCTIONS
@@ -315,7 +316,7 @@ log_print_format log_format_from_string(const char *formatString)
  * @param[in] filterExpression A filter expression ("tag:prio")
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
- * @retval TIZEN_ERROR_INVALID_PARAMETER One of the arguments was invalid
+ * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid syntax of the filterspec
  * @retval TIZEN_ERROR_OUT_OF_MEMORY Couldn't allocate enough memory
  * @remarks Assumes single threaded execution
  */
@@ -393,15 +394,16 @@ int log_add_filter_rule(dlogutil_filter_options_s *p_filter,
  * @param[in] filterString A filter string containing multiple filter rules delimited by spaces, tabs or commas
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
- * @retval TIZEN_ERROR_INVALID_PARAMETER One of the arguments was invalid
+ * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid syntax of the filterspec
+ * @retval TIZEN_ERROR_INVALID_PARAMETER One of the pointers was NULL
  * @retval TIZEN_ERROR_OUT_OF_MEMORY Couldn't allocate enough memory
  * @remarks Assumes single threaded execution
  */
 LIBDLOGUTIL_EXPORT_API int dlogutil_filter_options_set_filterspec(dlogutil_filter_options_s *p_filter,
                const char *filterString)
 {
-       assert(p_filter);
-       assert(filterString);
+       CHECK_PARAM(p_filter);
+       CHECK_PARAM(filterString);
 
        char *filterStringCopy = strdup(filterString);
        if (!filterStringCopy)
@@ -434,12 +436,13 @@ LIBDLOGUTIL_EXPORT_API int dlogutil_filter_options_set_filterspec(dlogutil_filte
  * @param[in] pid A pid to filter by
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER One of the pointers was NULL
  * @retval TIZEN_ERROR_OUT_OF_MEMORY Couldn't allocate enough memory
  * @remarks Assumes single threaded execution
  */
 LIBDLOGUTIL_EXPORT_API int dlogutil_filter_options_set_pid(dlogutil_filter_options_s *p_filter, pid_t pid)
 {
-       assert(p_filter);
+       CHECK_PARAM(p_filter);
 
        FilterInfo *p_fi = filterinfo_new(NULL, 0, false, false, pid, FILTERINFO_TID_NONE);
        if (!p_fi)
@@ -455,12 +458,13 @@ LIBDLOGUTIL_EXPORT_API int dlogutil_filter_options_set_pid(dlogutil_filter_optio
  * @param[in] tid A tid to filter by
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER One of the pointers was NULL
  * @retval TIZEN_ERROR_OUT_OF_MEMORY Couldn't allocate enough memory
  * @remarks Assumes single threaded execution
  */
 LIBDLOGUTIL_EXPORT_API int dlogutil_filter_options_set_tid(dlogutil_filter_options_s *p_filter, pid_t tid)
 {
-       assert(p_filter);
+       CHECK_PARAM(p_filter);
 
        FilterInfo *p_fi = filterinfo_new(NULL, 0, false, false, FILTERINFO_PID_NONE, tid);
        if (!p_fi)
@@ -476,12 +480,13 @@ LIBDLOGUTIL_EXPORT_API int dlogutil_filter_options_set_tid(dlogutil_filter_optio
  * @param[out] tag The log tag
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER One of the pointers was NULL
  * @retval TIZEN_ERROR_NO_DATA No valid tag was found
  */
 LIBDLOGUTIL_EXPORT_API int dlogutil_entry_get_tag(const dlogutil_entry_s *entry, const char **tag)
 {
-       assert(entry);
-       assert(tag);
+       CHECK_PARAM(entry);
+       CHECK_PARAM(tag);
 
        if (entry->len - (int) sizeof(dlogutil_entry_s) < 2
        || ((const char *)entry)[entry->len - 1] != '\0') {
@@ -500,12 +505,13 @@ LIBDLOGUTIL_EXPORT_API int dlogutil_entry_get_tag(const dlogutil_entry_s *entry,
  * @param[out] msg The log message
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
+ * @retval TIZEN_ERROR_INVALID_PARAMETER One of the pointers was NULL
  * @retval TIZEN_ERROR_NO_DATA No valid message was found
  */
 LIBDLOGUTIL_EXPORT_API int dlogutil_entry_get_message(const dlogutil_entry_s *entry, const char **msg)
 {
-       assert(entry);
-       assert(msg);
+       CHECK_PARAM(entry);
+       CHECK_PARAM(msg);
 
        if (entry->len - (int) sizeof(dlogutil_entry_s) < 2
        || ((const char *)entry)[entry->len - 1] != '\0') {
index f21c3ec..ec4f443 100644 (file)
@@ -100,8 +100,8 @@ bool log_entry_is_earlier(const dlogutil_sorting_order_e sort_by, const dlogutil
 
 LIBDLOGUTIL_EXPORT_API int dlogutil_entry_get_timestamp(const dlogutil_entry_s *le, dlogutil_sorting_order_e stamp_type, struct timespec *ts)
 {
-       assert(le);
-       assert(ts);
+       if (!le || !ts)
+               return TIZEN_ERROR_INVALID_PARAMETER;
 
        struct timespec ret;
 
@@ -123,7 +123,7 @@ LIBDLOGUTIL_EXPORT_API int dlogutil_entry_get_timestamp(const dlogutil_entry_s *
                ret.tv_nsec = le->nsec_recv_real;
                break;
 
-       default: assert(false); // LCOV_EXCL_LINE
+       default: return TIZEN_ERROR_INVALID_PARAMETER; // LCOV_EXCL_LINE
        }
 
        *ts = ret;