4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #include "app_signal.h"
26 static struct sigaction old_sigchild;
27 static DBusConnection *bus = NULL;
29 static inline void __socket_garbage_collector()
32 struct dirent *dentry;
33 char tmp[MAX_LOCAL_BUFSZ];
35 dp = opendir(AUL_SOCK_PREFIX);
39 while ((dentry = readdir(dp)) != NULL) {
40 if (!isdigit(dentry->d_name[0]))
43 snprintf(tmp, MAX_LOCAL_BUFSZ, "/proc/%s", dentry->d_name);
44 if (access(tmp, F_OK) < 0) { /* Flawfinder: ignore */
45 snprintf(tmp, MAX_LOCAL_BUFSZ, "%s/%s", AUL_SOCK_PREFIX,
54 static inline int __send_app_dead_signal(int dead_pid)
61 message = dbus_message_new_signal(AUL_DBUS_PATH,
62 AUL_DBUS_SIGNAL_INTERFACE,
63 AUL_DBUS_APPDEAD_SIGNAL);
65 if (dbus_message_append_args(message,
66 DBUS_TYPE_UINT32, &dead_pid,
67 DBUS_TYPE_INVALID) == FALSE) {
68 _E("Failed to load data error");
72 if (dbus_connection_send(bus, message, NULL) == FALSE) {
73 _E("dbus send error");
77 dbus_connection_flush(bus);
78 dbus_message_unref(message);
80 _D("send dead signal done\n");
85 static int __sigchild_action(void *data)
88 char buf[MAX_LOCAL_BUFSZ];
90 dead_pid = (pid_t) data;
94 __send_app_dead_signal(dead_pid);
96 snprintf(buf, MAX_LOCAL_BUFSZ, "%s/%d", AUL_SOCK_PREFIX, dead_pid);
99 __socket_garbage_collector();
104 static void __launchpad_sig_child(int signo, siginfo_t *info, void *data)
111 child_pgid = getpgid(info->si_pid);
112 _D("dead_pid = %d pgid = %d", info->si_pid, child_pgid);
114 while ((child_pid = waitpid(-1, &status, WNOHANG)) > 0) {
115 if (child_pid == child_pgid)
116 killpg(child_pgid, SIGKILL);
117 __sigchild_action((void *)child_pid);
123 static inline int __signal_init(void)
126 for (i = 0; i < _NSIG; i++) {
128 /* controlled by sys-assert package*/
146 static inline int __signal_set_sigchld(void)
148 struct sigaction act;
151 dbus_error_init(&error);
152 dbus_threads_init_default();
153 bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
155 _E("Failed to connect to the D-BUS daemon: %s", error.message);
156 dbus_error_free(&error);
159 /* TODO: if process stop mechanism is included,
160 should be modified (SA_NOCLDSTOP)*/
161 act.sa_handler = NULL;
162 act.sa_sigaction = __launchpad_sig_child;
163 sigemptyset(&act.sa_mask);
164 act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
166 if (sigaction(SIGCHLD, &act, &old_sigchild) < 0)
172 static inline int __signal_unset_sigchld(void)
174 struct sigaction dummy;
179 dbus_connection_close(bus);
180 if (sigaction(SIGCHLD, &old_sigchild, &dummy) < 0)
186 static inline int __signal_fini(void)
188 #ifndef PRELOAD_ACTIVATE
190 for (i = 0; i < _NSIG; i++)