apply FSL(Flora Software License)
[framework/system/system-server.git] / ss_sig_handler.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15 */
16
17
18 #include <stdio.h>
19 #include <sys/types.h>
20 #include <sys/wait.h>
21 #include "ss_core.h"
22
23 #define PRT_TRACE_ERR(format, args...) do { \
24         char buf[255];\
25         snprintf(buf, 255, format, ##args);\
26         write(2, buf, strlen(buf));\
27 } while (0);
28
29 #define PRT_TRACE(format, args...) do { \
30         char buf[255];\
31         snprintf(buf, 255, format, ##args);\
32         write(1, buf, strlen(buf));\
33 } while (0);
34
35 static struct sigaction sig_child_old_act;
36 static struct sigaction sig_pipe_old_act;
37
38 static void sig_child_handler(int signo, siginfo_t *info, void *data)
39 {
40         pid_t pid;
41         int status;
42
43         pid = waitpid(info->si_pid, &status, 0);
44         if (pid == -1) {
45                 PRT_TRACE_ERR("SIGCHLD received\n");
46                 return;
47         }
48
49         PRT_TRACE("sig child actend call - %d\n", info->si_pid);
50
51         ss_core_action_clear(info->si_pid);
52 }
53
54 static void sig_pipe_handler(int signo, siginfo_t *info, void *data)
55 {
56
57 }
58
59 void ss_signal_init()
60 {
61         struct sigaction sig_act;
62
63         sig_act.sa_handler = NULL;
64         sig_act.sa_sigaction = sig_child_handler;
65         sig_act.sa_flags = SA_SIGINFO;
66         sigemptyset(&sig_act.sa_mask);
67         sigaction(SIGCHLD, &sig_act, &sig_child_old_act);
68
69         sig_act.sa_handler = NULL;
70         sig_act.sa_sigaction = sig_pipe_handler;
71         sig_act.sa_flags = SA_SIGINFO;
72         sigemptyset(&sig_act.sa_mask);
73         sigaction(SIGPIPE, &sig_act, &sig_pipe_old_act);
74 }