Fix coding rule 19/79619/5 accepted/tizen/common/20160803.193159 accepted/tizen/ivi/20160804.080752 accepted/tizen/mobile/20160804.080843 accepted/tizen/tv/20160804.080710 accepted/tizen/wearable/20160804.080529 submit/tizen/20160803.012753
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 12 Jul 2016 05:13:49 +0000 (14:13 +0900)
committerSemun Lee <sm79.lee@samsung.com>
Thu, 28 Jul 2016 07:19:01 +0000 (00:19 -0700)
Change-Id: Ic18982d2254c09c628ae9e20059908c737063976
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/pkgmgr-server.c
src/pm-queue.c
src/request.c
src/restriction_mode.c

index deb83ab..b727ac8 100644 (file)
@@ -187,7 +187,7 @@ static void __send_fail_signal(backend_info *info)
                return;
        }
        pkgmgr_installer_set_session_id(pi, info->req_id);
-       switch(info->req_type) {
+       switch (info->req_type) {
        case PKGMGR_REQUEST_TYPE_INSTALL:
        case PKGMGR_REQUEST_TYPE_MOUNT_INSTALL:
        case PKGMGR_REQUEST_TYPE_REINSTALL:
@@ -325,11 +325,8 @@ static int __register_signal_handler(void)
 static int __check_backend_status_for_exit(void)
 {
        int i = 0;
-       for(i = 0; i < num_of_backends; i++)
-       {
-               if (!__is_backend_busy(i))
-                       continue;
-               else
+       for (i = 0; i < num_of_backends; i++) {
+               if (__is_backend_busy(i))
                        return 0;
        }
        return 1;
@@ -343,24 +340,18 @@ static int __check_queue_status_for_exit(void)
        int i = 0;
        int c = 0;
        int slot = -1;
-       for(i = 0; i < entries; i++)
-       {
+       for (i = 0; i < entries; i++) {
                if (ptr->queue_slot <= slot) {
                        ptr++;
-                       continue;
-               }
-               else {
+               } else {
                        head[c] = ptr->head;
                        slot = ptr->queue_slot;
                        c++;
                        ptr++;
                }
        }
-       for(i = 0; i < num_of_backends; i++)
-       {
-               if (!head[i])
-                       continue;
-               else
+       for (i = 0; i < num_of_backends; i++) {
+               if (head[i])
                        return 0;
        }
        return 1;
@@ -427,9 +418,8 @@ static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option)
        int pgid;
 
        dp = opendir("/proc");
-       if (dp == NULL) {
+       if (dp == NULL)
                return -1;
-       }
 
        for (ret = readdir_r(dp, &dentry, &result);
                        ret == 0 && result != NULL;
@@ -477,7 +467,7 @@ static void __make_pid_info_file(char *req_key, int pid, uid_t uid)
        struct passwd pwd;
        struct passwd *pwd_result;
 
-       if(req_key == NULL)
+       if (req_key == NULL)
                return;
 
        ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pwd_result);
@@ -526,9 +516,8 @@ static int __kill_app(char *appid, uid_t uid)
        }
 
        ret = __pkgcmd_proc_iter_kill_cmdline(exec, 1);
-       if (ret != PMINFO_R_OK) {
+       if (ret != PMINFO_R_OK)
                DBG("failed to kill app[%s], exec[%s]", appid, exec);
-       }
 
        pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
        return ret;
@@ -559,7 +548,7 @@ static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
 
        if (strcmp(pdata->cmd, "kill") == 0)
                pid = __pkgcmd_proc_iter_kill_cmdline(exec, 1);
-       else if(strcmp(pdata->cmd, "check") == 0)
+       else if (strcmp(pdata->cmd, "check") == 0)
                pid = __pkgcmd_proc_iter_kill_cmdline(exec, 0);
 
        __make_pid_info_file(pkgid, pid, pdata->uid);
@@ -574,7 +563,7 @@ void free_user_context(user_ctx* ctx)
        if (!ctx)
                return;
        env = ctx->env;
-       //env variable ends by NULL element
+       /* env variable ends by NULL element */
        while (env[i]) {
                free(env[i]);
                i++;
@@ -608,7 +597,7 @@ int set_environement(user_ctx *ctx)
                return -1;
        }
        env = ctx->env;
-       //env variable ends by NULL element
+       /* env variable ends by NULL element */
        while (env[i]) {
                if (putenv(env[i]) != 0)
                        res = -1;
@@ -647,17 +636,17 @@ user_ctx *get_user_context(uid_t uid)
                        ret = -1;
                        break;
                }
-               // Build environment context
+               /* Build environment context */
                len = snprintf(NULL, 0, "HOME=%s", pwd.pw_dir);
                env[0] = (char *)malloc((len + 1) * sizeof(char));
-               if(env[0] == NULL) {
+               if (env[0] == NULL) {
                        ret = -1;
                        break;
                }
                snprintf(env[0], len + 1, "HOME=%s", pwd.pw_dir);
                len = snprintf(NULL, 0, "USER=%s", pwd.pw_name);
                env[1] = (char *)malloc((len + 1) * sizeof(char));
-               if(env[1] == NULL) {
+               if (env[1] == NULL) {
                        ret = -1;
                        break;
                }
@@ -669,7 +658,7 @@ user_ctx *get_user_context(uid_t uid)
                free(context_res);
                context_res = NULL;
                i = 0;
-               //env variable ends by NULL element
+               /* env variable ends by NULL element */
                while (env && env[i]) {
                        free(env[i]);
                        i++;
@@ -1538,10 +1527,10 @@ char *_get_backend_cmd(char *type)
        char buffer[1024] = { 0 };
        char *command = NULL;
        int size = 0;
+
        fp = fopen(PKG_CONF_PATH, "r");
-       if (fp == NULL) {
+       if (fp == NULL)
                return NULL;
-       }
 
        char *path = NULL;
        while (fgets(buffer, 1024, fp) != NULL) {
@@ -1612,7 +1601,7 @@ int main(int argc, char *argv[])
                return -1;
        }
 
-#if !GLIB_CHECK_VERSION(2,35,0)
+#if !GLIB_CHECK_VERSION(2, 35, 0)
        g_type_init();
 #endif
        mainloop = g_main_loop_new(NULL, FALSE);
index 1022332..9ba8be9 100644 (file)
@@ -56,14 +56,11 @@ static int __is_pkg_supported(const char *pkgtype)
        queue_info_map *ptr = NULL;
        ptr = start;
        int i = 0;
-       for(i = 0; i < entries; i++)
-       {
+       for (i = 0; i < entries; i++) {
                if (!strncmp(ptr->pkgtype, pkgtype, MAX_PKG_TYPE_LEN))
                        return 1;
-               else {
+               else
                        ptr++;
-                       continue;
-               }
        }
        return 0;
 }
@@ -77,14 +74,11 @@ static int __entry_exist(char *backend)
        queue_info_map *ptr = NULL;
        ptr = start;
        int i = 0;
-       for(i = 0; i < entries; i++)
-       {
+       for (i = 0; i < entries; i++) {
                if (!strncmp(ptr->backend, backend, MAX_PKG_NAME_LEN))
                        return ptr->queue_slot;
-               else {
+               else
                        ptr++;
-                       continue;
-               }
        }
        return -1;
 }
@@ -97,24 +91,20 @@ static void __update_head_from_pkgtype(pm_queue_data *data)
        ptr = start;
        int slot = -1;
        int i = 0;
-       for(i = 0; i < entries; i++)
-       {
+       for (i = 0; i < entries; i++) {
                if (!strncmp(ptr->pkgtype, data->msg->pkg_type, MAX_PKG_TYPE_LEN)) {
                        ptr->head = data;
                        slot = ptr->queue_slot;
-               }
-               else {
+               } else {
                        ptr++;
-                       continue;
                }
        }
        /*update head for each duplicate entry*/
        ptr = start;
-       for(i = 0; i < entries; i++)
-       {
-               if(ptr->queue_slot == slot && !ptr->head) {
+       for (i = 0; i < entries; i++) {
+               if (ptr->queue_slot == slot && !ptr->head)
                        ptr->head = data;
-               }
+
                ptr++;
        }
        return;
@@ -126,14 +116,11 @@ static pm_queue_data *__get_head_from_pkgtype(const char *pkg_type)
        queue_info_map *ptr = NULL;
        ptr = start;
        int i = 0;
-       for(i = 0; i < entries; i++)
-       {
+       for (i = 0; i < entries; i++) {
                if (!strncmp(ptr->pkgtype, pkg_type, MAX_PKG_TYPE_LEN))
                        return ptr->head;
-               else {
+               else
                        ptr++;
-                       continue;
-               }
        }
        return NULL;
 
@@ -158,15 +145,14 @@ int _pm_queue_init(void)
                return -1;
        }
        i = n;
-       /*Find number of backends (symlinks + executables)
-       The backend dir should not conatin any other file except the backends.*/
-       while(n--)
-       {
-               if(!strcmp(namelist[n]->d_name, ".") ||
-                       !strcmp(namelist[n]->d_name, ".."))
+       /* Find number of backends (symlinks + executables)
+       The backend dir should not conatin any other file except the backends. */
+       while (n--) {
+               if (!strcmp(namelist[n]->d_name, ".") ||
+                               !strcmp(namelist[n]->d_name, ".."))
                                continue;
                snprintf(abs_filename, MAX_PKG_NAME_LEN, "%s/%s",
-                       BACKEND_DIR, namelist[n]->d_name);
+                               BACKEND_DIR, namelist[n]->d_name);
                if (lstat(abs_filename, &fileinfo)) {
                        perror("lstat");
                        continue;
@@ -176,24 +162,22 @@ int _pm_queue_init(void)
                c++;
                memset(abs_filename, 0x00, MAX_PKG_NAME_LEN);
        }
-       /*Add entries to info map.*/
+       /* Add entries to info map. */
        ptr = (queue_info_map*)calloc(c , sizeof(queue_info_map));
        memset(ptr, '\0', c * sizeof(queue_info_map));
        start = ptr;
-       for(n = 0; n < c ; n++)
-       {
+       for (n = 0; n < c ; n++) {
                ptr->backend[0] = '\0';
                ptr->head = NULL;
-               ptr->queue_slot = -2;/*-1 can be error return*/
+               ptr->queue_slot = -2; /* -1 can be error return */
                ptr->pkgtype[0] = '\0';
                ptr++;
        }
        n = i;
        ptr = start;
-       while(n--)
-       {
-               if(!strcmp(namelist[n]->d_name, ".") ||
-                       !strcmp(namelist[n]->d_name, ".."))
+       while (n--) {
+               if (!strcmp(namelist[n]->d_name, ".") ||
+                               !strcmp(namelist[n]->d_name, ".."))
                                continue;
                snprintf(abs_filename, MAX_PKG_NAME_LEN, "%s/%s",
                        BACKEND_DIR, namelist[n]->d_name);
@@ -212,9 +196,8 @@ int _pm_queue_init(void)
                                return -1;
                        }
                        buf[ret] = '\0';
-               }
-               /*executable*/
-               else {
+               } else {
+                       /*executable*/
                        snprintf(buf, sizeof(buf), "%s", abs_filename);
                }
                ret = __entry_exist(buf);
@@ -226,8 +209,7 @@ int _pm_queue_init(void)
                        entries++;
                        slot++;
                        ptr++;
-               }
-               else {
+               } else {
                        snprintf(ptr->backend, sizeof(ptr->backend), "%s", buf);
                        snprintf(ptr->pkgtype, sizeof(ptr->pkgtype), "%s", namelist[n]->d_name);
                        ptr->queue_slot = ret;
@@ -249,8 +231,7 @@ int _pm_queue_init(void)
        DBG("Number of Entries is %d", entries);
        DBG("Backend\tType\tSlot\tHead");
        ptr = start;
-       for(n = 0; n < entries; n++)
-       {
+       for (n = 0; n < entries; n++) {
                DBG("%s\t%s\t%d\t%p", ptr->backend, ptr->pkgtype, ptr->queue_slot, ptr->head);
                ptr++;
        }
@@ -306,8 +287,7 @@ int _pm_queue_push(uid_t uid, const char *req_id, int req_type,
                /* first push */
                cur = data;
                __update_head_from_pkgtype(data);
-       }
-       else {
+       } else {
                while (tmp->next)
                        tmp = tmp->next;
 
@@ -332,8 +312,7 @@ pm_dbus_msg *_pm_queue_pop(int position)
        }
        memset(ret, 0x00, sizeof(pm_dbus_msg));
        ptr = start;
-       for(i = 0; i < entries; i++)
-       {
+       for (i = 0; i < entries; i++) {
                if (ptr->queue_slot == position) {
                                cur = ptr->head;
                                break;
@@ -358,19 +337,18 @@ pm_dbus_msg *_pm_queue_pop(int position)
        cur->next = NULL;
        free(cur->msg);
        free(cur);
-       /*update head for each duplicate queue entry*/
+       /* update head for each duplicate queue entry */
        ptr = start;
-       for(i = 0; i < entries; i++)
-       {
-               if(ptr->queue_slot == position) {
+       for (i = 0; i < entries; i++) {
+               if (ptr->queue_slot == position)
                        ptr->head = saveptr;
-               }
+
                ptr++;
        }
        return ret;
 }
 
-/*populate an array of all queue heads and delete them one by one*/
+/* populate an array of all queue heads and delete them one by one */
 void _pm_queue_final()
 {
        int c = 0;
@@ -383,18 +361,13 @@ void _pm_queue_final()
        queue_info_map *ptr = NULL;
        ptr = start;
 
-       for(i = 0; i < num_of_backends; i++)
-       {
+       for (i = 0; i < num_of_backends; i++)
                head[i] = NULL;
-       }
 
-       for(i = 0; i < entries; i++)
-       {
+       for (i = 0; i < entries; i++) {
                if (ptr->queue_slot <= slot) {
                        ptr++;
-                       continue;
-               }
-               else {
+               } else {
                        head[c] = ptr->head;
                        slot = ptr->queue_slot;
                        c++;
@@ -403,7 +376,7 @@ void _pm_queue_final()
        }
 
        c = 0;
-       while(c < num_of_backends) {
+       while (c < num_of_backends) {
                if (!head[c]) { /* in case of head is NULL */
                        c = c + 1;
                        continue;
@@ -485,8 +458,7 @@ void _print_queue(int position)
        pm_queue_data *cur = NULL;
        queue_info_map *ptr = start;
        int i = 0;
-       for(i =0; i < entries; i++)
-       {
+       for (i = 0; i < entries; i++) {
                if (ptr->queue_slot == position) {
                                cur = ptr->head;
                                break;
@@ -494,9 +466,8 @@ void _print_queue(int position)
                ptr++;
        }
        int index = 1;
-       if (!cur) {
+       if (!cur)
                return;
-       }
 
        while (cur) {
                index++;
index d58f978..8f5e3f1 100644 (file)
@@ -372,16 +372,14 @@ static int __handle_request_mount_install(uid_t uid,
 
        if (target_uid == (uid_t)-1 || pkgtype == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                                                     g_variant_new("(is)",
-                                                                   PKGMGR_R_ECOMM, ""));
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
                ret = -1;
                goto catch;
        }
 
        if (pkgpath == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                                                     g_variant_new("(is)",
-                                                                   PKGMGR_R_ECOMM, ""));
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
                ret = -1;
                goto catch;
        }
@@ -393,21 +391,18 @@ static int __handle_request_mount_install(uid_t uid,
        }
 
        if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_MOUNT_INSTALL,
-                       pkgtype, pkgpath, args)) {
-       g_dbus_method_invocation_return_value(invocation,
-                                             g_variant_new("(is)",
-                                                           PKGMGR_R_ESYSTEM, ""));
+                       pkgtype, pkgpath, args)) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
                goto catch;
        }
 
        g_dbus_method_invocation_return_value(invocation,
-                                             g_variant_new("(is)",
-                                                           PKGMGR_R_OK,
-                                                           reqkey));
+                       g_variant_new("(is)", PKGMGR_R_OK, reqkey));
        ret = 0;
 
-       catch:
+catch:
        if (reqkey)
                free(reqkey);
 
@@ -623,7 +618,7 @@ static int __handle_request_enable_app(uid_t uid,
        ret = 0;
 
 catch:
-       if(reqkey)
+       if (reqkey)
                free(reqkey);
 
        return ret;
@@ -1301,8 +1296,7 @@ int __return_value_to_caller(const char *req_key, GVariant *result)
        return 0;
 }
 
-static const GDBusInterfaceVTable interface_vtable =
-{
+static const GDBusInterfaceVTable interface_vtable = {
        __handle_method_call,
        NULL,
        NULL,
index 376d4f9..a3a05fc 100644 (file)
@@ -261,9 +261,8 @@ static int __get_pkg_restriction_mode(uid_t uid, const char *pkgid, int *mode)
        sqlite3_stmt *stmt;
 
        db = __open_db();
-       if (db == NULL) {
+       if (db == NULL)
                return -1;
-       }
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {