[FEATURE] Implement kernel -> user connection
[platform/core/system/swap-manager.git] / daemon / da_debug.c
1 /*
2  *  DA manager
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
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>
13  *
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
17  *
18  * http://www.apache.org/licenses/LICENSE-2.0
19  *
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.
25  *
26  * Contributors:
27  * - S-Core Co., Ltd
28  * - Samsung RnD Institute Russia
29  *
30  */
31 #define _GNU_SOURCE
32 #include <stdio.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <unistd.h>
37
38 #include "daemon.h"
39
40 #define DEBUG_LOGFILE           "/tmp/daemonlog.da"
41
42 #if DEBUG
43 static inline void close_on_exec_dup(int old, int new)
44 {
45         dup2(old, new);
46         fcntl(new, F_SETFD, fcntl(new, F_GETFD) | FD_CLOEXEC);
47 }
48
49 void initialize_log(void)
50 {
51         int fd = open(DEBUG_LOGFILE, O_WRONLY | O_CREAT | O_TRUNC, 0777);
52         if (fd > 0) {
53                 close_on_exec_dup(fd, 1);
54                 close_on_exec_dup(fd, 2);
55
56                 close(fd);
57         } else {
58                 close(1);
59                 close(2);
60         }
61
62         close(0);
63 }
64
65 #else
66 void initialize_log(void)
67 {
68 }
69 #endif