Initialize Tizen 2.3
[framework/system/deviced.git] / src / core / sig-handler.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19
20 #include <stdio.h>
21 #include <sys/types.h>
22 #include <sys/wait.h>
23 #include <vconf.h>
24 #include "core.h"
25 #include "log.h"
26 #include "edbus-handler.h"
27 #include "display/poll.h"
28 #include "devices.h"
29 #include "common.h"
30
31 #if 0
32 #define _E(format, args...) do { \
33         char buf[255];\
34         snprintf(buf, 255, format, ##args);\
35         write(2, buf, strlen(buf));\
36 } while (0);
37
38 #define _D(format, args...) do { \
39         char buf[255];\
40         snprintf(buf, 255, format, ##args);\
41         write(1, buf, strlen(buf));\
42 } while (0);
43 #endif
44
45 static struct sigaction sig_child_old_act;
46 static struct sigaction sig_pipe_old_act;
47
48 static void sig_child_handler(int signo, siginfo_t *info, void *data)
49 {
50         pid_t pid;
51         int status;
52
53         if (!info || signo != SIGCHLD)
54                 return;
55
56         pid = waitpid(info->si_pid, &status, 0);
57         if (pid == -1) {
58                 _E("SIGCHLD received\n");
59                 return;
60         }
61
62         _D("sig child actend call - %d\n", info->si_pid);
63 }
64
65 static void sig_pipe_handler(int signo, siginfo_t *info, void *data)
66 {
67
68 }
69
70 static void signal_init(void *data)
71 {
72         struct sigaction sig_act;
73
74         sig_act.sa_handler = NULL;
75         sig_act.sa_sigaction = sig_child_handler;
76         sig_act.sa_flags = SA_SIGINFO;
77         sigemptyset(&sig_act.sa_mask);
78         sigaction(SIGCHLD, &sig_act, &sig_child_old_act);
79
80         sig_act.sa_handler = NULL;
81         sig_act.sa_sigaction = sig_pipe_handler;
82         sig_act.sa_flags = SA_SIGINFO;
83         sigemptyset(&sig_act.sa_mask);
84         sigaction(SIGPIPE, &sig_act, &sig_pipe_old_act);
85 }
86
87 static const struct device_ops signal_device_ops = {
88         .priority = DEVICE_PRIORITY_NORMAL,
89         .name     = "signal",
90         .init     = signal_init,
91 };
92
93 DEVICE_OPS_REGISTER(&signal_device_ops)