From: jk7744.park Date: Sat, 24 Oct 2015 07:29:18 +0000 (+0900) Subject: tizen 2.4 release X-Git-Tag: accepted/tizen/2.4/mobile/20151029.034151^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=818128bd218b49f7d3fa1fe5d5b9d8224fdfbaee;p=framework%2Fappfw%2Fapp2sd.git tizen 2.4 release --- diff --git a/packaging/app2sd.spec b/packaging/app2sd.spec index 1d4db72..a3f3e8b 100755 --- a/packaging/app2sd.spec +++ b/packaging/app2sd.spec @@ -1,6 +1,6 @@ Name: app2sd Summary: Application installation on external memory -Version: 0.5.36 +Version: 0.5.42 Release: 1 Group: Application Framework/Application Installer License: Apache-2.0 diff --git a/plugin/app2sd/CMakeLists.txt b/plugin/app2sd/CMakeLists.txt index 920c369..caed790 100755 --- a/plugin/app2sd/CMakeLists.txt +++ b/plugin/app2sd/CMakeLists.txt @@ -34,7 +34,7 @@ ADD_LIBRARY(${APP2SD} SHARED ${libapp2sd_SOURCES}) SET_TARGET_PROPERTIES(${APP2SD} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${APP2SD} PROPERTIES VERSION ${VERSION}) SET_TARGET_PROPERTIES(${APP2SD} PROPERTIES COMPILE_FLAGS "${libapp2sd_CFLAGS}") -TARGET_LINK_LIBRARIES(${APP2SD} ${libpkgs_LDFLAGS}) +TARGET_LINK_LIBRARIES(${APP2SD} ${libpkgs_LDFLAGS} "-lm") SET(CMAKE_INSTALL_PREFIX "/usr") SET(PREFIX ${CMAKE_INSTALL_PREFIX}) diff --git a/plugin/app2sd/inc/app2sd_internals.h b/plugin/app2sd/inc/app2sd_internals.h index c422d8b..93190e8 100755 --- a/plugin/app2sd/inc/app2sd_internals.h +++ b/plugin/app2sd/inc/app2sd_internals.h @@ -47,6 +47,7 @@ #include #include #include +#include #define DIR_PERMS (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) @@ -58,6 +59,7 @@ #define DEV_MAJOR 7 #define FS_TYPE "ext4" +#define INTERNAL_STORAGE_PATH "/opt/usr" typedef enum mount_type_t { MOUNT_TYPE_RD = 0, diff --git a/plugin/app2sd/src/app2sd_interface.c b/plugin/app2sd/src/app2sd_interface.c index 5961cb9..08da627 100755 --- a/plugin/app2sd/src/app2sd_interface.c +++ b/plugin/app2sd/src/app2sd_interface.c @@ -40,6 +40,7 @@ int app2sd_pre_app_install(const char *pkgid, GList* dir_list, char *device_node = NULL; char *devi = NULL; char *result = NULL; + int reqd_disk_size = size + ceil(size*0.2); /*Validate the function parameter recieved */ if (pkgid == NULL || dir_list == NULL || size <= 0) { @@ -60,13 +61,15 @@ int app2sd_pre_app_install(const char *pkgid, GList* dir_list, app2ext_print("App2Sd Error : Unable to get available free memory in MMC %d\n", ret); return APP2EXT_ERROR_MMC_STATUS; } + app2ext_print("Size details for application installation:size=%dMB, reqd_disk_size=%dMB, free_mmc_size=%dMB\n", + size, reqd_disk_size, free_mmc_mem); /*If avaialalbe free memory in MMC is less than required size + 5MB , return error */ - if ((size + PKG_BUF_SIZE + MEM_BUF_SIZE) > free_mmc_mem) { + if ((reqd_disk_size + PKG_BUF_SIZE + MEM_BUF_SIZE) > free_mmc_mem) { app2ext_print("Insufficient memory in MMC for application installation %d\n", ret); return APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY; } /*Create a loopback device */ - ret = _app2sd_create_loopback_device(pkgid, (size+PKG_BUF_SIZE)); + ret = _app2sd_create_loopback_device(pkgid, (reqd_disk_size+PKG_BUF_SIZE)); if (ret) { app2ext_print("App2Sd Error : Package already present\n"); char buf_dir[FILENAME_MAX] = { 0, }; @@ -219,7 +222,7 @@ int app2sd_post_app_install(const char *pkgid, int rt = 0; rt = pkgmgrinfo_pkginfo_set_installed_storage(pkgid, INSTALL_EXTERNAL); if (rt < 0) { - app2ext_print("fail to update installed location to db[%s, %s]\n", pkgid, INSTALL_EXTERNAL); + app2ext_print("fail to update installed location to db[%s, %d]\n", pkgid, INSTALL_EXTERNAL); } } return ret; @@ -561,7 +564,7 @@ int app2sd_move_installed_app(const char *pkgid, GList* dir_list, END: // vconf_set_int(VCONFKEY_PKGMGR_STATUS, ret); - _app2sd_make_result_info_file(pkgid, ret); + _app2sd_make_result_info_file((char*)pkgid, ret); return ret; } @@ -574,6 +577,7 @@ int app2sd_pre_app_upgrade(const char *pkgid, GList* dir_list, char *device_node = NULL; unsigned long long curr_size = 0; FILE *fp = NULL; + int reqd_disk_size = size + ceil(size*0.2); /*Validate function arguments*/ if (pkgid == NULL || dir_list == NULL || size<=0) { @@ -601,15 +605,15 @@ int app2sd_pre_app_upgrade(const char *pkgid, GList* dir_list, fclose(fp); /*Get installed app size*/ curr_size = _app2sd_calculate_file_size(app_path); - curr_size = (curr_size/1024)/1024; + curr_size = (curr_size)/(1024 * 1024); if (curr_size==0) { app2ext_print ("App2SD Error: App Entry is not present in SD Card\n"); return APP2EXT_ERROR_LOOPBACK_DEVICE_UNAVAILABLE; } - if (curr_size #include +#include #include #include #include #include +#include #include #include #include @@ -38,6 +40,9 @@ #include #include #include +#include + +extern int app2sd_force_clean(const char *pkgid); /* ########### Internal APIs ################## @@ -134,7 +139,8 @@ char *_app2sd_find_associated_device_node(const char *pkgid) free(result); return NULL; } else { - ret_result = strtok(dev, delims); + char *saveptr = NULL; + ret_result = strtok_r(dev, delims, &saveptr); if (ret_result) devnode = strdup(ret_result); } @@ -468,7 +474,9 @@ int _app2sd_create_file_system(const char *device_path) { int ret = APP2EXT_SUCCESS; FILE *fp = NULL; - if (NULL == device_path) { + char err_buf[1024] = {0,}; + + if (device_path == NULL) { app2ext_print("App2Sd Error: invalid param [NULL]\n"); return APP2EXT_ERROR_INVALID_ARGUMENTS; } @@ -477,18 +485,20 @@ int _app2sd_create_file_system(const char *device_path) const char *argv[] = { "/sbin/mkfs.ext4", device_path, NULL }; fp = fopen(device_path, "r+"); if (fp == NULL) { + strerror_r(errno, err_buf, sizeof(err_buf)); app2ext_print ("App2sd Error: Unable to access %s [System errono is %d.....%s]\n", - device_path, errno, strerror(errno)); + device_path, errno, err_buf); return APP2EXT_ERROR_ACCESS_FILE; } else { fclose(fp); } ret = _xsystem(argv); if (ret) { + strerror_r(errno, err_buf, sizeof(err_buf)); app2ext_print ("App2Sd Error : creating file system failed [System error is %s\n", - strerror(errno)); + err_buf); return APP2EXT_ERROR_CREATE_FS; } return ret; @@ -583,6 +593,11 @@ int _app2sd_mount_app_content(const char *pkgid, const char *dev, mode_t mode = DIR_PERMS; char app_dir_path[FILENAME_MAX] = { 0, }; char app_dir_mmc_path[FILENAME_MAX] = { 0, }; + struct timespec time = { + .tv_sec = 0, + .tv_nsec = 1000 * 1000 * 200 + }; + if (NULL == pkgid || NULL == dev) { app2ext_print("App2Sd Error : Input param is NULL %s %s \n", pkgid, dev); @@ -609,7 +624,7 @@ int _app2sd_mount_app_content(const char *pkgid, const char *dev, } } - usleep(200 * 1000); /* 200ms sleep*/ + nanosleep(&time, NULL); /* 200ms sleep */ app2ext_print ("App2Sd info : give a delay for mount\n"); switch (mount_type) { @@ -681,7 +696,7 @@ int _app2sd_mount_app_content(const char *pkgid, const char *dev, break; } } - if (cmd == APP2SD_PRE_INSTALL || cmd == APP2SD_MOVE_APP_TO_MMC) { + if (cmd == APP2SD_PRE_INSTALL || cmd == APP2SD_MOVE_APP_TO_MMC || cmd == APP2SD_PRE_UPGRADE) { ret = _app2sd_create_directory_entry(pkgid, dir_list); } return ret; @@ -691,9 +706,12 @@ int _app2sd_unmount_app_content(const char *pkgid) { int ret = APP2EXT_SUCCESS; char app_dir_mmc_path[FILENAME_MAX] = { 0, }; + snprintf(app_dir_mmc_path, FILENAME_MAX, "%s%s/.mmc", APP_INSTALLATION_PATH, pkgid); if ((ret = umount(app_dir_mmc_path)) < 0) { - app2ext_print("Unable to umount the dir %s\n", strerror(errno)); + char err_buf[1024] = {0,}; + strerror_r(errno, err_buf, sizeof(err_buf)); + app2ext_print("Unable to umount the dir %s\n", err_buf); } return ret; } @@ -703,21 +721,20 @@ static int _app2sd_move_to_archive(const char *src_path, const char *arch_path) int ret = APP2EXT_SUCCESS; ret = _app2sd_copy_dir(src_path, arch_path); - if (ret) { - if (ret != APP2EXT_ERROR_ACCESS_FILE) { - app2ext_print - ("App2Sd Error : unable to copy from %s to %s .....err is %s\n", - src_path, arch_path, strerror(errno)); - return APP2EXT_ERROR_MOVE; - } + if (ret && ret != APP2EXT_ERROR_ACCESS_FILE) { + char err_buf[1024] = {0,}; + strerror_r(errno, err_buf, sizeof(err_buf)); + app2ext_print("App2Sd Error : unable to copy from %s to %s .....err is %s\n", + src_path, arch_path, err_buf); + return APP2EXT_ERROR_MOVE; } + ret = _app2sd_delete_directory((char *)src_path); - if (ret) { - if (ret != APP2EXT_ERROR_ACCESS_FILE) { - app2ext_print("App2Sd Error : unable to delete %s \n", src_path); - return APP2EXT_ERROR_DELETE_DIRECTORY; - } + if (ret && ret != APP2EXT_ERROR_ACCESS_FILE) { + app2ext_print("App2Sd Error : unable to delete %s \n", src_path); + return APP2EXT_ERROR_DELETE_DIRECTORY; } + return ret; } @@ -731,6 +748,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list) char mmc_path[FILENAME_MAX] = { 0, }; unsigned long long total_size = 0; int reqd_size = 0; + int reqd_disk_size = 0; char *device_node = NULL; char *devi = NULL; mode_t mode = DIR_PERMS; @@ -758,6 +776,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list) ("Already %s entry is present in the SD Card, delete entry and go on without return\n", pkgid); fclose(fp); + app2sd_force_clean(pkgid); // return APP2EXT_ERROR_ALREADY_FILE_PRESENT; } @@ -794,7 +813,8 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list) list = g_list_next(list); } - reqd_size = ((total_size / 1024) / 1024) + 2; + reqd_size = ((total_size)/( 1024 * 1024)) + 2; + reqd_disk_size = reqd_size + ceil(reqd_size * 0.2); /*Find avialable free memory in the MMC card */ ret = @@ -807,7 +827,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list) return APP2EXT_ERROR_MMC_STATUS; } /*If avaialalbe free memory in MMC is less than required size + 5MB , return error */ - if (reqd_size > free_mmc_mem) { + if (reqd_disk_size > free_mmc_mem) { app2ext_print ("App2Sd Error : Insufficient memory in MMC for application installation %d\n", ret); @@ -815,7 +835,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list) } /*Create a loopback device */ ret = - _app2sd_create_loopback_device(pkgid, (reqd_size+PKG_BUF_SIZE)); + _app2sd_create_loopback_device(pkgid, (reqd_disk_size+PKG_BUF_SIZE)); if (ret) { app2ext_print ("App2Sd Error : loopback node creation failed\n"); @@ -905,16 +925,12 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list) app_mmc_path); if (ret) { if (ret == APP2EXT_ERROR_ACCESS_FILE) { - app2ext_print - ("App2Sd Error : unable to access %s\n", - path); + app2ext_print("App2Sd Error : unable to access %s\n", path); } else { - app2ext_print - ("App2Sd Error : unable to copy from %s to %s .....err is %s\n", - path, - app_mmc_path, - strerror - (errno)); + char err_buf[1024] = {0,}; + strerror_r(errno, err_buf, sizeof(err_buf)); + app2ext_print("App2Sd Error : unable to copy from %s to %s .....err is %s\n", + path, app_mmc_path, err_buf); // return APP2EXT_ERROR_MOVE; } } @@ -982,6 +998,11 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list) FILE *fp = NULL; GList *list = NULL; app2ext_dir_details* dir_detail = NULL; + int reqd_size = 0; + int free_internal_mem = 0; + struct statvfs buf = {0,}; + unsigned long long temp = 0; + char err_buf[1024] = {0,}; snprintf(app_mmc_path, FILENAME_MAX, "%s%s/.mmc", APP_INSTALLATION_PATH, pkgid); @@ -1013,7 +1034,50 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list) fp = NULL; } + memset((void *)&buf, '\0', sizeof(struct statvfs)); + ret = statvfs(INTERNAL_STORAGE_PATH, &buf); + if (0 == ret){ + temp = (buf.f_bsize * buf.f_bavail)/(1024*1024); + free_internal_mem = (int)temp; + }else{ + app2ext_print("App2SD Error: Unable to get internal storage size\n"); + return APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY; /*TODO: new error no for internal?*/ + } + + /*check app entry is there in sd card or not. */ + snprintf(app_path, FILENAME_MAX, "%s%s", APP2SD_PATH, + pkgid); + app2ext_print("App2Sd Log : Checking path %s\n", app_path); + fp = fopen(app_path, "r+"); + if (fp == NULL) { + app2ext_print + ("App2SD Error: App Entry is not present in SD Card\n"); + return APP2EXT_ERROR_INVALID_PACKAGE; + } + fclose(fp); + /*Get installed app size*/ + temp = _app2sd_calculate_file_size(app_path); + reqd_size = (int)((temp)/(1024 * 1024)); + app2ext_print("App2Sd Log : Reqd size is %d\n", reqd_size); + + if (reqd_size == 0) { + app2ext_print + ("App2SD Error: App Entry is not present in SD Card\n"); + return APP2EXT_ERROR_LOOPBACK_DEVICE_UNAVAILABLE; + } + + app2ext_print("Reqd Size: %d MB, free internal mem %d MB\n", reqd_size, free_internal_mem); + /*If avaialalbe free memory in internal storage is less than required size, return error */ + if (reqd_size > free_internal_mem) { + app2ext_print + ("App2Sd Error : Insufficient memory in internal storage for application installation %d\n", + ret); + return APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY; /*TODO: new error no for internal?*/ + } /*Get the associated device node for SD card applicationer */ + snprintf(app_path, FILENAME_MAX, "%s%s/", APP_INSTALLATION_PATH, + pkgid); + device_node = _app2sd_find_associated_device_node(pkgid); if (NULL == device_node) { @@ -1079,16 +1143,11 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list) app_archive_path); if (ret) { if (ret == APP2EXT_ERROR_ACCESS_FILE) { - app2ext_print - ("App2Sd Error : unable to access %s\n", - path); + app2ext_print("App2Sd Error : unable to access %s\n", path); } else { - app2ext_print - ("App2Sd Error : unable to copy from %s to %s .....err is %s\n", - path, - app_archive_path, - strerror - (errno)); + strerror_r(errno, err_buf, sizeof(err_buf)); + app2ext_print("App2Sd Error : unable to copy from %s to %s .....err is %s\n", + path, app_archive_path, err_buf); // return APP2EXT_ERROR_MOVE; } } @@ -1103,13 +1162,9 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list) ret = unlink(path); if (ret) { if (errno == ENOENT) { - app2ext_print - ("App2Sd Error : Directory %s does not exist\n", - path); + app2ext_print("App2Sd Error : Directory %s does not exist\n", path); } else { - app2ext_print - ("App2Sd Error : unable to remove the symbolic link file %s, it is already unlinked!!!\n", - path); + app2ext_print("App2Sd Error : unable to remove the symbolic link file %s, it is already unlinked!!!\n", path); // return APP2EXT_ERROR_DELETE_LINK_FILE; } } @@ -1118,24 +1173,16 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list) memset((void *)&path, '\0', FILENAME_MAX); snprintf(path, FILENAME_MAX, - "%s%s/.archive/%s", APP_INSTALLATION_PATH, - pkgid, - dir_detail->name); - ret = - _app2sd_copy_dir - (path, app_path); + "%s%s/.archive/%s", APP_INSTALLATION_PATH, + pkgid, dir_detail->name); + ret = _app2sd_copy_dir(path, app_path); if (ret) { if (ret == APP2EXT_ERROR_ACCESS_FILE) { - app2ext_print - ("App2Sd Error : unable to access %s\n", - path); + app2ext_print("App2Sd Error : unable to access %s\n", path); } else { - app2ext_print - ("App2Sd Error : unable to copy from %s to %s .....err is %s\n", - path, - app_path, - strerror - (errno)); + strerror_r(errno, err_buf, sizeof(err_buf)); + app2ext_print("App2Sd Error : unable to copy from %s to %s .....err is %s\n", + path, app_path, err_buf); // return APP2EXT_ERROR_MOVE; } } @@ -1143,6 +1190,7 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list) list = g_list_next(list); } + app2ext_print("App2Sd info : Copying file completed\n"); ret = _app2sd_unmount_app_content(pkgid); if (ret) { app2ext_print diff --git a/plugin/app2sd/src/app2sd_internals_utils.c b/plugin/app2sd/src/app2sd_internals_utils.c index 744f07b..0465f2b 100755 --- a/plugin/app2sd/src/app2sd_internals_utils.c +++ b/plugin/app2sd/src/app2sd_internals_utils.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,8 @@ int _xsystem(const char *argv[]) { int status = 0; pid_t pid; + char err_buf[1024] = {0,}; + pid = fork(); switch (pid) { case -1: @@ -56,8 +59,9 @@ int _xsystem(const char *argv[]) return -1; case 0: /* child */ + strerror_r(errno, err_buf, sizeof(err_buf)); if (execvp(argv[0], (char *const *)argv) < 0) { - fprintf(stderr, "execvp failed %d....%s\n", errno, strerror(errno)); /*Don't use d_msg_app2sd */ + fprintf(stderr, "execvp failed %d....%s\n", errno, err_buf); /*Don't use d_msg_app2sd */ } _exit(-1); default: @@ -118,6 +122,7 @@ int _app2sd_get_available_free_memory(const char *sd_path, int *free_mem) { struct statvfs buf; int ret = 0; + unsigned long long temp = 0; if (sd_path == NULL || free_mem == NULL) { app2ext_print("App2Sd Error : Invalid input parameter\n"); return -1; @@ -129,23 +134,26 @@ int _app2sd_get_available_free_memory(const char *sd_path, int *free_mem) ("App2SD Error: Unable to get SD Card memory information\n"); return APP2EXT_ERROR_MMC_INFORMATION; } - *free_mem = ((buf.f_bfree * buf.f_bsize) / 1024) / 1024; + temp = (unsigned long long)buf.f_bsize*buf.f_bavail; + *free_mem = (int)(temp/(1024*1024)); return 0; } int _app2sd_delete_directory(char *dirname) { DIR *dp = NULL; - struct dirent *ep = NULL; + struct dirent ep; + struct dirent *er = NULL; char abs_filename[FILENAME_MAX] = { 0, }; int ret = 0; + dp = opendir(dirname); if (dp != NULL) { - while ((ep = readdir(dp)) != NULL) { + while (readdir_r(dp, &ep, &er) == 0 && er != NULL) { struct stat stFileInfo; snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, - ep->d_name); + ep.d_name); if (lstat(abs_filename, &stFileInfo) < 0) { perror(abs_filename); @@ -154,8 +162,8 @@ int _app2sd_delete_directory(char *dirname) } if (S_ISDIR(stFileInfo.st_mode)) { - if (strcmp(ep->d_name, ".") - && strcmp(ep->d_name, "..")) { + if (strcmp(ep.d_name, ".") + && strcmp(ep.d_name, "..")) { ret = _app2sd_delete_directory(abs_filename); if (ret <0) { (void)closedir(dp); @@ -184,23 +192,26 @@ void _app2sd_delete_symlink(const char *dirname) { int ret = 0; DIR *dp = NULL; - struct dirent *ep = NULL; + struct dirent ep; + struct dirent *er = NULL; char abs_filename[FILENAME_MAX] = { 0, }; app2ext_print("star clean_symlink [%s]", dirname); dp = opendir(dirname); if (dp != NULL) { - while ((ep = readdir(dp)) != NULL) { - struct stat stFileInfo; + while (readdir_r(dp, &ep, &er) == 0 && er != NULL) { char mmc_path[PATH_MAX] = {0}; - if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, "..")) + if (!strcmp(ep.d_name, ".") || !strcmp(ep.d_name, "..")) continue; /*get realpath find symlink to ".mmc" and unlink it*/ - snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, ep->d_name); - realpath(abs_filename, mmc_path); + snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, ep.d_name); + char *path = realpath(abs_filename, mmc_path); + if(!path){ + app2ext_print("realpath failed\n"); + } if (strstr(mmc_path,".mmc")) { app2ext_print("force unlink [%s]", abs_filename); @@ -257,15 +268,17 @@ unsigned long long _app2sd_calculate_dir_size(char *dirname) { static unsigned long long total = 0; DIR *dp = NULL; - struct dirent *ep = NULL; + struct dirent ep; + struct dirent *er = NULL; char abs_filename[FILENAME_MAX] = { 0, };; + dp = opendir(dirname); if (dp != NULL) { - while ((ep = readdir(dp)) != NULL) { + while (readdir_r(dp, &ep, &er) == 0 && er != NULL) { struct stat stFileInfo; snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, - ep->d_name); + ep.d_name); if (stat(abs_filename, &stFileInfo) < 0) perror(abs_filename); @@ -273,8 +286,8 @@ unsigned long long _app2sd_calculate_dir_size(char *dirname) total += stFileInfo.st_size; if (S_ISDIR(stFileInfo.st_mode)) { - if (strcmp(ep->d_name, ".") - && strcmp(ep->d_name, "..")) { + if (strcmp(ep.d_name, ".") + && strcmp(ep.d_name, "..")) { _app2sd_calculate_dir_size (abs_filename); } @@ -313,6 +326,8 @@ char *_app2sd_encrypt_device(const char *device, const char *pkgid, char buf[FILENAME_MAX] = { 0, }; char *ret_result = NULL; int result = 0; + char err_buf[1024] = {0,}; + if (pipe(my_pipe) < 0) { fprintf(stderr, "Unable to create pipe\n"); return NULL; @@ -328,26 +343,29 @@ char *_app2sd_encrypt_device(const char *device, const char *pkgid, close(2); result = dup(my_pipe[1]); if (result < 0) { - fprintf(stderr, "dup failed %d....%s\n", errno, strerror(errno)); - close(result); + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "dup failed %d....%s\n", errno, err_buf); _exit(-1); } result = dup(my_pipe[1]); if (result < 0) { - fprintf(stderr, "dup failed %d....%s\n", errno, strerror(errno)); - close(result); + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "dup failed %d....%s\n", errno, err_buf); _exit(-1); } if (execvp(argv[0], (char *const *)argv) < 0) { - fprintf(stderr, "execvp failed %d....%s\n", errno, strerror(errno)); /*Don't use d_msg_app2sd */ + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "execvp failed %d....%s\n", errno, err_buf); /*Don't use d_msg_app2sd */ } _exit(-1); default: /* parent */ close(my_pipe[1]); result = read(my_pipe[0], buf, FILENAME_MAX); - if (result < 0) - fprintf(stderr, "read failed %d....%s\n", errno, strerror(errno)); + if (result < 0) { + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "read failed %d....%s\n", errno, err_buf); + } break; } @@ -370,6 +388,8 @@ char *_app2sd_detach_loop_device(const char *device) char buf[FILENAME_MAX] = { 0, }; char *ret_result = NULL; int result = 0; + char err_buf[1024] = {0,}; + if (pipe(my_pipe) < 0) { fprintf(stderr, "Unable to create pipe\n"); return NULL; @@ -385,14 +405,14 @@ char *_app2sd_detach_loop_device(const char *device) close(2); result = dup(my_pipe[1]); if (result < 0) { - fprintf(stderr, "dup failed %d....%s\n", errno, strerror(errno)); - close(result); + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "dup failed %d....%s\n", errno, err_buf); _exit(-1); } result = dup(my_pipe[1]); if (result < 0) { - fprintf(stderr, "dup failed %d....%s\n", errno, strerror(errno)); - close(result); + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "dup failed %d....%s\n", errno, err_buf); _exit(-1); } if (execvp(argv[0], (char *const *)argv) < 0) { @@ -403,8 +423,10 @@ char *_app2sd_detach_loop_device(const char *device) /* parent */ close(my_pipe[1]); result = read(my_pipe[0], buf, FILENAME_MAX); - if (result < 0) - fprintf(stderr, "read failed %d....%s\n", errno, strerror(errno)); + if (result < 0) { + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "read failed %d....%s\n", errno, err_buf); + } break; } @@ -428,6 +450,8 @@ char *_app2sd_find_associated_device(const char *mmc_app_path) char buf[FILENAME_MAX] = { 0, }; char *ret_result = NULL; int result = 0; + char err_buf[1024] = {0,}; + if (pipe(my_pipe) < 0) { fprintf(stderr, "Unable to create pipe\n"); return NULL; @@ -443,14 +467,14 @@ char *_app2sd_find_associated_device(const char *mmc_app_path) close(2); result = dup(my_pipe[1]); if (result < 0) { - fprintf(stderr, "dup failed %d....%s\n", errno, strerror(errno)); - close(result); + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "dup failed %d....%s\n", errno, err_buf); _exit(-1); } result = dup(my_pipe[1]); if (result < 0) { - fprintf(stderr, "dup failed %d....%s\n", errno, strerror(errno)); - close(result); + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "dup failed %d....%s\n", errno, err_buf); _exit(-1); } if (execvp(argv[0], (char *const *)argv) < 0) { @@ -461,8 +485,10 @@ char *_app2sd_find_associated_device(const char *mmc_app_path) /* parent */ close(my_pipe[1]); result = read(my_pipe[0], buf, FILENAME_MAX); - if (result < 0) - fprintf(stderr, "read failed %d....%s\n", errno, strerror(errno)); + if (result < 0) { + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "read failed %d....%s\n", errno, err_buf); + } break; } @@ -483,9 +509,11 @@ char *_app2sd_find_free_device(void) const char *argv[] = { "/sbin/losetup", "-f", NULL }; pid_t pid; int my_pipe[2] = { 0, }; - char buf[FILENAME_MAX+1] = { 0, }; + char buf[FILENAME_MAX + 1] = { 0, }; char *ret_result = NULL; int result = 0; + char err_buf[1024] = {0,}; + if (pipe(my_pipe) < 0) { fprintf(stderr, "Unable to create pipe\n"); return NULL; @@ -501,14 +529,14 @@ char *_app2sd_find_free_device(void) close(2); result = dup(my_pipe[1]); if (result < 0) { - fprintf(stderr, "dup failed %d....%s\n", errno, strerror(errno)); - close(result); + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "dup failed %d....%s\n", errno, err_buf); _exit(-1); } result = dup(my_pipe[1]); if (result < 0) { - fprintf(stderr, "dup failed %d....%s\n", errno, strerror(errno)); - close(result); + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "dup failed %d....%s\n", errno, err_buf); _exit(-1); } if (execvp(argv[0], (char *const *)argv) < 0) { @@ -519,8 +547,10 @@ char *_app2sd_find_free_device(void) /* parent */ close(my_pipe[1]); result = read(my_pipe[0], buf, FILENAME_MAX); - if (result < 0) - fprintf(stderr, "read failed %d....%s\n", errno, strerror(errno)); + if (result < 0) { + strerror_r(errno, err_buf, sizeof(err_buf)); + fprintf(stderr, "read failed %d....%s\n", errno, err_buf); + } break; } @@ -549,6 +579,7 @@ char *_app2sd_generate_password(const char *pkgid) int i = 0; int appname_len = strlen(pkgid); int j = appname_len; + unsigned int seed; /* Length of the password */ ret_result = (char*)malloc(PASSWD_LEN+1); @@ -559,8 +590,9 @@ char *_app2sd_generate_password(const char *pkgid) memset((void *)ret_result, '\0', PASSWD_LEN+1); while(i < PASSWD_LEN) { - char_1 = (rand()+pkgid[j--])%ASCII_PASSWD_CHAR; - char_2 = rand()%ASCII_PASSWD_CHAR; + seed = time(NULL); + char_1 = (rand_r(&seed)+pkgid[j--])%ASCII_PASSWD_CHAR; + char_2 = rand_r(&seed)%ASCII_PASSWD_CHAR; passwd[i] = set[char_1]; passwd[i+1] = set[(pkgid[j--])*2]; if (i