Prevent issues fixes
authorLukasz Marek <l.marek@samsung.com>
Fri, 1 Feb 2013 12:34:02 +0000 (13:34 +0100)
committerLukasz Marek <l.marek@samsung.com>
Mon, 4 Feb 2013 17:59:50 +0000 (18:59 +0100)
[Issue#] N/A
[Problem] Prevent issued some warnings.
[Cause] N/A
[Solution] Fixed.
[Verificaton] verify wrt_launchpad_daemon is working and wrt-client behaves correctly.

Change-Id: I1099ebbd544618b27644cdc6f19928eae72b9d50

src/view/webkit/view_logic_scheme_support.cpp
src/wrt-client/wrt-client.cpp
src/wrt-launchpad-daemon/legacy/preload.h

index cca7fd5..9366fa1 100644 (file)
@@ -106,10 +106,11 @@ bool SchemeSupport::HandleTizenScheme(const char* uri,
                        strlen(TIZEN_CHANGE_USERAGNET)) == 0)
     {
         LogInfo("Tizen scheme: " << uri << " change UA");
-        const char* userAgentString = strstr(uri, "=") + 1;
+        const char* userAgentString = strstr(uri, "=");
         if (NULL == userAgentString) {
             LogDebug("UA string is NULL");
         } else {
+            userAgentString++;
             LogDebug("Setting custom user agent as: " << userAgentString);
             ewk_view_user_agent_set(wkView, userAgentString);
         }
index bd3defb..16d8fb9 100755 (executable)
@@ -208,8 +208,6 @@ std::string WrtClient::getTizenIdFromArgument(int argc, char **argv)
 
         return arg;
     }
-
-    return "";
 }
 
 void WrtClient::setStep()
index 313aa2a..800caa8 100644 (file)
  */
 
 
-#ifdef PRELOAD_ACTIVATE 
+#ifdef PRELOAD_ACTIVATE
 
 #include <dlfcn.h>
 #define PRELOAD_FILE        SHARE_PREFIX"/preload_list.txt"
 #define PRELOAD_FILE_WRT    SHARE_PREFIX"/preload_list_wrt.txt"
 
-#define EFL_PREINIT_FUNC       "elm_quicklaunch_init"
-#define EFL_SHUTDOWN_FUNC      "elm_quicklaunch_shutdown"
+#define EFL_PREINIT_FUNC    "elm_quicklaunch_init"
+#define EFL_SHUTDOWN_FUNC   "elm_quicklaunch_shutdown"
 
 static int preload_initialized = 0;
 static int g_argc;
@@ -34,130 +34,182 @@ static int (*dl_efini) () = NULL;
 
 static inline void __preload_init(int argc, char **argv)
 {
-       void *handle = NULL;
-       char soname[MAX_LOCAL_BUFSZ] = {0, };
-       FILE *preload_list;
-       int (*func)() = NULL;
-       int i;
-
-       g_argc = argc;
-       g_argv = argv;
-       for (i = 0; i < argc; i++) {
-               max_cmdline_size += (strlen(argv[i]) + 1);
-       }
-       _D("max_cmdline_size = %d", max_cmdline_size);
-
-       preload_list = fopen(PRELOAD_FILE, "rt");
-       if (preload_list == NULL) {
-               _E("no preload\n");
-               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)
-                       continue;
-               _D("preload %s# - handle : %x\n", soname, handle);
-
-               func = dlsym(handle, EFL_PREINIT_FUNC);
-               if (func != NULL) {
-                       _D("get pre-initialization function\n");
-                       dl_einit = func;
-                       func = dlsym(handle, EFL_SHUTDOWN_FUNC);
-                       if (func != NULL) {
-                               _D("get shutdown function\n");
-                               dl_efini = func;
-                       }
-               }
-       }
-
-       fclose(preload_list);
-       preload_initialized = 1;
+        void *handle = NULL;
+        char soname[MAX_LOCAL_BUFSZ] = {0, };
+        FILE *preload_list;
+        int (*func)() = NULL;
+        int i;
+
+        g_argc = argc;
+        g_argv = argv;
+        for (i = 0; i < argc; i++) {
+                max_cmdline_size += (strlen(argv[i]) + 1);
+        }
+        _D("max_cmdline_size = %d", max_cmdline_size);
+
+        preload_list = fopen(PRELOAD_FILE, "rt");
+        if (preload_list == NULL) {
+                _E("no preload\n");
+                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)
+                        continue;
+                _D("preload %s# - handle : %x\n", soname, handle);
+
+                func = dlsym(handle, EFL_PREINIT_FUNC);
+                if (func != NULL) {
+                        _D("get pre-initialization function\n");
+                        dl_einit = func;
+                        func = dlsym(handle, EFL_SHUTDOWN_FUNC);
+                        if (func != NULL) {
+                                _D("get shutdown function\n");
+                                dl_efini = func;
+                        }
+                }
+        }
+
+        fclose(preload_list);
+        preload_initialized = 1;
 }
 
 static inline int preinit_init()
 {
-       if (dl_einit != NULL)
-               dl_einit(0, NULL);
-       _D("pre-initialzation on");
-       return 0;
+        if (dl_einit != NULL)
+                dl_einit(0, NULL);
+        _D("pre-initialzation on");
+        return 0;
 }
 
 static inline int preinit_fini()
 {
-       if (dl_efini != NULL)
-               dl_efini();
-       _D("pre-initialization off");
-       return 0;
+        if (dl_efini != NULL)
+                dl_efini();
+        _D("pre-initialization off");
+        return 0;
 }
 
 /* TODO : how to set cmdline gracefully ?? */
 static inline int __change_cmdline(char *cmdline)
 {
-       if (strlen(cmdline) > max_cmdline_size + 1) {
-               _E("cmdline exceed max size : %d", max_cmdline_size);
-               return -1;
-       }
+        if (strlen(cmdline) > max_cmdline_size + 1) {
+                _E("cmdline exceed max size : %d", max_cmdline_size);
+                return -1;
+        }
 
-       memset(g_argv[0], '\0', max_cmdline_size);
-       snprintf(g_argv[0], max_cmdline_size, "%s", cmdline);
+        memset(g_argv[0], '\0', max_cmdline_size);
+        snprintf(g_argv[0], max_cmdline_size, "%s", cmdline);
 
-       return 0;
+        return 0;
 }
 
 static inline void __preload_exec(int argc, char **argv)
 {
-       void *handle = NULL;
-       int (*dl_main) (int, char **);
+        void *handle = NULL;
+        int (*dl_main) (int, char **);
 
-       if (!preload_initialized)
-               return;
+        if (!preload_initialized)
+                return;
 
-       handle = dlopen(argv[0], RTLD_LAZY | RTLD_GLOBAL);
-       if (handle == NULL) {
-               return;
-       }
+        handle = dlopen(argv[0], RTLD_LAZY | RTLD_GLOBAL);
+        if (handle == NULL) {
+                return;
+        }
 
-       dl_main = dlsym(handle, "main");
-       if (dl_main != NULL) {
+        dl_main = dlsym(handle, "main");
+        if (dl_main != NULL) {
 #ifndef NATIVE_LAUNCHPAD
         /* do nothing */
 #else
-               if (__change_cmdline(argv[0]) < 0) {
-                       _E("change cmdline fail");
-                       return;
-               }
+                if (__change_cmdline(argv[0]) < 0) {
+                        _E("change cmdline fail");
+                        return;
+                }
 #endif
-               dl_main(argc, argv);
-       } else {
-               _E("dlsym not founded. bad preloaded app - check fpie pie");
-       }
+                dl_main(argc, argv);
+        } else {
+                _E("dlsym not founded. bad preloaded app - check fpie pie");
+        }
 
-       exit(0);
+        exit(0);
+}
+
+static int g_dlopen_size = 5;
+static int g_dlopen_count = 0;
+static void** g_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) {
+        void** tmp = realloc(g_dlopen_handle_list, 2 * g_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_dlopen_handle_list[g_dlopen_count++] = handle;
+    return 0;
+}
+
+static inline void __preload_fini_for_wrt()
+{
+    int i = 0;
+    if (!g_dlopen_handle_list)
+        return;
+    for (i = 0; i < g_dlopen_count; ++i)
+    {
+        void *handle = g_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;
 }
 
 static inline void __preload_init_for_wrt()
 {
-       void *handle = NULL;
-       char soname[MAX_LOCAL_BUFSZ];
-       FILE *preload_list;
-
-       preload_list = fopen(PRELOAD_FILE_WRT, "rt");
-       if (preload_list == NULL) {
-               _E("no wrt preload\n");
-               return;
-       }
-
-       while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) > (char*)0) {
-               soname[strlen(soname) - 1] = 0;
-        handle = dlopen((const char *)soname, RTLD_NOW|RTLD_GLOBAL);
-               if (handle == NULL)
-                       continue;
-               _D("preload %s# - handle : %x\n", soname, handle);
-       }
-
-       fclose(preload_list);
+    if (0 != atexit(__preload_fini_for_wrt)) {
+        _E("Cannot register atexit callback. Libraries will not be unloaded");
+    }
+    void *handle = NULL;
+    char soname[MAX_LOCAL_BUFSZ];
+    FILE *preload_list;
+
+    preload_list = fopen(PRELOAD_FILE_WRT, "rt");
+    if (preload_list == NULL) {
+        _E("no wrt preload\n");
+        return;
+    }
+
+    while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) != NULL) {
+        size_t len = strnlen(soname, MAX_LOCAL_BUFSZ);
+        if (len > 0)
+            soname[len - 1] = '\0';
+        handle = dlopen(soname, RTLD_NOW|RTLD_GLOBAL);
+        if (handle == NULL)
+            continue;
+        if (0 != __preload_save_dlopen_handle(handle)) {
+            _E("Cannot save handle, no more preloads");
+            break;
+        }
+        _D("preload %s# - handle : %x\n", soname, handle);
+    }
+
+    fclose(preload_list);
 }
 
 #else