4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
8 * Jaewon Lim <jaewon81.lim@samsung.com>
9 * Woojin Jung <woojin2.jung@samsung.com>
10 * Juyoung Kim <j0.kim@samsung.com>
11 * Cherepanov Vitaliy <v.cherepanov@samsung.com>
12 * Nikita Kalyazin <n.kalyazin@samsung.com>
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
18 * http://www.apache.org/licenses/LICENSE-2.0
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
28 * - Samsung RnD Institute Russia
33 #include <sys/types.h>
42 #define DEBUG_LOGFILE "/tmp/daemonlog.da"
45 static inline int close_on_exec_dup(int old, int new)
49 if (dup2(old, new) != -1) {
50 unsigned long flags = fcntl(new, F_GETFD);
52 LOGE("can not get flags fd #%d errno <%d>\n", new,
57 if (fcntl(new, F_SETFD, flags | FD_CLOEXEC) == -1) {
58 LOGE("can not get flags fd #%d errno <%d>\n", new,
74 int initialize_log(void)
76 /* TODO fix problem with ecore and redirect stderr to DEBUG_LOGFILE back
79 * *** IN FUNCTION: _ecore_main_fdh_epoll_mark_active()
80 * ERR<2328>:ecore ecore.c:572 _ecore_magic_fail() Input handle has already been freed!
81 * ERR<2328>:ecore ecore.c:581 _ecore_magic_fail() *** NAUGHTY PROGRAMMER!!!
82 * *** SPANK SPANK SPANK!!!
89 if (remove(DEBUG_LOGFILE))
90 LOGE("remove(%s), return error, errno=%d\n",
91 DEBUG_LOGFILE, errno);
93 fd = open(DEBUG_LOGFILE, O_WRONLY | O_CREAT | O_TRUNC, 0777);
94 fd_null = open("/dev/null", O_WRONLY | O_CREAT | O_TRUNC, 0777);
96 if (fd != -1 && fd_null != -1) {
97 if (close_on_exec_dup(fd_null, 1) != 0 ||
98 close_on_exec_dup(fd, 2) != 0) {
99 LOGE("duplicate fd fail\n");
118 int initialize_log(void)