Prevent issues fixes - wrt-launchpad-deamon
authorLukasz Marek <l.marek@samsung.com>
Tue, 5 Feb 2013 12:49:23 +0000 (13:49 +0100)
committerLukasz Marek <l.marek@samsung.com>
Mon, 11 Feb 2013 13:25:23 +0000 (14:25 +0100)
[Issue#] N/A
[Problem] Prevent issued some warnings.
[Cause] N/A
[Solution] Fixed.
[Verification] successful build, restart wrt-launchpad-deamon.
No logical difference in working of wrt-launchpad-deamon.

Change-Id: I4e73e25794a7b2d4fe655294a3dd134425a53934

src/wrt-launchpad-daemon/feature/preexec.h
src/wrt-launchpad-daemon/legacy/preload.h
src/wrt-launchpad-daemon/src/app_sock.c

index 0e950c0..584db6a 100644 (file)
@@ -28,6 +28,7 @@ typedef struct _preexec_list_t {
     char *pkg_type;
     char *so_path;
     int (*dl_do_pre_exe)(char *, char *);
+    void *handle;
 } preexec_list_t;
 
 static void __preexec_list_free()
@@ -44,6 +45,9 @@ static void __preexec_list_free()
             if (type_t->so_path) {
                 free(type_t->so_path);
             }
+            if (type_t->handle) {
+                dlclose(type_t->handle);
+            }
             free(type_t);
         }
     }
@@ -123,6 +127,8 @@ static inline void __preexec_init(int argc, char **argv)
         if (type_t->pkg_type == NULL) {
             _E("no available memory\n");
             free(type_t);
+            dlclose(handle);
+            handle = NULL;
             __preexec_list_free();
             fclose(preexec_file);
             return;
@@ -132,10 +138,13 @@ static inline void __preexec_init(int argc, char **argv)
             _E("no available memory\n");
             free(type_t->pkg_type);
             free(type_t);
+            dlclose(handle);
+            handle = NULL;
             __preexec_list_free();
             fclose(preexec_file);
             return;
         }
+        type_t->handle = handle;
         type_t->dl_do_pre_exe = func;
 
         preexec_list = g_slist_append(preexec_list, (void *)type_t);
index fb5fcb7..7baf625 100644 (file)
@@ -17,6 +17,8 @@
 #ifdef PRELOAD_ACTIVATE
 
 #include <dlfcn.h>
+#include <glib.h>
+
 #define PRELOAD_FILE        SHARE_PREFIX "/preload_list.txt"
 #define PRELOAD_FILE_WRT    SHARE_PREFIX "/preload_list_wrt.txt"
 
@@ -28,8 +30,13 @@ static int g_argc;
 static char **g_argv;
 static size_t max_cmdline_size = 0;
 
-static int (*dl_einit)() = NULL;
-static int (*dl_efini)() = NULL;
+static GSList *g_dlopen_handle_list = NULL;
+
+typedef struct handle_list_t {
+    int (*dl_einit)();
+    int (*dl_efini)();
+    void *handle;
+} handle_list_t;
 
 static inline void __preload_init(int argc, char **argv)
 {
@@ -52,34 +59,50 @@ static inline void __preload_init(int argc, char **argv)
         return;
     }
 
-    while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) > (char*)0) {
-        soname[MAX_LOCAL_BUFSZ - 1] = 0;
-        handle = dlopen(soname, RTLD_NOW);
-        if (handle == NULL) {
+    while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) != NULL) {
+        size_t pos = strnlen(soname, MAX_LOCAL_BUFSZ);
+        if (pos > 0) {
+            soname[pos - 1] = '\0';
+        }
+
+        handle_list_t *entry = calloc(1, sizeof(handle_list_t));
+        if (!entry) {
+            _E("out of memory\n");
+            break;
+        }
+
+        entry->handle = dlopen(soname, RTLD_NOW);
+        if (entry->handle == NULL) {
+            free(entry);
             continue;
         }
-        _D("preload %s# - handle : %x\n", soname, handle);
+        _D("preload %s# - handle : %x\n", soname, entry->handle);
 
-        func = dlsym(handle, EFL_PREINIT_FUNC);
+        func = dlsym(entry->handle, EFL_PREINIT_FUNC);
         if (func != NULL) {
             _D("get pre-initialization function\n");
-            dl_einit = func;
+            entry->dl_einit = func;
             func = dlsym(handle, EFL_SHUTDOWN_FUNC);
             if (func != NULL) {
                 _D("get shutdown function\n");
-                dl_efini = func;
+                entry->dl_efini = func;
             }
         }
+        g_dlopen_handle_list = g_slist_prepend(g_dlopen_handle_list, entry);
     }
-
     fclose(preload_list);
     preload_initialized = 1;
 }
 
 static inline int preinit_init()
 {
-    if (dl_einit != NULL) {
-        dl_einit(0, NULL);
+    GSList *iter = NULL;
+    handle_list_t *entry;
+
+    for (iter = g_dlopen_handle_list; iter != NULL; iter = g_slist_next(iter)) {
+        entry = iter->data;
+        if (entry->dl_einit != NULL)
+            entry->dl_einit(0, NULL);
     }
     _D("pre-initialzation on");
     return 0;
@@ -87,10 +110,19 @@ static inline int preinit_init()
 
 static inline int preinit_fini()
 {
-    if (dl_efini != NULL) {
-        dl_efini();
+    GSList *iter = NULL;
+    handle_list_t *entry;
+
+    for (iter = g_dlopen_handle_list; iter != NULL; iter = g_slist_next(iter)) {
+        entry = iter->data;
+        if (entry->dl_efini != NULL)
+            entry->dl_efini();
+        if (entry->handle)
+            dlclose(entry->handle);
     }
     _D("pre-initialization off");
+    g_slist_free_full(g_dlopen_handle_list, free);
+    g_dlopen_handle_list = NULL;
     return 0;
 }
 
@@ -140,48 +172,49 @@ static inline void __preload_exec(int argc, char **argv)
     exit(0);
 }
 
-static int g_dlopen_size = 5;
-static int g_dlopen_count = 0;
-static void** g_dlopen_handle_list = NULL;
+static int g_wrt_dlopen_size = 5;
+static int g_wrt_dlopen_count = 0;
+static void** g_wrt_dlopen_handle_list = NULL;
 
 static inline int __preload_save_dlopen_handle(void *handle)
 {
     if (!handle) {
         return 1;
     }
-    if (g_dlopen_count == g_dlopen_size || !g_dlopen_handle_list) {
+    if (g_wrt_dlopen_count == g_wrt_dlopen_size || !g_wrt_dlopen_handle_list) {
         void** tmp =
-            realloc(g_dlopen_handle_list, 2 * g_dlopen_size * sizeof(void *));
+            realloc(g_wrt_dlopen_handle_list, 2 * g_wrt_dlopen_size * sizeof(void *));
         if (NULL == tmp) {
             _E("out of memory\n");
             dlclose(handle);
             return 1;
         }
-        g_dlopen_size *= 2;
-        g_dlopen_handle_list = tmp;
+        g_wrt_dlopen_size *= 2;
+        g_wrt_dlopen_handle_list = tmp;
     }
-    g_dlopen_handle_list[g_dlopen_count++] = handle;
+    g_wrt_dlopen_handle_list[g_wrt_dlopen_count++] = handle;
     return 0;
 }
 
 static inline void __preload_fini_for_wrt()
 {
     int i = 0;
-    if (!g_dlopen_handle_list) {
+    if (!g_wrt_dlopen_handle_list) {
         return;
     }
-    for (i = 0; i < g_dlopen_count; ++i) {
-        void *handle = g_dlopen_handle_list[i];
+    for (i = 0; i < g_wrt_dlopen_count; ++i)
+    {
+        void *handle = g_wrt_dlopen_handle_list[i];
         if (handle) {
             if (0 != dlclose(handle)) {
                 _E("dlclose failed\n");
             }
         }
     }
-    free(g_dlopen_handle_list);
-    g_dlopen_handle_list = NULL;
-    g_dlopen_size = 5;
-    g_dlopen_count = 0;
+    free(g_wrt_dlopen_handle_list);
+    g_wrt_dlopen_handle_list = NULL;
+    g_wrt_dlopen_size = 5;
+    g_wrt_dlopen_count = 0;
 }
 
 static inline void __preload_init_for_wrt()
index 4d55622..c3b27c6 100644 (file)
@@ -31,17 +31,21 @@ static int __connect_client_sock(int sockfd,
                                  socklen_t salen,
                                  int nsec);
 
-static inline void __set_sock_option(int fd, int cli)
+static inline int __set_sock_option(int fd, int cli)
 {
     int size;
-    struct timeval tv = { 3, 200 * 1000 };      /*  3.2 sec */
+    struct timeval tv = { 3, 200 * 1000 };    /*  3.2 sec */
 
     size = AUL_SOCK_MAXBUFF;
-    setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
-    setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
-    if (cli) {
-        setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
+    if (0 != setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) ||
+        0 != setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)))
+    {
+        return 1;
+    }
+    if (cli && 0 != setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))) {
+        return 1;
     }
+    return 0;
 }
 
 int __create_server_sock(int pid)
@@ -111,7 +115,10 @@ int __create_server_sock(int pid)
         return -1;
     }
 
-    __set_sock_option(fd, 0);
+    if (0 != __set_sock_option(fd, 0)) {
+        close(fd);
+        return -1;
+    }
 
     if (listen(fd, 10) == -1) {
         _E("listen error");
@@ -129,7 +136,8 @@ int __create_server_sock(int pid)
             if (link(saddr.sun_path, p_saddr.sun_path) < 0) {
                 if (errno == EEXIST) {
                     _D("pg path - already exists");
-                } else {
+                }
+                else {
                     _E("pg path - unknown create error");
                 }
             }
@@ -179,7 +187,10 @@ retry_con:
         return -1;
     }
 
-    __set_sock_option(fd, 1);
+    if (0 != __set_sock_option(fd, 1)) {
+        close(fd);
+        return -1;
+    }
 
     return fd;
 }
@@ -198,19 +209,21 @@ static int __connect_client_sock(int fd,
     struct timeval timeout;
 
     flags = fcntl(fd, F_GETFL, 0);
-    fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+    if (0 != fcntl(fd, F_SETFL, flags | O_NONBLOCK)) {
+        return -1;
+    }
 
     error = 0;
     if ((ret = connect(fd, (struct sockaddr *)saptr, salen)) < 0) {
         if (errno != EAGAIN && errno != EINPROGRESS) {
-            fcntl(fd, F_SETFL, flags);
+            (void) fcntl(fd, F_SETFL, flags);
             return (-2);
         }
     }
 
     /* Do whatever we want while the connect is taking place. */
     if (ret == 0) {
-        goto done;              /* connect completed immediately */
+        goto done;    /* connect completed immediately */
     }
     FD_ZERO(&readfds);
     FD_SET(fd, &readfds);
@@ -219,9 +232,8 @@ static int __connect_client_sock(int fd,
     timeout.tv_usec = nsec;
 
     if ((ret = select(fd + 1, &readfds, &writefds, NULL,
-                      nsec ? &timeout : NULL)) == 0)
-    {
-        close(fd);              /* timeout */
+                      nsec ? &timeout : NULL)) == 0) {
+        close(fd);    /* timeout */
         errno = ETIMEDOUT;
         return (-1);
     }
@@ -229,11 +241,13 @@ static int __connect_client_sock(int fd,
     if (FD_ISSET(fd, &readfds) || FD_ISSET(fd, &writefds)) {
         len = sizeof(error);
         if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
-            return (-1);                /* Solaris pending error */
+            return (-1);    /* Solaris pending error */
         }
-    } else {
-        return (-1);            /* select error: sockfd not set*/
     }
+    else {
+        return (-1);    /* select error: sockfd not set*/
+    }
+
 done:
     (void) fcntl(fd, F_SETFL, flags);
     if (error) {
@@ -327,7 +341,7 @@ app_pkt_t *__app_recv_raw(int fd, int *clifd, struct ucred *cr)
     }
 
     if (getsockopt(*clifd, SOL_SOCKET, SO_PEERCRED, cr,
-                   (socklen_t *) &cl) < 0)
+                  (socklen_t *) &cl) < 0)
     {
         _E("peer information error");
         close(*clifd);
@@ -335,13 +349,16 @@ app_pkt_t *__app_recv_raw(int fd, int *clifd, struct ucred *cr)
     }
 
     pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
-    if (pkt == NULL) {
+    if(pkt == NULL) {
         close(*clifd);
         return NULL;
     }
     memset(pkt, 0, AUL_SOCK_MAXBUFF);
 
-    __set_sock_option(*clifd, 1);
+    if (0 != __set_sock_option(*clifd, 1)) {
+            close(*clifd);
+            return NULL;
+    }
 
 retry_recv:
     /* receive single packet from socket */