diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2018-05-03 10:55:13 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2018-05-03 10:55:13 +0900 |
commit | b18c37a5b0b4948a9af41d30e57715b930c97e3d (patch) | |
tree | a0045a423e6104a018cac2d56d1085de12d5fa87 | |
parent | 1f78269af76e525b3cba50ac3539e3b79f97af3f (diff) | |
download | aul-1-b18c37a5b0b4948a9af41d30e57715b930c97e3d.tar.gz aul-1-b18c37a5b0b4948a9af41d30e57715b930c97e3d.tar.bz2 aul-1-b18c37a5b0b4948a9af41d30e57715b930c97e3d.zip |
Delete socket path
While calling aul_finalize(), the aul library removes the socket path.
Change-Id: Idc52326197c76f4abb2186b452d4099cc87bfab5
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | include/aul_sock.h | 6 | ||||
-rw-r--r-- | src/aul_sock.c | 55 | ||||
-rwxr-xr-x | src/launch.c | 6 |
3 files changed, 64 insertions, 3 deletions
diff --git a/include/aul_sock.h b/include/aul_sock.h index c1074713..e305cf18 100644 --- a/include/aul_sock.h +++ b/include/aul_sock.h @@ -112,5 +112,9 @@ int aul_sock_recv_pkt_with_cb(int fd, /* * This API in only for Appfw internally. */ -API int aul_sock_recv_result_with_fd(int fd); +int aul_sock_recv_result_with_fd(int fd); +/* + * This API in only for Appfw internally. + */ +int aul_sock_destroy_server(int fd); diff --git a/src/aul_sock.c b/src/aul_sock.c index 70ab1ce1..dd2f4cd3 100644 --- a/src/aul_sock.c +++ b/src/aul_sock.c @@ -979,3 +979,58 @@ retry_recv: return res; } +static void __delete_dir(const char *path) +{ + DIR *dp; + struct dirent *dentry = NULL; + char buf[PATH_MAX]; + struct stat statbuf; + int ret; + + if (path == NULL) + return; + + dp = opendir(path); + if (dp == NULL) + return; + + while ((dentry = readdir(dp)) != NULL) { + if (!strcmp(dentry->d_name, ".") || + !strcmp(dentry->d_name, "..")) + continue; + + snprintf(buf, sizeof(buf), "%s/%s", path, dentry->d_name); + ret = stat(buf, &statbuf); + if (ret == 0) { + if (S_ISDIR(statbuf.st_mode)) + __delete_dir(buf); + else + unlink(buf); + } + } + + rmdir(path); + closedir(dp); +} + +API int aul_sock_destroy_server(int fd) +{ + char path[PATH_MAX]; + + if (fd > 3) + close(fd); + + if (getuid() >= REGULAR_UID_MIN) { + snprintf(path, sizeof(path), + "/run/aul/apps/%u/%d", + getuid(), getpid()); + __delete_dir(path); + } else { + snprintf(path, sizeof(path), + "/run/aul/daemons/%u/.app-sock-%d", + getuid(), getpid()); + unlink(path); + } + + return 0; +} diff --git a/src/launch.c b/src/launch.c index f52abf91..b87c722e 100755 --- a/src/launch.c +++ b/src/launch.c @@ -623,8 +623,10 @@ API void aul_finalize() { aul_launch_fini(); - if (aul_initialized) - close(aul_fd); + if (aul_initialized) { + aul_sock_destroy_server(aul_fd); + aul_fd = -1; + } return; } |