Set debugmode by checking debugmode file 21/88421/2
authorKichan Kwon <k_c.kwon@samsung.com>
Mon, 19 Sep 2016 02:39:35 +0000 (11:39 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Tue, 20 Sep 2016 14:22:06 +0000 (23:22 +0900)
- If debugmode is enabled, fatal log can be written
- Else, process writing fatal log is aborted

Change-Id: I4c4928f9ff3041ba103908179c563a172f3a737f
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
configure.ac
packaging/dlog.spec
src/libdlog/log.c

index b5d1f95..d59834f 100755 (executable)
@@ -62,14 +62,6 @@ AC_ARG_ENABLE([debug_enable],
        AS_HELP_STRING([--enable-debug_enable Turn on debug_enable]),
                [debug_enable=yes],
            debug_enable=no)
-# check for fatal_on
-AC_ARG_ENABLE([fatal_on],
-       AS_HELP_STRING([--enable-fatal_on Turn on fatal assertion]),
-               [fatal_on=yes],
-           fatal_on=no)
-if test "x$fatal_on" = "xyes" ; then
-       DEBUG_CFLAGS+=" -DFATAL_ON"
-fi
 AC_SUBST(DEBUG_CFLAGS)
 # Checks for libraries.
 # Checks for header files.
index d2ce68d..add849a 100755 (executable)
@@ -84,7 +84,6 @@ cp %{SOURCE101} .
 cp %{SOURCE102} .
 %autogen --disable-static
 %configure --disable-static \
-                       --enable-fatal_on \
                %if %{?backend_pipe} == ON
                        --enable-pipe \
                %endif
index be3dc2b..063787e 100755 (executable)
 #include <logcommon.h>
 #include "loglimiter.h"
 #include "logconfig.h"
-#ifdef FATAL_ON
 #include <assert.h>
-#endif
+#include <unistd.h>
+
+#define DEBUGMODE_FILE TZ_SYS_ETC"/.debugmode"
 
 /**
  * @brief Points to a function which writes a log message
@@ -43,6 +44,7 @@ extern void __dlog_init_backend();
 
 static int limiter;
 static int plog;
+static int debugmode;
 
 /**
  * @brief Null handler
@@ -134,6 +136,7 @@ static void __dlog_init(void)
        write_to_log = __write_to_log_null;
        __configure();
        __dlog_init_backend();
+       debugmode = access(DEBUGMODE_FILE, F_OK) != -1 ? 1 : 0;
        pthread_mutex_unlock(&log_init_lock);
 }
 
@@ -144,9 +147,7 @@ static void __dlog_init(void)
  */
 void __dlog_fatal_assert(int prio)
 {
-#ifdef FATAL_ON
-       assert(!(prio == DLOG_FATAL));
-#endif
+       assert(debugmode || !(prio == DLOG_FATAL));
 }
 
 /**
@@ -218,9 +219,7 @@ int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, v
 
        vsnprintf(buf, LOG_MAX_SIZE, fmt, ap);
        ret = write_to_log(log_id, prio, tag, buf);
-#ifdef FATAL_ON
        __dlog_fatal_assert(prio);
-#endif
        return ret;
 }
 
@@ -252,9 +251,7 @@ int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ..
        va_end(ap);
 
        ret = write_to_log(log_id, prio, tag, buf);
-#ifdef FATAL_ON
        __dlog_fatal_assert(prio);
-#endif
        return ret;
 }