Remove socket link 09/266009/4
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 4 Nov 2021 03:07:31 +0000 (12:07 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 4 Nov 2021 06:25:51 +0000 (15:25 +0900)
While calling the aul_sock_destroy_server() function, the function
removes the socket link if that exists. This patch is to remove
the unnecessary link file.

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

index 4980758..6cd8dc7 100644 (file)
  */
 
 #define _GNU_SOURCE
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <stdbool.h>
-#include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <sys/xattr.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <ctype.h>
 #include <tzplatform_config.h>
 #include <glib.h>
 #include <vconf.h>
@@ -46,6 +47,8 @@ typedef struct app_pkt_header_s {
 } app_pkt_header_t;
 
 static int socket_timeout_initialized;
+static int socket_link_created;
+static char socket_link_path[108];
 
 static struct timeval tv = { 5, 200 * 1000 }; /* 5.2 */
 
@@ -217,7 +220,7 @@ API int aul_sock_set_sock_option(int fd, int cli)
 
 static int __create_socket_dir(int pid, uid_t uid)
 {
-       char path[PATH_MAX];
+       char path[108];
 
        if (uid < REGULAR_UID_MIN)
                snprintf(path, sizeof(path), "/run/aul/daemons/%d", uid);
@@ -252,7 +255,7 @@ 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];
+       char path[108];
 
        if (__create_socket_dir(pid, uid) < 0)
                return;
@@ -264,6 +267,9 @@ static void __create_socket_link(const char *socket_path, int pid, uid_t uid)
                else
                        _E("path(%s) - unknown create error", path);
        }
+
+       snprintf(socket_link_path, sizeof(socket_link_path), "%s", path);
+       socket_link_created = 1;
 }
 
 API int aul_sock_create_server(int pid, uid_t uid)
@@ -924,11 +930,21 @@ API int aul_sock_destroy_server(int fd)
                                "/run/aul/apps/%u/%d",
                                getuid(), getpid());
                __delete_dir(path);
+
+               if (socket_link_created) {
+                       __delete_dir(dirname(socket_link_path));
+                       socket_link_created = 0;
+               }
        } else {
                snprintf(path, sizeof(path),
                                "/run/aul/daemons/%u/.app-sock-%d",
                                getuid(), getpid());
                unlink(path);
+
+               if (socket_link_created) {
+                       unlink(socket_link_path);
+                       socket_link_created = 0;
+               }
        }
 
        return 0;