fixed prevent issues
authorJaeho Lee <jaeho81.lee@samsung.com>
Mon, 7 Jan 2013 02:38:57 +0000 (11:38 +0900)
committerJaeho Lee <jaeho81.lee@samsung.com>
Mon, 7 Jan 2013 02:38:57 +0000 (11:38 +0900)
Signed-off-by: Jaeho Lee <jaeho81.lee@samsung.com>
13 files changed:
am_daemon/amd_cgutil.c
am_daemon/amd_main.c
am_daemon/amd_request.c
feature/preexec.h
include/aul_util.h
launchpad_src/launchpad.c
legacy/preload.h
packaging/aul.spec
src/app_sock.c
src/launch_glib.c
src/pkginfo.c
test/aul_dbus.c
test/launch_app.c

index 3fb9d43..4c6f8b8 100755 (executable)
@@ -265,7 +265,7 @@ static int check_cgroup_mount(const char *mount_point)
 
 static int _mount_root(struct cginfo *cg, const char *mount_point)
 {
-       int r;
+       int r = 0;
 
        if (check_cgroup_mount(mount_point) < 0)
                r = _mount(mount_point, &mntinfos[_MNT_ROOT]);
index 6ceb4b8..19f5c03 100755 (executable)
@@ -98,6 +98,7 @@ static int __kill_bg_apps(int limit)
                free(info_t);
        }
 
+       return 0;
 }
 
 static int __remove_item_running_list(int pid)
@@ -120,7 +121,7 @@ static int __remove_item_running_list(int pid)
 gboolean __add_item_running_list(gpointer user_data)
 {
        bool taskmanage;
-       ail_appinfo_h handle;
+       ail_appinfo_h handle = NULL;
        ail_error_e ail_ret;
        r_app_info_t *info_t = NULL;
        GSList *iter = NULL;
@@ -155,11 +156,11 @@ gboolean __add_item_running_list(gpointer user_data)
        ail_ret = ail_appinfo_get_bool(handle, AIL_PROP_X_SLP_TASKMANAGE_BOOL, &taskmanage);
        if (ail_ret != AIL_ERROR_OK) {
                _E("ail_appinfo_get_bool failed");
-               return false;
+               goto END;
        }
 
        if (taskmanage == false)
-               return false;
+               goto END;
 
        for (iter = r_app_info_list; iter != NULL; iter = g_slist_next(iter))
        {
@@ -190,11 +191,12 @@ gboolean __add_item_running_list(gpointer user_data)
                info_t = (r_app_info_t *)iter->data;
        }
 
+END:
        if (ail_destroy_appinfo(handle) != AIL_ERROR_OK)
                _E("ail_destroy_rs failed");
 
        free(item);
-       return false;
+       return ail_ret == AIL_ERROR_OK ? true : false;
 }
 
 static void __vconf_cb(keynode_t *key, void *data)
@@ -281,7 +283,8 @@ int main(int argc, char *argv[])
        ret = __init();
 
        handle = creat("/tmp/amd_ready", S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
-       close(handle);
+       if (handle != -1)
+               close(handle);
 
        ecore_main_loop_begin();
 
index f1e3312..7a7b119 100755 (executable)
@@ -165,6 +165,9 @@ static gboolean __add_history_handler(gpointer user_data)
        struct appinfo *ai;
        app_pkt_t *pkt = (app_pkt_t *)user_data;
 
+       if (!pkt)
+               return FALSE;
+
        kb = bundle_decode(pkt->data, pkt->len);
        appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
 
@@ -192,8 +195,7 @@ static gboolean __add_history_handler(gpointer user_data)
 
        if (kb != NULL)
                bundle_free(kb);
-       if (pkt != NULL)
-               free(pkt);
+       free(pkt);
 
        return FALSE;
 }
@@ -298,94 +300,98 @@ static gboolean __request_handler(gpointer data)
        }
 
        switch (pkt->cmd) {
-       case APP_OPEN:
-       case APP_RESUME:
-       case APP_START:
-       case APP_START_RES:
-               kb = bundle_decode(pkt->data, pkt->len);
-               appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
-               ret = _start_app(appid, kb, pkt->cmd, cr.pid, clifd);
-
-               item = malloc(sizeof(item_pkt_t));
-               item->pid = ret;
-               strncpy(item->appid, appid, 512);
-
-               if (kb != NULL)
-                       bundle_free(kb);
-
-               if(ret > 0) {
-                       g_timeout_add(1000, __add_history_handler, pkt);
-                       g_timeout_add(1200, __add_item_running_list, item);
-               } else {
+               case APP_OPEN:
+               case APP_RESUME:
+               case APP_START:
+               case APP_START_RES:
+                       kb = bundle_decode(pkt->data, pkt->len);
+                       appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
+                       ret = _start_app(appid, kb, pkt->cmd, cr.pid, clifd);
+
+                       item = calloc(1, sizeof(item_pkt_t));
+                       item->pid = ret;
+                       strncpy(item->appid, appid, 511);
+
+                       if (kb != NULL)
+                               bundle_free(kb), kb = NULL;
+
+                       if(ret > 0) {
+                               g_timeout_add(1000, __add_history_handler, pkt);
+                               g_timeout_add(1200, __add_item_running_list, item);
+                       } else {
+                               free(pkt);
+                               free(item);
+                       }
+                       break;
+               case APP_RESULT:
+               case APP_CANCEL:
+                       kb = bundle_decode(pkt->data, pkt->len);
+                       ret = __foward_cmd(pkt->cmd, kb, cr.pid);
+                       __real_send(clifd, ret);
                        free(pkt);
-                       free(item);
-               }
-               break;
-       case APP_RESULT:
-       case APP_CANCEL:
-               kb = bundle_decode(pkt->data, pkt->len);
-               ret = __foward_cmd(pkt->cmd, kb, cr.pid);
-               __real_send(clifd, ret);
-               free(pkt);
-               break;
-       case APP_TERM_BY_PID:
-       case APP_RESUME_BY_PID:
-       case APP_KILL_BY_PID:
-               kb = bundle_decode(pkt->data, pkt->len);
-               appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
-               ret = __app_process_by_pid(pkt->cmd, appid, &cr);
-               __real_send(clifd, ret);
-               free(pkt);
-               break;
-       case APP_RUNNING_INFO:
-               _status_send_running_appinfo_v2(clifd);
-               free(pkt);
-               break;
-       case APP_IS_RUNNING:
-               appid = malloc(MAX_PACKAGE_STR_SIZE);
-               strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1);
-               ret = _status_app_is_running_v2(appid);
-               _D("APP_IS_RUNNING : %s : %d",appid, ret);
-               __send_result_to_client(clifd, ret);
-               free(pkt);
-               break;
-       case APP_KEY_RESERVE:
-               ret = _register_key_event(cr.pid);
-               __send_result_to_client(clifd, ret);
-               free(pkt);
-               break;
-       case APP_KEY_RELEASE:
-               ret = _unregister_key_event(cr.pid);
-               __send_result_to_client(clifd, ret);
-               free(pkt);
-               break;
-       case APP_STATUS_UPDATE:
-               status = (int *)pkt->data;
-               ret = _status_update_app_info_list(cr.pid, *status);
-               __send_result_to_client(clifd, ret);
-               free(pkt);
-               break;
-       case APP_RELEASED:
-               appid = malloc(MAX_PACKAGE_STR_SIZE);
-               strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1);
-               ret = __release_srv(appid);
-               __send_result_to_client(clifd, ret);
-               free(pkt);
-               break;
-       case APP_RUNNING_LIST_UPDATE:
-               /*kb = bundle_decode(pkt->data, pkt->len);
-               appid = (char *)bundle_get_val(kb, AUL_K_APPID);
-               app_path = (char *)bundle_get_val(kb, AUL_K_EXEC);
-               tmp_pid = (char *)bundle_get_val(kb, AUL_K_PID);
-               pid = atoi(tmp_pid);
-               ret = _status_add_app_info_list(appid, app_path, pid);*/
-               ret = 0;
-               __send_result_to_client(clifd, ret);
-               free(pkt);
-               break;
-       default:
-               _E("no support packet");
+                       break;
+               case APP_TERM_BY_PID:
+               case APP_RESUME_BY_PID:
+               case APP_KILL_BY_PID:
+                       kb = bundle_decode(pkt->data, pkt->len);
+                       appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
+                       ret = __app_process_by_pid(pkt->cmd, appid, &cr);
+                       __real_send(clifd, ret);
+                       free(pkt);
+                       break;
+               case APP_RUNNING_INFO:
+                       _status_send_running_appinfo_v2(clifd);
+                       free(pkt);
+                       break;
+               case APP_IS_RUNNING:
+                       appid = malloc(MAX_PACKAGE_STR_SIZE);
+                       strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1);
+                       ret = _status_app_is_running_v2(appid);
+                       _D("APP_IS_RUNNING : %s : %d",appid, ret);
+                       __send_result_to_client(clifd, ret);
+                       free(pkt);
+                       free(appid);
+                       break;
+               case APP_KEY_RESERVE:
+                       ret = _register_key_event(cr.pid);
+                       __send_result_to_client(clifd, ret);
+                       free(pkt);
+                       break;
+               case APP_KEY_RELEASE:
+                       ret = _unregister_key_event(cr.pid);
+                       __send_result_to_client(clifd, ret);
+                       free(pkt);
+                       break;
+               case APP_STATUS_UPDATE:
+                       status = (int *)pkt->data;
+                       ret = _status_update_app_info_list(cr.pid, *status);
+                       __send_result_to_client(clifd, ret);
+                       free(pkt);
+                       break;
+               case APP_RELEASED:
+                       appid = malloc(MAX_PACKAGE_STR_SIZE);
+                       strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1);
+                       ret = __release_srv(appid);
+                       __send_result_to_client(clifd, ret);
+                       free(pkt);
+                       free(appid);
+                       break;
+               case APP_RUNNING_LIST_UPDATE:
+                       /*kb = bundle_decode(pkt->data, pkt->len);
+                         appid = (char *)bundle_get_val(kb, AUL_K_APPID);
+                         app_path = (char *)bundle_get_val(kb, AUL_K_EXEC);
+                         tmp_pid = (char *)bundle_get_val(kb, AUL_K_PID);
+                         pid = atoi(tmp_pid);
+                         ret = _status_add_app_info_list(appid, app_path, pid);*/
+                       ret = 0;
+                       __send_result_to_client(clifd, ret);
+                       free(pkt);
+                       break;
+               default:
+                       _E("no support packet");
        }
+       if (kb != NULL)
+               bundle_free(kb), kb = NULL;
 
        return TRUE;
 }
@@ -407,7 +413,7 @@ static gboolean __au_glib_check(GSource *src)
 }
 
 static gboolean __au_glib_dispatch(GSource *src, GSourceFunc callback,
-                                 gpointer data)
+               gpointer data)
 {
        callback(data);
        return TRUE;
@@ -441,7 +447,7 @@ int _requset_init(struct amdmgr *amd)
 
        g_source_add_poll(src, gpollfd);
        g_source_set_callback(src, (GSourceFunc) __request_handler,
-                                     (gpointer) gpollfd, NULL);
+                       (gpointer) gpollfd, NULL);
        g_source_set_priority(src, G_PRIORITY_DEFAULT);
 
        r = g_source_attach(src, NULL);
index 6848c7d..94db506 100755 (executable)
@@ -109,6 +109,7 @@ static inline void __preexec_init(int argc, char **argv)
                           type, sopath);
                        free(type_t);
                        dlclose(handle);
+                       handle = NULL;
                        continue;
                }
 
index d86a3f9..e4c4630 100755 (executable)
 #define MAX_PACKAGE_APP_PATH_SIZE 512
 #define MAX_RUNNING_APP_INFO 512
 
-struct history_data {
-       char pkg_name[MAX_PACKAGE_STR_SIZE];
-       char app_path[MAX_PACKAGE_APP_PATH_SIZE];
-       int pid;
-       int len;
-       unsigned char data[1];
-};
-
 typedef struct _app_status_info_t{
        char appid[MAX_PACKAGE_STR_SIZE];
        char app_path[MAX_PACKAGE_APP_PATH_SIZE];
index e5f5777..c3b34c2 100755 (executable)
@@ -86,8 +86,6 @@ _static_ int __fake_launch_app(int cmd, int pid, bundle * kb);
 _static_ char **__create_argc_argv(bundle * kb, int *margc);
 _static_ int __normal_fork_exec(int argc, char **argv);
 _static_ void __real_launch(const char *app_path, bundle * kb);
-_static_ void __add_history(int caller, int callee, const char *pkgname,
-                               bundle *b, const char *app_path);
 static inline int __parser(const char *arg, char *out, int out_size);
 _static_ void __modify_bundle(bundle * kb, int caller_pid,
                            app_info_from_db * menu_info, int cmd);
@@ -284,47 +282,6 @@ _static_ void __real_launch(const char *app_path, bundle * kb)
        __normal_fork_exec(app_argc, app_argv);
 }
 
-_static_ void __add_history(int caller, int callee, const char *pkgname, 
-                               bundle *b, const char *app_path)
-{
-       struct history_data *hd;
-       bundle_raw *kb_data;
-       int len;
-
-       _D("***** HISTORY *****\n");
-       _D("%d ==> %d(%s) \n", caller, callee, pkgname);
-       _D("*******************\n");
-
-       if (b) {
-               bundle_encode(b, (bundle_raw **)&kb_data, &len);
-               hd = (struct history_data *)malloc(sizeof(char) * (len+1033));
-
-               strncpy(hd->pkg_name, pkgname, MAX_PACKAGE_STR_SIZE-1);
-               strncpy(hd->app_path, app_path, MAX_PACKAGE_APP_PATH_SIZE-1);
-               hd->pid = callee;
-               hd->len = len;
-               memcpy(hd->data, kb_data, len);
-
-               __app_send_raw(AUL_UTIL_PID, APP_ADD_HISTORY, (unsigned char *)hd,
-                       hd->len+1033);
-               free(kb_data);
-               free(hd);
-       } else {
-               hd = (struct history_data *)malloc(sizeof(char) * 1033);
-
-               strncpy(hd->pkg_name, pkgname, MAX_PACKAGE_STR_SIZE-1);
-               strncpy(hd->app_path, app_path, MAX_PACKAGE_APP_PATH_SIZE-1);
-               hd->pid = callee;
-               hd->len = 0;
-
-               __app_send_raw(AUL_UTIL_PID, APP_ADD_HISTORY, (unsigned char *)hd,
-                       1033);
-               free(hd);
-       }
-
-       return;
-}
-
 
 /*
  * Parsing original app path to retrieve default bundle
index 1764cf3..2af9468 100755 (executable)
@@ -59,7 +59,7 @@ static inline void __preload_init(int argc, char **argv)
 
        while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) > 0) {
                soname[strlen(soname) - 1] = 0;
-               handle = dlopen(soname, RTLD_NOW);
+               handle = dlopen((const char *) soname, RTLD_NOW);
                if (handle == NULL)
                        continue;
                _D("preload %s# - handle : %x\n", soname, handle);
index 74ffd32..047e8b8 100644 (file)
@@ -1,6 +1,6 @@
 Name:       aul
 Summary:    App utility library
-Version:    0.0.222
+Version:    0.0.226
 Release:    1
 Group:      System/Libraries
 License:    Apache License, Version 2.0
index e6e0c36..7aff414 100755 (executable)
@@ -57,7 +57,7 @@ int __create_server_sock(int pid)
 
        /* Create basedir for our sockets */
        orig_mask = umask(0);
-       mkdir(AUL_SOCK_PREFIX, S_IRWXU | S_IRWXG | S_IRWXO | S_ISVTX);
+       (void) mkdir(AUL_SOCK_PREFIX, S_IRWXU | S_IRWXG | S_IRWXO | S_ISVTX);
        umask(orig_mask);
 
        fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
@@ -115,6 +115,7 @@ int __create_server_sock(int pid)
 
        if (listen(fd, 10) == -1) {
                _E("listen error");
+               close(fd);
                return -1;
        }
 
@@ -229,9 +230,9 @@ static int __connect_client_sock(int fd, const struct sockaddr *saptr, socklen_t
                return (-1);    /* select error: sockfd not set*/
 
  done:
-       fcntl(fd, F_SETFL, flags);      
+       (void) fcntl(fd, F_SETFL, flags);
        if (error) {
-               close(fd);      
+               close(fd);
                errno = error;
                return (-1);
        }
index 273749e..f0850d0 100755 (executable)
@@ -126,6 +126,7 @@ SLPAPI int aul_launch_init(
 SLPAPI int aul_launch_fini()
 {
        g_source_destroy(src);
+       return AUL_R_OK;
 }
 
 SLPAPI int aul_launch_argv_handler(int argc, char **argv)
index 603c031..8a3d978 100755 (executable)
@@ -62,6 +62,7 @@ SLPAPI int aul_app_get_running_app_info(aul_app_info_iter_fn enum_fn,
        char *pkt_data;
        aul_app_info info;
 
+       bzero(&info, sizeof(info));
        if (enum_fn == NULL)
                return AUL_R_EINVAL;
 
index a6000a5..ccd2c79 100755 (executable)
@@ -51,6 +51,7 @@ int main(int argc, char **argv)
        DBusMessage *message;
        DBusPendingCall *pc;
        GMainLoop *loop;
+       dbus_bool_t ret;
 
        char tmp[MAX_LOCAL_BUFSZ];
        char *s;
@@ -68,7 +69,7 @@ int main(int argc, char **argv)
 
        message = dbus_message_new_method_call (
                        SERVICE_NAME,PATH_NAME,INTERFACE_NAME,
-                       METHOD_NAME); 
+                       METHOD_NAME);
 
        gettimeofday(&tv, NULL);
        snprintf(tmp, MAX_LOCAL_BUFSZ, "%ld/%ld", tv.tv_sec, tv.tv_usec);
@@ -77,7 +78,12 @@ int main(int argc, char **argv)
        dbus_message_append_args(message,
                                 DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID);
 
-       dbus_connection_send_with_reply(bus, message, &pc, INT_MAX);
+       ret = dbus_connection_send_with_reply(bus, message, &pc, INT_MAX);
+       if (!ret) {
+               _E("dbus_connection_send_with_reply() failed.");
+               dbus_message_unref(message);
+               return -1;
+       }
        if (!dbus_pending_call_set_notify(pc, request_cb, NULL, NULL))
                _E("pending call set fail");
 
index 59eac96..a07cd90 100755 (executable)
@@ -37,7 +37,7 @@ static bundle *create_internal_bundle(int start)
 {
        bundle *kb;
        int i;
-       char arg[1024];
+       char arg[1024] = {0, };
        char* val_array[128];
 
        kb = bundle_create();
@@ -46,7 +46,7 @@ static bundle *create_internal_bundle(int start)
                        bundle_add(kb, gargv[i], " ");
                else {
                        int j = 1;
-                       strncpy(arg, gargv[i + 1], 1024);
+                       strncpy(arg, gargv[i + 1], 1023);
                        val_array[0] = strtok(arg,",");
                        while(1)
                        {