Tizen 2.4.0 rev3 SDK Public Release submit/tizen_2.3.1/20160302.054139
authorjk7744.park <jk7744.park@samsung.com>
Wed, 24 Feb 2016 11:53:14 +0000 (20:53 +0900)
committerjk7744.park <jk7744.park@samsung.com>
Wed, 24 Feb 2016 11:53:14 +0000 (20:53 +0900)
include/app_signal.h
src/app_sock.c
src/launchpad.c
src/sigchild.h

index 31c7267..f84a54c 100755 (executable)
@@ -28,9 +28,9 @@
 #include <dbus/dbus-glib-lowlevel.h>
 
 #define AUL_DBUS_PATH "/aul/dbus_handler"
-#define AUL_DBUS_SIGNAL_INTERFACE "org.tizen.aul.signal"
+#define AUL_DBUS_SIGNAL_INTERFACE "com.samsung.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"
index 60f366a..1029ab4 100755 (executable)
@@ -51,6 +51,7 @@ 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;
 
@@ -122,6 +123,22 @@ 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;
 }
 
@@ -132,7 +149,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) {
index bf456b8..8c81ff4 100755 (executable)
@@ -62,6 +62,7 @@
 #include <sys/capability.h>
 
 #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
 #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;
@@ -1142,15 +1137,16 @@ void __launchpad_main_loop(int main_fd)
 
                close(clifd);
                close(main_fd);
-               __signal_unblock_sigchld();
-               __close_dbus_connection();
+               __signal_unset_sigchld();
+               __signal_fini();
 
-               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");
@@ -1170,7 +1166,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 */
@@ -1192,8 +1188,12 @@ void __launchpad_main_loop(int main_fd)
        __send_result_to_caller(clifd, pid);
 
        if (pid > 0) {
-               if (is_real_launch)
+               if (is_real_launch) {
+                       /*TODO: retry*/
+                       __signal_block_sigchld();
                        __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,8 +1213,7 @@ 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)
@@ -1239,6 +1238,10 @@ int __launchpad_pre_init(int argc, char **argv)
                return -1;
        }
 
+       __preload_init(argc, argv);
+
+       __preexec_init(argc, argv);
+
        return fd;
 }
 
@@ -1253,6 +1256,9 @@ int __launchpad_post_init()
                return 0;
        }
 
+       if (__signal_set_sigchld() < 0)
+               return -1;
+
        initialized++;
 
        return 0;
@@ -1260,11 +1266,9 @@ int __launchpad_post_init()
 
 int main(int argc, char **argv)
 {
-       int main_fd = -1;
-       int sigchld_fd = -1;
+       int main_fd;
        struct pollfd pfds[POLLFD_MAX];
-       struct signalfd_siginfo siginfo;
-       ssize_t s;
+       int i;
 
        __adjust_process_capability(CAPABILITY_GET_ORIGINAL);
 
@@ -1275,53 +1279,26 @@ int main(int argc, char **argv)
                exit(-1);
        }
 
-       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;
+       pfds[0].fd = main_fd;
+       pfds[0].events = POLLIN;
+       pfds[0].revents = 0;
 
        while (1) {
                if (poll(pfds, POLLFD_MAX, -1) < 0)
                        continue;
 
-               /* 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);
+               /* init with concerning X & EFL (because of booting 
+               sequence problem)*/
+               if (__launchpad_post_init() < 0) {
+                       _E("launcpad post init failed");
+                       exit(-1);
                }
 
-               if ((pfds[LAUNCHPAD_FD].revents & POLLIN) != 0) {
-                       _D("pfds[LAUNCHPAD_FD].revents & POLLIN");
-                       __launchpad_main_loop(pfds[LAUNCHPAD_FD].fd);
+               for (i = 0; i < POLLFD_MAX; i++) {
+                       if ((pfds[i].revents & POLLIN) != 0) {
+                               __launchpad_main_loop(pfds[i].fd);
+                       }
                }
        }
-
-error:
-       if (main_fd != -1)
-               close(main_fd);
-       if (sigchld_fd != -1)
-               close(sigchld_fd);
-
-       return 0;
 }
+
index 2c49c20..900ebde 100755 (executable)
 
 #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;
@@ -170,14 +168,14 @@ static int __sigchild_action(void *data)
        return 0;
 }
 
-static void __launchpad_process_sigchld(struct signalfd_siginfo *info)
+static void __launchpad_sig_child(int signo, siginfo_t *info, void *data)
 {
        int status;
        pid_t child_pid;
        pid_t child_pgid;
 
-       child_pgid = getpgid(info->ssi_pid);
-       _D("dead_pid = %d pgid = %d", info->ssi_pid, child_pgid);
+       child_pgid = getpgid(info->si_pid);
+       _D("dead_pid = %d pgid = %d", info->si_pid, child_pgid);
 
        while ((child_pid = waitpid(-1, &status, WNOHANG)) > 0) {
                if (child_pid == child_pgid)
@@ -211,51 +209,66 @@ static inline int __signal_init(void)
        return 0;
 }
 
-static inline int __signal_get_sigchld_fd(void)
+static inline int __signal_set_sigchld(void)
 {
-       sigset_t mask;
-       int sfd;
+       struct sigaction act;
        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 sfd;
+       return 0;
 }
 
-static inline int __close_dbus_connection(void)
+static inline int __signal_unset_sigchld(void)
 {
+       struct sigaction dummy;
+
        if (bus == NULL)
                return 0;
 
        dbus_connection_close(bus);
-       dbus_connection_unref(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");
 
        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;
        }