Update SMACK, Fix a crash of terminating sequence, etc, ...
[apps/livebox/data-provider-master.git] / src / dead_monitor.c
1 /*
2  * Copyright 2013  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (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://floralicense.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 #include <stdio.h>
18 #include <unistd.h>
19
20 #include <gio/gio.h>
21 #include <packet.h>
22 #include <com-core.h>
23 #include <dlog.h>
24
25 #include <Eina.h>
26
27 #include "slave_life.h"
28 #include "client_life.h"
29 #include "instance.h"
30 #include "fault_manager.h"
31 #include "util.h"
32 #include "debug.h"
33 #include "liveinfo.h"
34 #include "conf.h"
35
36 static int evt_cb(int handle, void *data)
37 {
38         struct slave_node *slave;
39         struct client_node *client;
40         struct liveinfo *liveinfo;
41
42         slave = slave_find_by_rpc_handle(handle);
43         if (slave) {
44                 if (slave_pid(slave) != (pid_t)-1) {
45                         if (slave_state(slave) == SLAVE_REQUEST_TO_TERMINATE)
46                                 slave = slave_deactivated(slave);
47                         else if (slave_state(slave) != SLAVE_TERMINATED)
48                                 slave = slave_deactivated_by_fault(slave);
49                 }
50
51                 DbgPrint("Slave pointer: %p (0 means deleted)\n", slave);
52                 return 0;
53         }
54
55         client = client_find_by_rpc_handle(handle);
56         if (client) {
57                 if (client_pid(client) != (pid_t)-1)
58                         client = client_deactivated_by_fault(client);
59
60                 DbgPrint("Client pointer: %p (0 means deleted)\n", client);
61                 return 0;
62         }
63
64         liveinfo = liveinfo_find_by_handle(handle);
65         if (liveinfo) {
66                 liveinfo_destroy(liveinfo);
67                 return 0;
68         }
69
70         return 0;
71 }
72
73 HAPI int dead_init(void)
74 {
75         com_core_add_event_callback(CONNECTOR_DISCONNECTED, evt_cb, NULL);
76         return 0;
77 }
78
79 HAPI int dead_fini(void)
80 {
81         com_core_del_event_callback(CONNECTOR_DISCONNECTED, evt_cb, NULL);
82         return 0;
83 }
84
85 /* End of a file */