change chmod to fchmod 93/72893/1
authorjongmyeongko <jongmyeong.ko@samsung.com>
Fri, 3 Jun 2016 02:18:08 +0000 (11:18 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Fri, 3 Jun 2016 02:18:08 +0000 (11:18 +0900)
plus, delete a not-used function

Change-Id: I591f6429915121f4377107d540510cc660d4c0db
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
plugin/app2sd/src/app2sd_interface.c
plugin/app2sd/src/app2sd_internals.c

index 3aa8d01..76e5462 100644 (file)
@@ -666,8 +666,7 @@ int app2sd_usr_move_installed_app(const char *pkgid, GList* dir_list,
                || move_type < APP2EXT_MOVE_TO_EXT
                || move_type > APP2EXT_MOVE_TO_PHONE) {
                _E("invalid function arguments");
-               ret = APP2EXT_ERROR_INVALID_ARGUMENTS;
-               goto END;
+               return APP2EXT_ERROR_INVALID_ARGUMENTS;
        }
 
        pkgmgrinfo_pkginfo_h info_handle = NULL;
@@ -676,21 +675,21 @@ int app2sd_usr_move_installed_app(const char *pkgid, GList* dir_list,
        if (pkgmgr_ret < 0) {
                _E("failed to get pkginfo for pkg(%s), uid(%d), pkgmgr_ret(%d)",
                        pkgid, uid, pkgmgr_ret);
+               return APP2EXT_ERROR_PKGMGR_ERROR;
        }
        pkgmgr_ret = pkgmgrinfo_pkginfo_get_installed_storage(info_handle, &storage);
        if (pkgmgr_ret < 0) {
                _E("failed to get installed storage for pkg(%s) of uid(%d), pkgmgr_ret(%d)",
                        pkgid, uid, pkgmgr_ret);
                pkgmgrinfo_pkginfo_destroy_pkginfo(info_handle);
-               goto END;
+               return APP2EXT_ERROR_PKGMGR_ERROR;
        }
 
        if ((move_type == APP2EXT_MOVE_TO_EXT && storage == PMINFO_EXTERNAL_STORAGE)
                || (move_type == APP2EXT_MOVE_TO_PHONE && storage == PMINFO_INTERNAL_STORAGE)) {
-                       ret = APP2EXT_ERROR_PKG_EXISTS;
                        _E("PKG_EXISTS in [%d] STORAGE", storage);
                        pkgmgrinfo_pkginfo_destroy_pkginfo(info_handle);
-                       goto END;
+                       return APP2EXT_ERROR_PKG_EXISTS;
        } else {
                _D("pkgid[%s] move to STORAGE [%d]", pkgid, storage);
        }
@@ -699,7 +698,7 @@ int app2sd_usr_move_installed_app(const char *pkgid, GList* dir_list,
        ret = _app2sd_usr_move_app(pkgid, move_type, dir_list, uid);
        if (ret) {
                _D("unable to move application");
-               goto END;
+               return ret;
        }
 
        /* if move is completed, then update installed storage to pkgmgr_parser db */
@@ -723,10 +722,7 @@ int app2sd_usr_move_installed_app(const char *pkgid, GList* dir_list,
                }
        }
 
-END:
-       _app2sd_make_result_info_file((char*)pkgid, ret, uid);
-
-       return ret;
+       return APP2EXT_SUCCESS;
 }
 
 int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
index 21eddd2..8f990db 100644 (file)
@@ -34,6 +34,20 @@ static int _app2sd_setup_path(const char* path, const char *label, uid_t uid)
        struct passwd pwd;
        struct passwd *pwd_result;
        char buf[1024] = { 0, };
+       int fd;
+
+       fd = open(path, O_RDONLY);
+       if (fd < 0) {
+               _E("can't open path(%s)", path);
+               return APP2EXT_ERROR_OPEN_DIR;
+       }
+       ret = fchmod(fd, 0755);
+       if (ret < 0) {
+               _E("change file permission error");
+               close(fd);
+               return APP2EXT_ERROR_ACCESS_FILE;
+       }
+       close(fd);
 
        ret = lsetxattr(path, "security.SMACK64TRANSMUTE", "TRUE", 4, 0);
        if (ret < 0) {
@@ -45,11 +59,6 @@ static int _app2sd_setup_path(const char* path, const char *label, uid_t uid)
                _E("set label(%s) error", label);
                return APP2EXT_ERROR_ACCESS_FILE;
        }
-       ret = chmod(path, 0755);
-       if (ret < 0) {
-               _E("change file permission error");
-               return APP2EXT_ERROR_ACCESS_FILE;
-       }
 
        ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pwd_result);
        if (ret != 0 || pwd_result == NULL) {
@@ -1487,55 +1496,3 @@ FINISH_OFF:
 
        return err_res;
 }
-
-void _app2sd_make_result_info_file(char *pkgid, int size, uid_t uid)
-{
-       int ret = 0;
-       FILE* file = NULL;
-       int fd = 0;
-       char buf[FILENAME_MAX] = {0};
-       const char* app_info_label = "*";
-       char info_file[FILENAME_MAX] = {'\0', };
-       struct passwd pwd;
-       struct passwd *pwd_result;
-
-       if(pkgid == NULL)
-               return;
-
-       snprintf(info_file, FILENAME_MAX - 1, "/tmp/%s", pkgid);
-       _D("file path = %s", info_file);
-
-       file = fopen(info_file, "w");
-       if (file == NULL) {
-               _E("couldn't open the file (%s)", info_file);
-               return;
-       }
-
-       snprintf(buf, FILENAME_MAX - 1, "%d\n", size);
-       fwrite(buf, 1, strlen(buf), file);
-
-       fflush(file);
-       fd = fileno(file);
-       fsync(fd);
-       fclose(file);
-
-       if(lsetxattr(info_file, "security.SMACK64", app_info_label, strlen(app_info_label), 0)) {
-               _E("error(%d) in setting smack label", errno);
-       }
-
-       ret = chmod(info_file, 0755);
-       if (ret == -1) {
-               return;
-       }
-
-       memset(buf, '\0', FILENAME_MAX);
-       ret = getpwuid_r(uid, &pwd, buf, FILENAME_MAX, &pwd_result);
-       if (ret != 0 || pwd_result == NULL) {
-               _E("get uid failed(%d)", ret);
-       }
-
-       ret = chown(info_file, uid, pwd.pw_gid);
-       if (ret == -1) {
-               return;
-       }
-}