Delete socket path 84/177684/1
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 3 May 2018 01:55:13 +0000 (10:55 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 3 May 2018 01:55:13 +0000 (10:55 +0900)
While calling aul_finalize(), the aul library removes the socket path.

Change-Id: Idc52326197c76f4abb2186b452d4099cc87bfab5
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/aul_sock.h
src/aul_sock.c
src/launch.c

index c107471..e305cf1 100644 (file)
@@ -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);
index 70ab1ce..dd2f4cd 100644 (file)
@@ -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;
+}
index f52abf9..b87c722 100755 (executable)
@@ -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;
 }