summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xinclude/app_signal.h4
-rwxr-xr-xinclude/simple_util.h12
-rwxr-xr-xsrc/launchpad.c85
-rwxr-xr-xsrc/sigchild.h85
4 files changed, 94 insertions, 92 deletions
diff --git a/include/app_signal.h b/include/app_signal.h
index f84a54c..31c7267 100755
--- a/include/app_signal.h
+++ b/include/app_signal.h
@@ -28,9 +28,9 @@
#include <dbus/dbus-glib-lowlevel.h>
#define AUL_DBUS_PATH "/aul/dbus_handler"
-#define AUL_DBUS_SIGNAL_INTERFACE "com.samsung.aul.signal"
+#define AUL_DBUS_SIGNAL_INTERFACE "org.tizen.aul.signal"
#define AUL_DBUS_APPDEAD_SIGNAL "app_dead"
-#define AUL_DBUS_APPLAUNCH_SIGNAL "app_launch"
+#define AUL_DBUS_APPLAUNCH_SIGNAL "app_launch"
#define OPT_VALGRIND_LOGFILE "--log-file="
#define OPT_VALGRIND_LOGFILE_FIXED "--log-file=/tmp/valgrind_result.txt"
diff --git a/include/simple_util.h b/include/simple_util.h
index 83f554d..b9f3b85 100755
--- a/include/simple_util.h
+++ b/include/simple_util.h
@@ -27,18 +27,10 @@
#include <ctype.h>
#include <dlog.h>
-#ifdef LAUNCHPAD_LOG
+#ifdef LOG_TAG
#undef LOG_TAG
-#define LOG_TAG "AUL_PAD"
-#else
-#undef LOG_TAG
-#define LOG_TAG "AUL"
-#endif
-#ifdef AMD_LOG
-#undef LOG_TAG
-#define LOG_TAG "AUL_AMD"
#endif
-
+#define LOG_TAG "DEBUG_LAUNCHPAD"
#define MAX_LOCAL_BUFSZ 128
#define MAX_PID_STR_BUFSZ 20
diff --git a/src/launchpad.c b/src/launchpad.c
index f823944..8aa8eef 100755
--- a/src/launchpad.c
+++ b/src/launchpad.c
@@ -67,7 +67,6 @@
#endif
#define _static_ static inline
-#define POLLFD_MAX 1
#define SQLITE_FLUSH_MAX (1048576) /* (1024*1024) */
#define AUL_POLL_CNT 15
#define AUL_PR_NAME 16
@@ -103,6 +102,12 @@
#define CAPABILITY_GET_ORIGINAL 0
#define CAPABILITY_SET_INHERITABLE 1
+enum {
+ LAUNCHPAD_FD,
+ SIGCHLD_FD,
+ POLLFD_MAX,
+};
+
static int need_to_set_inh_cap_after_fork = 0;
static char *launchpad_cmdline;
static int initialized = 0;
@@ -1134,11 +1139,11 @@ void __launchpad_main_loop(int main_fd)
close(clifd);
close(main_fd);
- __signal_unset_sigchld();
- __signal_fini();
+ __signal_unblock_sigchld();
+ __close_dbus_connection();
- snprintf(sock_path, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX
- , getpid());
+ snprintf(sock_path, UNIX_PATH_MAX, "%s/%d",
+ AUL_SOCK_PREFIX, getpid());
unlink(sock_path);
if(__stdout_stderr_redirection(__get_caller_pid(kb))) {
@@ -1183,12 +1188,8 @@ end:
__send_result_to_caller(clifd, pid);
if (pid > 0) {
- if (is_real_launch) {
- /*TODO: retry*/
- __signal_block_sigchld();
- __send_app_launch_signal(pid);
- __signal_unblock_sigchld();
- }
+ if (is_real_launch)
+ __send_app_launch_signal(pid, pkg_name);
}
if (menu_info != NULL)
@@ -1259,10 +1260,6 @@ int __launchpad_pre_init(int argc, char **argv)
}
#endif
- __preload_init(argc, argv);
-
- __preexec_init(argc, argv);
-
return fd;
}
@@ -1277,9 +1274,6 @@ int __launchpad_post_init()
return 0;
}
- if (__signal_set_sigchld() < 0)
- return -1;
-
initialized++;
return 0;
@@ -1287,9 +1281,11 @@ int __launchpad_post_init()
int main(int argc, char **argv)
{
- int main_fd;
+ int main_fd = -1;
+ int sigchld_fd = -1;
struct pollfd pfds[POLLFD_MAX];
- int i;
+ struct signalfd_siginfo siginfo;
+ ssize_t s;
__adjust_process_capability(CAPABILITY_GET_ORIGINAL);
@@ -1300,9 +1296,19 @@ int main(int argc, char **argv)
exit(-1);
}
- pfds[0].fd = main_fd;
- pfds[0].events = POLLIN;
- pfds[0].revents = 0;
+ pfds[LAUNCHPAD_FD].fd = main_fd;
+ pfds[LAUNCHPAD_FD].events = POLLIN;
+ pfds[LAUNCHPAD_FD].revents = 0;
+
+ sigchld_fd = __signal_get_sigchld_fd();
+ if (sigchld_fd == -1) {
+ _E("Failed to get sigchld fd");
+ goto error;
+ }
+
+ pfds[SIGCHLD_FD].fd = sigchld_fd;
+ pfds[SIGCHLD_FD].events = POLLIN;
+ pfds[SIGCHLD_FD].revents = 0;
while (1) {
if (poll(pfds, POLLFD_MAX, -1) < 0)
@@ -1310,16 +1316,35 @@ int main(int argc, char **argv)
/* init with concerning X & EFL (because of booting
sequence problem)*/
- if (__launchpad_post_init() < 0) {
- _E("launcpad post init failed");
- exit(-1);
+ __launchpad_post_init();
+
+ if ((pfds[SIGCHLD_FD].revents & POLLIN) != 0) {
+ do {
+ s = read(pfds[SIGCHLD_FD].fd, &siginfo, sizeof(struct signalfd_siginfo));
+ if (s == 0)
+ break;
+
+ if (s != sizeof(struct signalfd_siginfo)) {
+ _E("error reading sigchld info");
+ break;
+ }
+
+ __launchpad_process_sigchild(&siginfo);
+ } while (s > 0);
}
- for (i = 0; i < POLLFD_MAX; i++) {
- if ((pfds[i].revents & POLLIN) != 0) {
- __launchpad_main_loop(pfds[i].fd);
- }
+ if ((pfds[LAUNCHPAD_FD].revents & POLLIN) != 0) {
+ _E("pfds[LAUNCHPAD_FD].revents & POLLIN");
+ __launchpad_main_loop(pfds[LAUNCHPAD_FD].fd);
}
}
+
+error:
+ if (main_fd != -1)
+ close(main_fd);
+ if (sigchld_fd != -1)
+ close(sigchld_fd);
+
+ return 0;
}
diff --git a/src/sigchild.h b/src/sigchild.h
index 8f1bf3c..cab7d37 100755
--- a/src/sigchild.h
+++ b/src/sigchild.h
@@ -22,10 +22,11 @@
#include <pthread.h>
#include <sys/smack.h>
+#include <sys/signalfd.h>
+
#include "app_signal.h"
#include "fileutils.h"
-static struct sigaction old_sigchild;
static DBusConnection *bus = NULL;
sigset_t oldmask;
static int gdbserver_pid;
@@ -87,7 +88,7 @@ static inline int __send_app_dead_signal(int dead_pid)
return 0;
}
-static inline int __send_app_launch_signal(int launch_pid)
+static inline int __send_app_launch_signal(int launch_pid, const char *app_id)
{
DBusMessage *message;
@@ -99,8 +100,9 @@ static inline int __send_app_launch_signal(int launch_pid)
AUL_DBUS_APPLAUNCH_SIGNAL);
if (dbus_message_append_args(message,
- DBUS_TYPE_UINT32, &launch_pid,
- DBUS_TYPE_INVALID) == FALSE) {
+ DBUS_TYPE_UINT32, &launch_pid,
+ DBUS_TYPE_STRING, &app_id,
+ DBUS_TYPE_INVALID) == FALSE) {
_E("Failed to load data error");
return -1;
}
@@ -145,19 +147,17 @@ static int __sigchild_action(void *data)
pid_t dead_pid;
char buf[MAX_LOCAL_BUFSZ];
- dead_pid = (pid_t) data;
+ dead_pid = (pid_t)data;
if (dead_pid <= 0)
goto end;
- /* send app pid instead of gdbserver pid */
- if(dead_pid == gdbserver_pid)
- dead_pid = gdbserver_app_pid;
+ /* send app pid instead of gdbserver pid */
+ if (dead_pid == gdbserver_pid)
+ dead_pid = gdbserver_app_pid;
/* valgrind xml file */
- if(access(PATH_VALGRIND_XMLFILE,F_OK)==0)
- {
+ if (access(PATH_VALGRIND_XMLFILE,F_OK) == 0)
__chmod_chsmack_toread(PATH_VALGRIND_XMLFILE);
- }
__send_app_dead_signal(dead_pid);
@@ -165,18 +165,18 @@ static int __sigchild_action(void *data)
unlink(buf);
__socket_garbage_collector();
- end:
+end:
return 0;
}
-static void __launchpad_sig_child(int signo, siginfo_t *info, void *data)
+static void __launchpad_process_sigchild(struct signalfd_siginfo *info)
{
int status;
pid_t child_pid;
pid_t child_pgid;
- child_pgid = getpgid(info->si_pid);
- _D("dead_pid = %d pgid = %d", info->si_pid, child_pgid);
+ child_pgid = getpgid(info->ssi_pid);
+ _D("dead_pid = %d pgid = %d", info->ssi_pid, child_pgid);
while ((child_pid = waitpid(-1, &status, WNOHANG)) > 0) {
if (child_pid == child_pgid)
@@ -210,66 +210,51 @@ static inline int __signal_init(void)
return 0;
}
-static inline int __signal_set_sigchld(void)
+static inline int __signal_get_sigchld_fd(void)
{
- struct sigaction act;
+ sigset_t mask;
+ int sfd;
DBusError error;
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGCHLD);
+
+ if (sigprocmask(SIG_BLOCK, &mask, &oldmask) == -1)
+ _E("Failed to sigprocmask");
+
+ sfd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
+ if (sfd == -1) {
+ _E("Failed to create signalfd for SIGCHLD");
+ return -1;
+ }
+
dbus_error_init(&error);
dbus_threads_init_default();
bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
if (!bus) {
_E("Failed to connect to the D-BUS daemon: %s", error.message);
dbus_error_free(&error);
+ close(sfd);
return -1;
}
- /* TODO: if process stop mechanism is included,
- should be modified (SA_NOCLDSTOP)*/
- act.sa_handler = NULL;
- act.sa_sigaction = __launchpad_sig_child;
- sigemptyset(&act.sa_mask);
- act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
-
- if (sigaction(SIGCHLD, &act, &old_sigchild) < 0)
- return -1;
- return 0;
+ return sfd;
}
-static inline int __signal_unset_sigchld(void)
+static inline int __close_dbus_connection(void)
{
- struct sigaction dummy;
-
if (bus == NULL)
return 0;
dbus_connection_close(bus);
- if (sigaction(SIGCHLD, &old_sigchild, &dummy) < 0)
- return -1;
-
- return 0;
-}
-
-static inline int __signal_block_sigchld(void)
-{
- sigset_t newmask;
-
- sigemptyset(&newmask);
- sigaddset(&newmask, SIGCHLD);
-
- if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
- _E("SIG_BLOCK error");
- return -1;
- }
-
- _D("SIGCHLD blocked");
+ dbus_connection_unref(bus);
return 0;
}
static inline int __signal_unblock_sigchld(void)
{
- if(sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
+ if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
_E("SIG_SETMASK error");
return -1;
}