Prepare a server socket of an application 57/73557/6 accepted/tizen/common/20160627.191230 accepted/tizen/ivi/20160623.121720 accepted/tizen/mobile/20160623.121618 accepted/tizen/tv/20160623.121631 accepted/tizen/wearable/20160623.121653 submit/tizen/20160622.081450
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 8 Jun 2016 12:38:28 +0000 (21:38 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 21 Jun 2016 22:53:21 +0000 (07:53 +0900)
- The debug-launchpad socket path is changed to
"/run/aul/daemons/<uid>/.debug-launchpad-sock".
- Requires
[aul] https://review.tizen.org/gerrit/#/c/73534/
[amd] https://review.tizen.org/gerrit/#/c/73537/

Change-Id: Ied141d714591b2528559adcf64e67f0a3be558a4
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/common.h
packaging/debug-launchpad.service
packaging/debug-launchpad.socket
src/common.c
src/debug-launchpad.c
src/signal_util.c

index b63e6c6..c01d142 100644 (file)
@@ -34,7 +34,7 @@
 #define _D(fmt, arg...) LOGD(fmt, ##arg)
 #define _W(fmt, arg...) LOGW(fmt, ##arg)
 
-#define SOCKET_PATH "/run/user"
+#define SOCKET_PATH "/run/aul"
 #define MAX_LOCAL_BUFSZ 128
 #define AUL_SOCK_MAXBUFF 131071
 
@@ -68,6 +68,7 @@ void _modify_bundle(bundle *kb, int caller_pid, appinfo_t *appinfo, int cmd);
 void _set_env(appinfo_t *app_info, bundle *kb);
 char **_create_argc_argv(bundle *kb, int *margc, const char *app_path);
 int _proc_check_cmdline_bypid(int pid);
+void _prepare_listen_sock(void);
 
 #endif /* __COMMON_H__ */
 
index 0b7d052..18af17f 100644 (file)
@@ -3,4 +3,8 @@ Description=Start the debug preload/preinit daemon
 After=dbus.service ac.service
 
 [Service]
+ExecStartPre=-/usr/bin/mkdir -p /run/aul/daemons/%U
+ExecStartPre=-/usr/bin/chmod 0777 /run/aul/daemons/%U
+ExecStartPre=-/usr/bin/mkdir -p /run/aul/apps/%U
+ExecStartPre=-/usr/bin/chmod 0777 /run/aul/apps/%U
 ExecStart=/usr/bin/debug_launchpad_preloading_preinitializing_daemon
index 4c5d81f..b1b7fd4 100644 (file)
@@ -2,7 +2,7 @@
 Description=The debug preload/preinit daemon Socket
 
 [Socket]
-ListenStream=/run/user/%U/.debug-launchpad-sock
+ListenStream=/run/aul/daemons/%U/.debug-launchpad-sock
 DirectoryMode=0777
 
 [Install]
index faed540..6b19d93 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -72,12 +73,15 @@ static int __create_sock_activation(void)
 }
 #endif /* _APPFW_FEATURE_SOCKET_ACTIVATION */
 
-static int __create_server_socket(void)
+static int __create_server_socket(bool is_app)
 {
        struct sockaddr_un saddr;
        int fd;
 
-       fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+       if (is_app)
+               fd = socket(AF_UNIX, SOCK_STREAM, 0);
+       else
+               fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
        /* support above version 2.6.27 */
        if (fd < 0) {
                if (errno == EINVAL) {
@@ -94,9 +98,16 @@ static int __create_server_socket(void)
 
        memset(&saddr, 0, sizeof(saddr));
        saddr.sun_family = AF_UNIX;
-       snprintf(saddr.sun_path, sizeof(saddr.sun_path),
-                       "%s/%d/.debug-launchpad-sock",
-                       SOCKET_PATH, getuid());
+
+       if (is_app) {
+               snprintf(saddr.sun_path, sizeof(saddr.sun_path),
+                               "%s/apps/%d/%d",
+                               SOCKET_PATH, getuid(), getpid());
+       } else {
+               snprintf(saddr.sun_path, sizeof(saddr.sun_path),
+                               "%s/daemons/%d/.debug-launchpad-sock",
+                               SOCKET_PATH, getuid());
+       }
        unlink(saddr.sun_path);
 
        if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
@@ -131,7 +142,7 @@ int _create_server_sock(void)
        fd = __create_sock_activation();
 #endif /* _APPFW_FEATURE_SOCKET_ACTIAVTION */
        if (fd < 0) {
-               fd = __create_server_socket();
+               fd = __create_server_socket(false);
                if (fd < 0) {
                        _E("server sock error %d", fd);
                        return -1;
@@ -775,3 +786,16 @@ int _proc_check_cmdline_bypid(int pid)
        return 0;
 }
 
+void _prepare_listen_sock(void)
+{
+       int fd;
+       char buf[12];
+
+       fd = __create_server_socket(true);
+       if (fd < 0)
+               return;
+
+       snprintf(buf, sizeof(buf), "%d", fd);
+       setenv("AUL_LISTEN_SOCK", buf, 1);
+}
+
index e38c4e7..4bf29ad 100644 (file)
@@ -126,6 +126,8 @@ static int __prepare_exec(const char *appid, const char *app_path,
                return -1;
        }
 
+       _prepare_listen_sock();
+
        memset(process_name, '\0', AUL_PR_NAME);
        snprintf(process_name, AUL_PR_NAME, "%s", file_name);
        prctl(PR_SET_NAME, process_name);
@@ -269,7 +271,7 @@ static int __start_process(const char *appid, const char *app_path,
                for (iter_fd = 3; iter_fd <= max_fd; iter_fd++)
                        close(iter_fd);
 
-               snprintf(sock_path, sizeof(sock_path), "%s/%d/%d",
+               snprintf(sock_path, sizeof(sock_path), "%s/apps/%d/%d",
                                SOCKET_PATH, getuid(), getpid());
                unlink(sock_path);
 
index f1cbc8e..8b1d62f 100644 (file)
@@ -44,7 +44,7 @@ static void __socket_garbage_collector(void)
        struct dirent *dentry;
        char path[PATH_MAX];
 
-       snprintf(path, sizeof(path), "%s/%d", SOCKET_PATH, getuid());
+       snprintf(path, sizeof(path), "%s/apps/%d", SOCKET_PATH, getuid());
        dp = opendir(path);
        if (dp == NULL)
                return;
@@ -55,7 +55,7 @@ static void __socket_garbage_collector(void)
 
                snprintf(path, sizeof(path), "/proc/%s", dentry->d_name);
                if (access(path, F_OK) != 0) { /* Flawfinder: ignore */
-                       snprintf(path, sizeof(path), "%s/%d/%s",
+                       snprintf(path, sizeof(path), "%s/apps/%d/%s",
                                        SOCKET_PATH, getuid(), dentry->d_name);
                        unlink(path);
                        continue;
@@ -146,7 +146,7 @@ static int __sigchild_action(pid_t dead_pid)
 
        _send_app_dead_signal(dead_pid);
 
-       snprintf(buf, MAX_LOCAL_BUFSZ, "%s/%d/%d",
+       snprintf(buf, MAX_LOCAL_BUFSZ, "%s/apps/%d/%d",
                                SOCKET_PATH, getuid(), dead_pid);
        unlink(buf);