From: Boram Park Date: Wed, 21 Feb 2018 07:09:04 +0000 (+0900) Subject: log: restore stdout when set NULL. X-Git-Tag: submit/tizen/20180227.014049~51 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d7cab3249db011494da88586a9488de357194b15;p=platform%2Fcore%2Fuifw%2Flibtdm.git log: restore stdout when set NULL. Change-Id: I25934b33f8468e55fdd063068f868fafab81f948 --- diff --git a/common/tdm_log.c b/common/tdm_log.c index 3ddcda12..1befbfb8 100644 --- a/common/tdm_log.c +++ b/common/tdm_log.c @@ -69,6 +69,8 @@ static pthread_mutex_t log_lock; unsigned int tdm_log_debug_level = TDM_LOG_LEVEL_INFO; +static int stdout_fd = -1; + EXTERN void tdm_log_enable_color(unsigned int enable) { @@ -105,26 +107,40 @@ tdm_log_set_assert_level(int level) EXTERN void tdm_log_set_path(const char *path) { - char fd_name[TDM_PATH_LEN]; - int log_fd = -1; - FILE *log_fl; + if (!path) { + if (stdout_fd != -1) { + fflush(stdout); + close(STDOUT_FILENO); + dup2(stdout_fd, STDOUT_FILENO); + close(stdout_fd); + stdout_fd = -1; + } + } else { + char fd_name[TDM_PATH_LEN]; + int log_fd = -1; + FILE *log_fl; - snprintf(fd_name, TDM_PATH_LEN, "%s", path); + snprintf(fd_name, TDM_PATH_LEN, "%s", path); - log_fl = fopen(fd_name, "a"); - if (!log_fl) { - TDM_ERR("failed: open file(%s)\n", fd_name); - return; - } + log_fl = fopen(fd_name, "a"); + if (!log_fl) { + TDM_ERR("failed: open file(%s)\n", fd_name); + return; + } - fflush(stdout); - close(STDOUT_FILENO); + if (stdout_fd == -1) { + fflush(stdout); + stdout_fd = dup(STDOUT_FILENO); + TDM_RETURN_IF_FAIL(stdout_fd != -1); + } - setvbuf(log_fl, NULL, _IOLBF, 512); - log_fd = fileno(log_fl); + setvbuf(log_fl, NULL, _IOLBF, 512); + log_fd = fileno(log_fl); - dup2(log_fd, STDOUT_FILENO); - fclose(log_fl); + close(STDOUT_FILENO); + dup2(log_fd, STDOUT_FILENO); + fclose(log_fl); + } } EXTERN void