limiter: do not treat limiter restrictions as an error 65/191865/6
authorMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Wed, 24 Oct 2018 15:54:04 +0000 (17:54 +0200)
committerMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Fri, 26 Oct 2018 15:03:40 +0000 (17:03 +0200)
Currently when a log is blocked by limiter rules,
dlog_print() returns an error code. Let it be blocked,
but return a success code - number of written bytes
(which is 0).

Change-Id: Ie37e3d0e17f0fa3cd9fef012412270bdce8565e2
Signed-off-by: Maciej Slodczyk <m.slodczyk2@partner.samsung.com>
src/libdlog/log.c

index 3139308..378bc75 100644 (file)
@@ -198,21 +198,34 @@ static void __dlog_fatal_assert(int prio)
  * @param[in] log_id The target buffer ID
  * @param[in] prio The log's priority
  * @param[in] tag The log's tag
- * @return 0 on success, else an error code.
+ * @return DLOG_ERROR_NONE on success, else an error code.
  * @retval DLOG_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval DLOG_ERROR_NOT_PERMITTED Not permitted
  */
-static int dlog_should_log(log_id_t log_id, int prio, const char *tag)
+static int dlog_check_validity(log_id_t log_id, int prio, const char *tag)
 {
-       if (!debugmode && prio <= DLOG_DEBUG)
-               return DLOG_ERROR_INVALID_PARAMETER;
-
        if (!tag)
                return DLOG_ERROR_INVALID_PARAMETER;
 
        if (log_id <= LOG_ID_INVALID || LOG_ID_MAX <= log_id)
                return DLOG_ERROR_INVALID_PARAMETER;
 
+       return DLOG_ERROR_NONE;
+}
+
+/**
+ * @brief Check log against limiter rules
+ * @details Checks whether the log passes current limiter rules
+ * @param[in] log_id The target buffer ID
+ * @param[in] prio The log's priority
+ * @param[in] tag The log's tag
+ * @return DLOG_ERROR_NONE on success, else an error code.
+ * @retval DLOG_ERROR_NOT_PERMITTED Not permitted
+ */
+static int dlog_check_limiter(log_id_t log_id, int prio, const char *tag)
+{
+       if (!debugmode && prio <= DLOG_DEBUG)
+               return DLOG_ERROR_NOT_PERMITTED;
+
        if (dynamic_config)
                __dynamic_config_update();
 
@@ -242,15 +255,20 @@ static int __write_to_log(log_id_t log_id, int prio, const char *tag, const char
 {
        char buf[LOG_MAX_PAYLOAD_SIZE];
 
+       int ret = dlog_check_validity(log_id, prio, tag);
+       if (ret < 0)
+               return ret;
+
        __dlog_init();
 
        /* if limiter_apply_to_all_buffers config variable is set to 1,
         * check_should_log value does not matter and the entry is always
         * tested against all conditions, i.e. limiter rules
         */
-       int ret = (limiter_apply_to_all_buffers ? true : check_should_log) ? dlog_should_log(log_id, prio, tag) : 0;
+       ret = (check_should_log || limiter_apply_to_all_buffers) ? dlog_check_limiter(log_id, prio, tag) : 0;
+
        if (ret < 0)
-               return ret;
+               return DLOG_ERROR_NONE;
 
        vsnprintf(buf, sizeof buf, fmt, ap);