From ffc2e5955631c924506bb621d0f3382ed149924a Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Fri, 4 Mar 2016 13:10:06 +0900 Subject: [PATCH] Tizen 2.4.0 rev3 SDK Public Release --- include/app_signal.h | 4 +-- src/app_sock.c | 19 +--------- src/launchpad.c | 97 ++++++++++++++++++++++++++++++++-------------------- src/sigchild.h | 65 ++++++++++++++--------------------- 4 files changed, 89 insertions(+), 96 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 #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/src/app_sock.c b/src/app_sock.c index 1029ab4..60f366a 100755 --- a/src/app_sock.c +++ b/src/app_sock.c @@ -51,7 +51,6 @@ static inline void __set_sock_option(int fd, int cli) int __create_server_sock(int pid) { struct sockaddr_un saddr; - struct sockaddr_un p_saddr; int fd; mode_t orig_mask; @@ -123,22 +122,6 @@ int __create_server_sock(int pid) return -1; } - /* support app launched by shell script */ - /*if (pid != LAUNCHPAD_PID) { - int pgid; - pgid = getpgid(pid); - if (pgid > 1) { - snprintf(p_saddr.sun_path, UNIX_PATH_MAX, "%s/%d", - AUL_SOCK_PREFIX, pgid); - if (link(saddr.sun_path, p_saddr.sun_path) < 0) { - if (errno == EEXIST) - _D("pg path - already exists"); - else - _E("pg path - unknown create error"); - } - } - }*/ - return fd; } @@ -149,7 +132,7 @@ int __create_client_sock(int pid) int retry = 1; int ret = -1; - fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); /* support above version 2.6.27*/ if (fd < 0) { if (errno == EINVAL) { diff --git a/src/launchpad.c b/src/launchpad.c index 8c81ff4..bf456b8 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -62,7 +62,6 @@ #include #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 @@ -97,6 +96,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; @@ -1137,16 +1142,15 @@ 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))) { + if (__stdout_stderr_redirection(__get_caller_pid(kb))) _E("__stdout_stderr_redirection fail"); - } PERF("prepare exec - first done"); _D("lock up test log(no error) : prepare exec - first done"); @@ -1166,7 +1170,7 @@ void __launchpad_main_loop(int main_fd) exit(-1); } - if(is_gdbserver_launched) { + if (is_gdbserver_launched) { char buf[MAX_LOCAL_BUFSZ]; usleep(100 * 1000); /* 100ms sleep */ @@ -1188,12 +1192,8 @@ void __launchpad_main_loop(int main_fd) __send_result_to_caller(clifd, pid); if (pid > 0) { - if (is_real_launch) { - /*TODO: retry*/ - __signal_block_sigchld(); + if (is_real_launch) __send_app_launch_signal(pid); - __signal_unblock_sigchld(); - } } if (menu_info != NULL) @@ -1203,7 +1203,7 @@ void __launchpad_main_loop(int main_fd) bundle_free(kb); if (pkt != NULL) free(pkt); - if (appid != NULL) + if (appid != NULL) free(appid); /* Active Flusing for Daemon */ @@ -1213,7 +1213,8 @@ void __launchpad_main_loop(int main_fd) initialized = 1; } - if(poll_outputfile) __waiting_outputfile(); + if (poll_outputfile) + __waiting_outputfile(); } int __launchpad_pre_init(int argc, char **argv) @@ -1238,10 +1239,6 @@ int __launchpad_pre_init(int argc, char **argv) return -1; } - __preload_init(argc, argv); - - __preexec_init(argc, argv); - return fd; } @@ -1256,9 +1253,6 @@ int __launchpad_post_init() return 0; } - if (__signal_set_sigchld() < 0) - return -1; - initialized++; return 0; @@ -1266,9 +1260,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); @@ -1279,26 +1275,53 @@ 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) continue; - /* init with concerning X & EFL (because of booting - sequence problem)*/ - if (__launchpad_post_init() < 0) { - _E("launcpad post init failed"); - exit(-1); + /* init with concerning X & EFL (because of booting sequence problem) */ + __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_sigchld(&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) { + _D("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 900ebde..2c49c20 100755 --- a/src/sigchild.h +++ b/src/sigchild.h @@ -22,9 +22,11 @@ #include #include +#include + #include "app_signal.h" +#include "fileutils.h" -static struct sigaction old_sigchild; static DBusConnection *bus = NULL; sigset_t oldmask; static int gdbserver_pid; @@ -168,14 +170,14 @@ static int __sigchild_action(void *data) return 0; } -static void __launchpad_sig_child(int signo, siginfo_t *info, void *data) +static void __launchpad_process_sigchld(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) @@ -209,66 +211,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; } -- 2.7.4