From: Hwankyu Jhun Date: Thu, 2 Feb 2017 06:42:55 +0000 (+0900) Subject: Create socket link for debug mode X-Git-Tag: accepted/tizen/common/20170203.161757~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F68%2F112668%2F5;p=platform%2Fcore%2Fappfw%2Faul-1.git Create socket link for debug mode When the application is launched by the debugger, the socket link should be created for re-launching the application. Until now, the running application by the debugger could not get the re-launch request. Requires: - https://review.tizen.org/gerrit/#/c/112729/ Change-Id: I1f25f342ef3eeac3dae3e66749fe9a11f7d8851c Signed-off-by: Hwankyu Jhun --- diff --git a/src/aul_sock.c b/src/aul_sock.c index 6003511..93f67fa 100644 --- a/src/aul_sock.c +++ b/src/aul_sock.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -115,6 +116,30 @@ API int aul_sock_set_sock_option(int fd, int cli) return 0; } +static int __create_socket_dir(int pid, uid_t uid) +{ + char path[PATH_MAX]; + + if (uid < REGULAR_UID_MIN) + snprintf(path, sizeof(path), "/run/aul/daemons/%d", uid); + else + snprintf(path, sizeof(path), "/run/aul/apps/%d/%d", uid, pid); + + if (mkdir(path, 0700) != 0) { + if (errno == EEXIST) { + if (access(path, R_OK) != 0) { + _E("Failed to acess %s directory", path); + return -1; + } + } else { + _E("Failed to create %s directory", path); + return -1; + } + } + + return 0; +} + static void __create_socket_path(char *path_buf, int size, int pid, uid_t uid) { if (uid < REGULAR_UID_MIN) { @@ -126,13 +151,28 @@ static void __create_socket_path(char *path_buf, int size, int pid, uid_t uid) } } +static void __create_socket_link(const char *socket_path, int pid, uid_t uid) +{ + char path[PATH_MAX]; + + if (__create_socket_dir(pid, uid) < 0) + return; + + __create_socket_path(path, sizeof(path), pid, uid); + if (link(socket_path, path) < 0) { + if (errno == EEXIST) + _D("path(%s) - already exists", path); + else + _E("path(%s) - unknown create error", path); + } +} + API int aul_sock_create_server(int pid, uid_t uid) { struct sockaddr_un saddr; - struct sockaddr_un p_saddr; int fd; - int ret; - int pgid; + int env_pid = -1; + char *env_str; fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); /* support above version 2.6.27*/ @@ -152,29 +192,9 @@ API int aul_sock_create_server(int pid, uid_t uid) memset(&saddr, 0, sizeof(saddr)); saddr.sun_family = AF_UNIX; - if (uid < REGULAR_UID_MIN) { - snprintf(saddr.sun_path, sizeof(saddr.sun_path), - "/run/aul/daemons/%d", uid); - - } else { - snprintf(saddr.sun_path, sizeof(saddr.sun_path), - "/run/aul/apps/%d/%d", uid, pid); - } - - ret = mkdir(saddr.sun_path, 0700); - if (ret != 0) { - if (errno == EEXIST) { - if (access(saddr.sun_path, R_OK) != 0) { - _E("Failed to access %s directory", - saddr.sun_path); - close(fd); - return -1; - } - } else { - _E("Failed to create %s directory", saddr.sun_path); - close(fd); - return -1; - } + if (__create_socket_dir(pid, uid) < 0) { + close(fd); + return -1; } __create_socket_path(saddr.sun_path, sizeof(saddr.sun_path), pid, uid); @@ -216,18 +236,14 @@ API int aul_sock_create_server(int pid, uid_t uid) return -1; } - /* support app launched by shell script */ + /* Create socket link */ if (pid > 0) { - pgid = getpgid(pid); - if (pgid > 1) { - __create_socket_path(saddr.sun_path, sizeof(saddr.sun_path), pgid, uid); - 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"); - } - } + env_str = getenv("AUL_PID"); + if (env_str && isdigit(env_str[0])) + env_pid = atoi(env_str); + + if (env_pid > 1 && pid != env_pid) + __create_socket_link(saddr.sun_path, env_pid, uid); } return fd;