From: junsuk77.oh Date: Thu, 9 May 2013 02:47:57 +0000 (+0900) Subject: get package size using pkg server, clean LOG_TAG X-Git-Tag: submit/tizen_2.1/20130514.054730~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09106729add39cff0e0f3209e3bd329abe83d5ad;p=platform%2Fcore%2Fappfw%2Fslp-pkgmgr.git get package size using pkg server, clean LOG_TAG Signed-off-by: junsuk77.oh --- diff --git a/client/include/pkgmgr-debug.h b/client/include/pkgmgr-debug.h index d8e43c6..3040e7e 100644 --- a/client/include/pkgmgr-debug.h +++ b/client/include/pkgmgr-debug.h @@ -24,21 +24,14 @@ #include -#undef LOG_TAG -#ifndef LOG_TAG -#define LOG_TAG "PKGMGR" -#endif /* LOG_TAG */ - #define _LOGE(fmt, arg...) LOGE(fmt, ##arg) #define _LOGD(fmt, arg...) LOGD(fmt, ##arg) -#define PKGMGR_ENABLE_DLOG #define COLOR_RED "\033[0;31m" #define COLOR_BLUE "\033[0;34m" #define COLOR_END "\033[0;m" -#ifdef PKGMGR_ENABLE_DLOG #define PKGMGR_DEBUG(fmt, ...)\ do\ {\ @@ -64,28 +57,6 @@ } \ while( 0 ) -#else -#define PKGMGR_DEBUG(fmt, ...) \ - do\ - {\ - printf("\n [%s: %s(): %d] " fmt"\n", rindex(__FILE__, '/')+1, __FUNCTION__, __LINE__, ##__VA_ARGS__);\ - } while (0) - -#define PKGMGR_BEGIN() \ - do\ - {\ - printf("\n [%s: %d] : BEGIN >>>> %s() \n", rindex(__FILE__, '/')+1, __LINE__ , __FUNCTION__);\ - } while( 0 ) - -#define PKGMGR_END() \ - do\ - {\ - printf("\n [%s: %d]: END <<<< %s()\n", rindex(__FILE__, '/')+1, __LINE__ , __FUNCTION__); \ - } \ - while( 0 ) -#endif - - #define ret_if(expr) do { \ if (expr) { \ PKGMGR_DEBUG_ERR("(%s) ", #expr); \ diff --git a/client/include/pkgmgr-internal.h b/client/include/pkgmgr-internal.h index d188ac1..8939a3b 100755 --- a/client/include/pkgmgr-internal.h +++ b/client/include/pkgmgr-internal.h @@ -29,10 +29,8 @@ #include #include -#include #include "package-manager-plugin.h" -#include "pkgmgr-debug.h" typedef package_manager_pkg_info_t package_manager_app_info_t; diff --git a/client/src/pkgmgr-internal.c b/client/src/pkgmgr-internal.c index 8e8a360..1c546db 100755 --- a/client/src/pkgmgr-internal.c +++ b/client/src/pkgmgr-internal.c @@ -32,6 +32,7 @@ #include #include "pkgmgr-internal.h" +#include "pkgmgr-debug.h" #include #include @@ -42,6 +43,11 @@ #include "package-manager.h" #include +#undef LOG_TAG +#ifndef LOG_TAG +#define LOG_TAG "PKGMGR" +#endif /* LOG_TAG */ + #define IS_WHITESPACE(CHAR) \ ((CHAR == ' ' || CHAR == '\t' || CHAR == '\r' || CHAR == '\n') ? \ true : false) diff --git a/client/src/pkgmgr.c b/client/src/pkgmgr.c index 914ff01..62950e9 100755 --- a/client/src/pkgmgr.c +++ b/client/src/pkgmgr.c @@ -40,10 +40,15 @@ #include "package-manager.h" #include "pkgmgr-internal.h" +#include "pkgmgr-debug.h" #include "pkgmgr-api.h" #include "comm_client.h" #include "comm_status_broadcast_server.h" +#undef LOG_TAG +#ifndef LOG_TAG +#define LOG_TAG "PKGMGR" +#endif /* LOG_TAG */ static int _get_request_id() { @@ -193,94 +198,6 @@ static void __error_to_string(int errnumber, char **errstr) } } -static int __csc_process(const char *csc_path, char *result_path) -{ - int ret = 0; - int cnt = 0; - int count = 0; - int csc_fail = 0; - int fd = 0; - char *pkgtype = NULL; - char *des = NULL; - char buf[PKG_STRING_LEN_MAX] = {0,}; - char type_buf[1024] = { 0 }; - char des_buf[1024] = { 0 }; - dictionary *csc = NULL; - FILE* file = NULL; - - csc = iniparser_load(csc_path); - retvm_if(csc == NULL, PKGMGR_R_EINVAL, "cannot open parse file [%s]", csc_path); - - file = fopen(result_path, "w"); - tryvm_if(file == NULL, ret = PKGMGR_R_EINVAL, "cannot open result file [%s]", result_path); - - count = iniparser_getint(csc, "csc packages:count", -1); - tryvm_if(count == 0, ret = PKGMGR_R_ERROR, "csc [%s] dont have packages", csc_path); - - snprintf(buf, PKG_STRING_LEN_MAX, "[result]\n"); - fwrite(buf, 1, strlen(buf), file); - snprintf(buf, PKG_STRING_LEN_MAX, "count = %d\n", count); - fwrite(buf, 1, strlen(buf), file); - - for(cnt = 1 ; cnt <= count ; cnt++) - { - snprintf(type_buf, PKG_STRING_LEN_MAX - 1, "csc packages:type_%03d", cnt); - snprintf(des_buf, PKG_STRING_LEN_MAX - 1, "csc packages:description_%03d", cnt); - - pkgtype = iniparser_getstr(csc, type_buf); - des = iniparser_getstr(csc, des_buf); - ret = 0; - - if (pkgtype == NULL) { - csc_fail++; - snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get pkgtype\n", type_buf); - fwrite(buf, 1, strlen(buf), file); - continue; - } else if (des == NULL) { - csc_fail++; - snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get description\n", des_buf); - fwrite(buf, 1, strlen(buf), file); - continue; - } - - snprintf(buf, PKG_STRING_LEN_MAX, "type_%03d = %s\n", cnt, pkgtype); - fwrite(buf, 1, strlen(buf), file); - snprintf(buf, PKG_STRING_LEN_MAX, "description_%03d = %s\n", cnt, des); - fwrite(buf, 1, strlen(buf), file); - - if (strcmp(pkgtype, "tpk") == 0) { - const char *ospinstaller_argv[] = { "/usr/bin/osp-installer", "-c", des, NULL }; - ret = __xsystem(ospinstaller_argv); - } else if (strcmp(pkgtype, "wgt")== 0) { - const char *wrtinstaller_argv[] = { "/usr/bin/wrt-installer", "-c", des, NULL }; - ret = __xsystem(wrtinstaller_argv); - } else { - csc_fail++; - ret = -1; - } - - if (ret != 0) { - char *errstr = NULL; - __error_to_string(ret, &errstr); - snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = fail[%s]\n", cnt, pkgtype, errstr); - } - else - snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = success\n", cnt, pkgtype); - - fwrite(buf, 1, strlen(buf), file); - } - -catch: - iniparser_freedict(csc); - if (file != NULL) { - fflush(file); - fd = fileno(file); - fsync(fd); - fclose(file); - } - return ret; -} - static void __add_op_cbinfo(pkgmgr_client_t * pc, int request_id, const char *req_key, pkgmgr_handler event_cb, void *data) @@ -384,63 +301,375 @@ static void __add_stat_cbinfo(pkgmgr_client_t *pc, int request_id, } } -static void __operation_callback(void *cb_data, const char *req_id, - const char *pkg_type, const char *pkgid, - const char *key, const char *val) +static void __operation_callback(void *cb_data, const char *req_id, + const char *pkg_type, const char *pkgid, + const char *key, const char *val) +{ + pkgmgr_client_t *pc; + req_cb_info *cb_info; + + _LOGD("__operation_callback() req_id[%s] pkg_type[%s] pkgid[%s]" + "key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val); + + pc = (pkgmgr_client_t *) cb_data; + + /* find callback info */ + cb_info = __find_op_cbinfo(pc, req_id); + if (cb_info == NULL) + return; + + _LOGD("__find_op_cbinfo"); + + /* call callback */ + if (cb_info->event_cb) { + cb_info->event_cb(cb_info->request_id, pkg_type, pkgid, key, + val, NULL, cb_info->data); + _LOGD("event_cb is called"); + } + + /*remove callback for last call + if (strcmp(key, "end") == 0) { + __remove_op_cbinfo(pc, cb_info); + _LOGD("__remove_op_cbinfo"); + } + */ + + return; +} + +static void __status_callback(void *cb_data, const char *req_id, + const char *pkg_type, const char *pkgid, + const char *key, const char *val) +{ + pkgmgr_client_t *pc; + listen_cb_info *tmp; + + _LOGD("__status_callback() req_id[%s] pkg_type[%s] pkgid[%s]" + "key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val); + + pc = (pkgmgr_client_t *) cb_data; + + tmp = pc->info.listening.lhead; + while (tmp) { + if (tmp->event_cb(tmp->request_id, pkg_type, pkgid, key, val, + NULL, tmp->data) != 0) + break; + tmp = tmp->next; + } + + return; +} + +static char *__get_req_key(const char *pkg_path) +{ + struct timeval tv; + long curtime; + char timestr[PKG_STRING_LEN_MAX]; + char *str_req_key; + int size; + + gettimeofday(&tv, NULL); + curtime = tv.tv_sec * 1000000 + tv.tv_usec; + snprintf(timestr, sizeof(timestr), "%ld", curtime); + + size = strlen(pkg_path) + strlen(timestr) + 2; + str_req_key = (char *)calloc(size, sizeof(char)); + if (str_req_key == NULL) { + _LOGD("calloc failed"); + return NULL; + } + snprintf(str_req_key, size, "%s_%s", pkg_path, timestr); + + return str_req_key; +} + +static char *__get_type_from_path(const char *pkg_path) +{ + int ret; + char mimetype[255] = { '\0', }; + char extlist[256] = { '\0', }; + char *pkg_type; + + ret = _get_mime_from_file(pkg_path, mimetype, sizeof(mimetype)); + if (ret) { + _LOGE("_get_mime_from_file() failed - error code[%d]\n", + ret); + return NULL; + } + + ret = _get_mime_extension(mimetype, extlist, sizeof(extlist)); + if (ret) { + _LOGE("_get_mime_extension() failed - error code[%d]\n", + ret); + return NULL; + } + + if (strlen(extlist) == 0) + return NULL; + + if (strchr(extlist, ',')) { + extlist[strlen(extlist) - strlen(strchr(extlist, ','))] = '\0'; + } + pkg_type = strchr(extlist, '.') + 1; + return strdup(pkg_type); +} + +static inline int __pkgmgr_read_proc(const char *path, char *buf, int size) +{ + int fd; + int ret; + + if (buf == NULL || path == NULL) + return -1; + + fd = open(path, O_RDONLY); + if (fd < 0) + return -1; + + ret = read(fd, buf, size - 1); + if (ret <= 0) { + close(fd); + return -1; + } else + buf[ret] = 0; + + close(fd); + + return ret; +} + +static inline int __pkgmgr_find_pid_by_cmdline(const char *dname, + const char *cmdline, const char *apppath) +{ + int pid = 0; + + if (strncmp(cmdline, apppath, PKG_STRING_LEN_MAX-1) == 0) { + pid = atoi(dname); + if (pid != getpgid(pid)) + pid = 0; + } + + return pid; +} + + +static int __pkgmgr_proc_iter_kill_cmdline(const char *apppath) +{ + DIR *dp; + struct dirent *dentry; + int pid; + int ret; + char buf[PKG_STRING_LEN_MAX]; + + dp = opendir("/proc"); + if (dp == NULL) { + return -1; + } + + while ((dentry = readdir(dp)) != NULL) { + if (!isdigit(dentry->d_name[0])) + continue; + + snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name); + ret = __pkgmgr_read_proc(buf, buf, sizeof(buf)); + if (ret <= 0) + continue; + + pid = __pkgmgr_find_pid_by_cmdline(dentry->d_name, buf, apppath); + + if (pid > 0) { + int pgid; + + pgid = getpgid(pid); + if (pgid <= 1) { + closedir(dp); + return -1; + } + + if (killpg(pgid, SIGKILL) < 0) { + closedir(dp); + return -1; + } + } + } + + closedir(dp); + return 0; +} + + +static int __app_list_cb (const pkgmgr_appinfo_h handle, + void *user_data) +{ + char *exec = NULL; + pkgmgr_appinfo_get_exec(handle, &exec); + + __pkgmgr_proc_iter_kill_cmdline(exec); + + return 0; +} + +static int __csc_process(const char *csc_path, char *result_path) +{ + int ret = 0; + int cnt = 0; + int count = 0; + int csc_fail = 0; + int fd = 0; + char *pkgtype = NULL; + char *des = NULL; + char buf[PKG_STRING_LEN_MAX] = {0,}; + char type_buf[1024] = { 0 }; + char des_buf[1024] = { 0 }; + dictionary *csc = NULL; + FILE* file = NULL; + + csc = iniparser_load(csc_path); + retvm_if(csc == NULL, PKGMGR_R_EINVAL, "cannot open parse file [%s]", csc_path); + + file = fopen(result_path, "w"); + tryvm_if(file == NULL, ret = PKGMGR_R_EINVAL, "cannot open result file [%s]", result_path); + + count = iniparser_getint(csc, "csc packages:count", -1); + tryvm_if(count == 0, ret = PKGMGR_R_ERROR, "csc [%s] dont have packages", csc_path); + + snprintf(buf, PKG_STRING_LEN_MAX, "[result]\n"); + fwrite(buf, 1, strlen(buf), file); + snprintf(buf, PKG_STRING_LEN_MAX, "count = %d\n", count); + fwrite(buf, 1, strlen(buf), file); + + for(cnt = 1 ; cnt <= count ; cnt++) + { + snprintf(type_buf, PKG_STRING_LEN_MAX - 1, "csc packages:type_%03d", cnt); + snprintf(des_buf, PKG_STRING_LEN_MAX - 1, "csc packages:description_%03d", cnt); + + pkgtype = iniparser_getstr(csc, type_buf); + des = iniparser_getstr(csc, des_buf); + ret = 0; + + if (pkgtype == NULL) { + csc_fail++; + snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get pkgtype\n", type_buf); + fwrite(buf, 1, strlen(buf), file); + continue; + } else if (des == NULL) { + csc_fail++; + snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get description\n", des_buf); + fwrite(buf, 1, strlen(buf), file); + continue; + } + + snprintf(buf, PKG_STRING_LEN_MAX, "type_%03d = %s\n", cnt, pkgtype); + fwrite(buf, 1, strlen(buf), file); + snprintf(buf, PKG_STRING_LEN_MAX, "description_%03d = %s\n", cnt, des); + fwrite(buf, 1, strlen(buf), file); + + if (strcmp(pkgtype, "tpk") == 0) { + const char *ospinstaller_argv[] = { "/usr/bin/osp-installer", "-c", des, NULL }; + ret = __xsystem(ospinstaller_argv); + } else if (strcmp(pkgtype, "wgt")== 0) { + const char *wrtinstaller_argv[] = { "/usr/bin/wrt-installer", "-c", des, NULL }; + ret = __xsystem(wrtinstaller_argv); + } else { + csc_fail++; + ret = -1; + } + + if (ret != 0) { + char *errstr = NULL; + __error_to_string(ret, &errstr); + snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = fail[%s]\n", cnt, pkgtype, errstr); + } + else + snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = success\n", cnt, pkgtype); + + fwrite(buf, 1, strlen(buf), file); + } + +catch: + iniparser_freedict(csc); + if (file != NULL) { + fflush(file); + fd = fileno(file); + fsync(fd); + fclose(file); + } + return ret; +} + +static int __get_size_process(pkgmgr_client * pc, char *pkgid, pkgmgr_handler event_cb) { - pkgmgr_client_t *pc; - req_cb_info *cb_info; + char *req_key = NULL; + int req_id = 0; + int ret =0; + pkgmgrinfo_pkginfo_h handle; + char *pkgtype = NULL; + char *installer_path = NULL; + char *argv[PKG_ARGC_MAX] = { NULL, }; + char *args = NULL; + int argcnt = 0; + int len = 0; + char *temp = NULL; + int i = 0; - _LOGD("__operation_callback() req_id[%s] pkg_type[%s] pkgid[%s]" - "key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val); + pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc; + retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n"); - pc = (pkgmgr_client_t *) cb_data; + ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); + retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_pkginfo failed"); - /* find callback info */ - cb_info = __find_op_cbinfo(pc, req_id); - if (cb_info == NULL) - return; + ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype); + tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_type failed"); - _LOGD("__find_op_cbinfo"); + installer_path = _get_backend_path_with_type(pkgtype); + req_key = __get_req_key(pkgid); + req_id = _get_request_id(); + __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL); - /* call callback */ - if (cb_info->event_cb) { - cb_info->event_cb(cb_info->request_id, pkg_type, pkgid, key, - val, NULL, cb_info->data); - _LOGD("event_cb is called"); + argv[argcnt++] = installer_path; + /* argv[1] */ + argv[argcnt++] = strdup("-k"); + /* argv[2] */ + argv[argcnt++] = req_key; + /* argv[3] */ + argv[argcnt++] = strdup("-d"); + /* argv[4] */ + argv[argcnt++] = strdup(pkgid); + + /*** add quote in all string for special charactor like '\n'*** FIX */ + for (i = 0; i < argcnt; i++) { + temp = g_shell_quote(argv[i]); + len += (strlen(temp) + 1); + g_free(temp); } - /*remove callback for last call - if (strcmp(key, "end") == 0) { - __remove_op_cbinfo(pc, cb_info); - _LOGD("__remove_op_cbinfo"); - } - */ + args = (char *)calloc(len, sizeof(char)); + tryvm_if(args == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail"); - return; -} + strncpy(args, argv[0], len - 1); -static void __status_callback(void *cb_data, const char *req_id, - const char *pkg_type, const char *pkgid, - const char *key, const char *val) -{ - pkgmgr_client_t *pc; - listen_cb_info *tmp; + for (i = 1; i < argcnt; i++) { + strncat(args, " ", strlen(" ")); + temp = g_shell_quote(argv[i]); + strncat(args, temp, strlen(temp)); + g_free(temp); + } + _LOGD("[args] %s [len] %d\n", args, len); - _LOGD("__status_callback() req_id[%s] pkg_type[%s] pkgid[%s]" - "key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val); + /* 6. request install */ + ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_GET_SIZE, pkgtype, pkgid, args, NULL, 1); + if (ret < 0) + _LOGE("request failed, ret=%d\n", ret); - pc = (pkgmgr_client_t *) cb_data; +catch: + for (i = 0; i < argcnt; i++) + free(argv[i]); - tmp = pc->info.listening.lhead; - while (tmp) { - if (tmp->event_cb(tmp->request_id, pkg_type, pkgid, key, val, - NULL, tmp->data) != 0) - break; - tmp = tmp->next; - } + if(args) + free(args); - return; + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + return ret; } API pkgmgr_client *pkgmgr_client_new(client_type ctype) @@ -563,60 +792,6 @@ API int pkgmgr_client_free(pkgmgr_client *pc) return PKGMGR_R_ERROR; } -static char *__get_req_key(const char *pkg_path) -{ - struct timeval tv; - long curtime; - char timestr[PKG_STRING_LEN_MAX]; - char *str_req_key; - int size; - - gettimeofday(&tv, NULL); - curtime = tv.tv_sec * 1000000 + tv.tv_usec; - snprintf(timestr, sizeof(timestr), "%ld", curtime); - - size = strlen(pkg_path) + strlen(timestr) + 2; - str_req_key = (char *)calloc(size, sizeof(char)); - if (str_req_key == NULL) { - _LOGD("calloc failed"); - return NULL; - } - snprintf(str_req_key, size, "%s_%s", pkg_path, timestr); - - return str_req_key; -} - -static char *__get_type_from_path(const char *pkg_path) -{ - int ret; - char mimetype[255] = { '\0', }; - char extlist[256] = { '\0', }; - char *pkg_type; - - ret = _get_mime_from_file(pkg_path, mimetype, sizeof(mimetype)); - if (ret) { - _LOGE("_get_mime_from_file() failed - error code[%d]\n", - ret); - return NULL; - } - - ret = _get_mime_extension(mimetype, extlist, sizeof(extlist)); - if (ret) { - _LOGE("_get_mime_extension() failed - error code[%d]\n", - ret); - return NULL; - } - - if (strlen(extlist) == 0) - return NULL; - - if (strchr(extlist, ',')) { - extlist[strlen(extlist) - strlen(strchr(extlist, ','))] = '\0'; - } - pkg_type = strchr(extlist, '.') + 1; - return strdup(pkg_type); -} - API int pkgmgr_client_install(pkgmgr_client * pc, const char *pkg_type, const char *descriptor_path, const char *pkg_path, const char *optional_file, pkgmgr_mode mode, @@ -871,102 +1046,6 @@ catch: return ret; } -static inline int __pkgmgr_read_proc(const char *path, char *buf, int size) -{ - int fd; - int ret; - - if (buf == NULL || path == NULL) - return -1; - - fd = open(path, O_RDONLY); - if (fd < 0) - return -1; - - ret = read(fd, buf, size - 1); - if (ret <= 0) { - close(fd); - return -1; - } else - buf[ret] = 0; - - close(fd); - - return ret; -} - -static inline int __pkgmgr_find_pid_by_cmdline(const char *dname, - const char *cmdline, const char *apppath) -{ - int pid = 0; - - if (strncmp(cmdline, apppath, PKG_STRING_LEN_MAX-1) == 0) { - pid = atoi(dname); - if (pid != getpgid(pid)) - pid = 0; - } - - return pid; -} - - -static int __pkgmgr_proc_iter_kill_cmdline(const char *apppath) -{ - DIR *dp; - struct dirent *dentry; - int pid; - int ret; - char buf[PKG_STRING_LEN_MAX]; - - dp = opendir("/proc"); - if (dp == NULL) { - return -1; - } - - while ((dentry = readdir(dp)) != NULL) { - if (!isdigit(dentry->d_name[0])) - continue; - - snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name); - ret = __pkgmgr_read_proc(buf, buf, sizeof(buf)); - if (ret <= 0) - continue; - - pid = __pkgmgr_find_pid_by_cmdline(dentry->d_name, buf, apppath); - - if (pid > 0) { - int pgid; - - pgid = getpgid(pid); - if (pgid <= 1) { - closedir(dp); - return -1; - } - - if (killpg(pgid, SIGKILL) < 0) { - closedir(dp); - return -1; - } - } - } - - closedir(dp); - return 0; -} - - -static int __app_list_cb (const pkgmgr_appinfo_h handle, - void *user_data) -{ - char *exec = NULL; - pkgmgr_appinfo_get_exec(handle, &exec); - - __pkgmgr_proc_iter_kill_cmdline(exec); - - return 0; -} - - API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type, const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb, void *data) @@ -1690,36 +1769,24 @@ API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, pkgmgr_client * pc, const char *pkg_type, const char *pkgid, const char *custom_info, pkgmgr_handler event_cb, void *data) { - char *installer_path = NULL; - char *req_key = NULL; - int req_id = 0; int ret =0; /* Check for NULL value of service type */ retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n"); retvm_if(service_type < 0, PKGMGR_R_EINVAL, "service type is error\n"); - /* check optional_file length */ - if (custom_info) - retvm_if(strlen(custom_info) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "optional_file over PKG_STRING_LEN_MAX"); - - /* add callback info - add callback info to pkgmgr_client if there is pc and pkgid */ - if (pc && pkgid) { - pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc; - retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL); - req_key = __get_req_key(pkgid); - req_id = _get_request_id(); - __add_op_cbinfo(mpc, req_id, req_key, event_cb, data); - } - switch (service_type) { case PM_REQUEST_CSC: tryvm_if(custom_info == NULL, ret = PKGMGR_R_EINVAL, "custom_info is NULL\n"); + tryvm_if(strlen(custom_info) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "optional_file over PKG_STRING_LEN_MAX"); tryvm_if(data == NULL, ret = PKGMGR_R_EINVAL, "data is NULL\n"); ret = __csc_process(custom_info, (char *)data); if (ret < 0) _LOGE("__csc_process fail \n"); + else + ret = PKGMGR_R_OK; + break; case PM_REQUEST_MOVE: @@ -1727,18 +1794,24 @@ API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, break; case PM_REQUEST_GET_SIZE: - ret = 0; + tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n"); + tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n"); + + ret = __get_size_process(pc, pkgid, event_cb); + if (ret < 0) + _LOGE("__get_size_process fail \n"); + else + ret = PKGMGR_R_OK; + break; default: - printf("Wrong Request\n"); + _LOGE("Wrong Request\n"); ret = -1; break; } catch: - if (req_key) - free(req_key); return ret; } diff --git a/comm/comm_config.h b/comm/comm_config.h index a73d211..adb09f5 100755 --- a/comm/comm_config.h +++ b/comm/comm_config.h @@ -111,6 +111,9 @@ enum { /* cancel job */ COMM_REQ_CANCEL, + /*get package size */ + COMM_REQ_GET_SIZE, + COMM_REQ_MAX_SENTINEL }; diff --git a/comm/pkgmgr_installer.c b/comm/pkgmgr_installer.c index ebe60f3..37ddcd0 100755 --- a/comm/pkgmgr_installer.c +++ b/comm/pkgmgr_installer.c @@ -39,6 +39,11 @@ #include +#undef LOG_TAG +#ifndef LOG_TAG +#define LOG_TAG "PKGMGR_INSTALLER" +#endif /* LOG_TAG */ + #define MAX_STRLEN 1024 #define MAX_QUERY_LEN 4096 diff --git a/comm/pkgmgr_installer.h b/comm/pkgmgr_installer.h index e4fb12c..aed5b6a 100755 --- a/comm/pkgmgr_installer.h +++ b/comm/pkgmgr_installer.h @@ -42,10 +42,6 @@ extern "C" { #include #include -#undef LOG_TAG -#ifndef LOG_TAG -#define LOG_TAG "PKGMGR_INSTALLER" -#endif /* LOG_TAG */ #define _LOGE(fmt, arg...) LOGE(fmt,##arg) @@ -66,7 +62,8 @@ enum { PKGMGR_REQ_CLEAR = 3, PKGMGR_REQ_MOVE = 4, PKGMGR_REQ_RECOVER = 5, - PKGMGR_REQ_REINSTALL = 6 + PKGMGR_REQ_REINSTALL = 6, + PKGMGR_REQ_GETSIZE = 7 }; enum { diff --git a/packaging/pkgmgr.spec b/packaging/pkgmgr.spec index 50f641b..4284371 100755 --- a/packaging/pkgmgr.spec +++ b/packaging/pkgmgr.spec @@ -1,7 +1,7 @@ #sbs-git:slp/pkgs/s/slp-pkgmgr pkgmgr 0.1.103 29b53909a5d6e8728429f0a188177eac691cb6ce Name: pkgmgr Summary: Packager Manager client library package -Version: 0.2.82 +Version: 0.2.83 Release: 1 Group: System/Libraries License: Apache License, Version 2.0 @@ -133,6 +133,7 @@ mkdir -p /usr/etc/package-manager/server %defattr(-,root,root,-) %{_bindir}/pkgcmd %{_bindir}/pkg_initdb +%{_bindir}/pkg_getsize %{_bindir}/pkginfo %{_bindir}/pkgmgr-install %{_datadir}/packages/org.tizen.pkgmgr-install.xml diff --git a/server/src/pkgmgr-server.c b/server/src/pkgmgr-server.c index 06889ef..82dc55b 100755 --- a/server/src/pkgmgr-server.c +++ b/server/src/pkgmgr-server.c @@ -1034,6 +1034,16 @@ void req_cb(void *cb_data, const char *req_id, const int req_type, free(item); *ret = COMM_RET_OK; break; + case COMM_REQ_GET_SIZE: + err = _pm_queue_push(item); + p = __get_position_from_pkg_type(item->pkg_type); + __set_backend_mode(p); + /* Free resource */ + free(item); + if (err == 0) + g_idle_add(queue_job, NULL); + *ret = COMM_RET_OK; + break; default: DBG("Check your request..\n"); *ret = COMM_RET_ERROR; @@ -1516,6 +1526,100 @@ pop: break; } break; + + case COMM_REQ_GET_SIZE: + DBG("COMM_REQ_GET_SIZE pkgid = %s\n", item->pkgid); + _save_queue_status(item, "processing"); + DBG("saved queue status. Now try fork()"); + /*save pkg type and pkg name for future*/ + x = (pos + num_of_backends - 1) % num_of_backends; + strncpy((ptr + x)->pkgtype, item->pkg_type, MAX_PKG_TYPE_LEN-1); + strncpy((ptr + x)->pkgid, item->pkgid, MAX_PKG_NAME_LEN-1); + strncpy((ptr + x)->args, item->args, MAX_PKG_ARGS_LEN-1); + (ptr + x)->pid = fork(); + DBG("child forked [%d]\n", (ptr + x)->pid); + + switch ((ptr + x)->pid) { + case 0: /* child */ + DBG("before run _get_backend_cmd()"); + backend_cmd = strdup("/usr/bin/pkg_getsize"); + if (NULL == backend_cmd) + break; + + DBG("Try to exec [%s][%s]", item->pkg_type, + backend_cmd); + fprintf(stdout, "Try to exec [%s][%s]\n", + item->pkg_type, backend_cmd); + + /* Create args vector + * req_id + pkgid + args + * + * vector size = # of args + + *(req_id + pkgid + NULL termination = 3) + * Last value must be NULL for execv. + */ + gboolean ret_parse; + gint argcp; + gchar **argvp; + GError *gerr = NULL; + ret_parse = g_shell_parse_argv(item->args, + &argcp, &argvp, &gerr); + if (FALSE == ret_parse) { + DBG("Failed to split args: %s", item->args); + DBG("messsage: %s", gerr->message); + exit(1); + } + + /* Setup argument !!! */ + /*char **args_vector = + calloc(argcp + 4, sizeof(char *)); */ + char **args_vector = calloc(argcp + 1, sizeof(char *)); + /*args_vector[0] = strdup(backend_cmd); + args_vector[1] = strdup(item->req_id); + args_vector[2] = strdup(item->pkgid); */ + int arg_idx; + for (arg_idx = 0; arg_idx < argcp; arg_idx++) { + /* args_vector[arg_idx+3] = argvp[arg_idx]; */ + args_vector[arg_idx] = argvp[arg_idx]; + } + + /* dbg */ + /*for(arg_idx = 0; arg_idx < argcp+3; arg_idx++) { */ + for (arg_idx = 0; arg_idx < argcp + 1; arg_idx++) { + DBG(">>>>>> args_vector[%d]=%s", + arg_idx, args_vector[arg_idx]); + } + + /* Execute backend !!! */ + ret = execv(backend_cmd, args_vector); + + /* Code below: exec failure. Should not be happened! */ + DBG(">>>>>> OOPS 2!!!"); + + /* g_strfreev(args_vector); *//* FIXME: causes error */ + + if (ret == -1) { + perror("fail to exec"); + exit(1); + } + _save_queue_status(item, "done"); + if (NULL != backend_cmd) + free(backend_cmd); + exit(0); + break; + + case -1: /* error */ + fprintf(stderr, "Fail to execute fork()\n"); + exit(1); + break; + + default: /* parent */ + DBG("parent \n"); + _save_queue_status(item, "done"); + break; + } + break; + default: break; } diff --git a/server/src/pm-queue.c b/server/src/pm-queue.c index 33ed498..948e665 100755 --- a/server/src/pm-queue.c +++ b/server/src/pm-queue.c @@ -399,13 +399,11 @@ void _pm_queue_final() cur = head[c]->next; while (cur->next) { - printf(" -- [%p]\n", cur); prev = cur; cur = cur->next; } tail = cur; - printf("%p\n", tail); free(tail->msg); free(tail); @@ -479,9 +477,7 @@ void _save_queue_status(pm_dbus_msg *item, char *status) } fprintf(fp_status, "%s\n", status); - printf("[%s]\n", status); fprintf(fp_status, "%s\n", item->pkg_type); - printf("[%s]\n", item->pkg_type); fsync(fp_status->_fileno); fclose(fp_status); @@ -502,18 +498,10 @@ void _print_queue(int position) } int index = 1; if (!cur) { - printf(" ** queue is NULL **\n"); return; } while (cur) { - printf(" * queue[%d]: [%s] [%d] [%s] [%s] [%s] [%s]\n", - index, - cur->msg->req_id, - cur->msg->req_type, - cur->msg->pkg_type, - cur->msg->pkgid, cur->msg->args, cur->msg->cookie); - index++; cur = cur->next; } diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt index 936c1c1..28a6ae5 100755 --- a/tool/CMakeLists.txt +++ b/tool/CMakeLists.txt @@ -32,6 +32,11 @@ add_executable(pkginfo target_link_libraries(pkginfo pkgmgr-client pkgmgr_installer ${pkgs_test_LDFLAGS}) INSTALL(TARGETS pkginfo DESTINATION bin) +add_executable(pkg_getsize + pkg_getsize.c) +target_link_libraries(pkg_getsize pkgmgr-client pkgmgr_installer ${pkgs_test_LDFLAGS}) +INSTALL(TARGETS pkg_getsize DESTINATION bin) + add_executable(pkg_initdb pkg_initdb.c) target_link_libraries(pkg_initdb ${pkgs_test_LDFLAGS}) diff --git a/tool/pkg_cmd.c b/tool/pkg_cmd.c index a2976d1..33e2feb 100755 --- a/tool/pkg_cmd.c +++ b/tool/pkg_cmd.c @@ -59,13 +59,14 @@ static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option); static int __app_list_cb(const pkgmgr_appinfo_h handle, void *user_data); /* Supported options */ -const char *short_options = "iurmcCkaADL:lsd:p:t:n:T:S:qh"; +const char *short_options = "iurmcgCkaADL:lsd:p:t:n:T:S:qh"; const struct option long_options[] = { {"install", 0, NULL, 'i'}, {"uninstall", 0, NULL, 'u'}, {"reinstall", 0, NULL, 'r'}, {"move", 0, NULL, 'm'}, {"clear", 0, NULL, 'c'}, + {"getsize", 0, NULL, 'g'}, {"activate", 0, NULL, 'A'}, {"deactivate", 0, NULL, 'D'}, {"activate with Label", 1, NULL, 'L'}, @@ -90,6 +91,7 @@ enum pm_tool_request_e { UNINSTALL_REQ, REINSTALL_REQ, CSC_REQ, + GETSIZE_REQ, CLEAR_REQ, MOVE_REQ, ACTIVATE_REQ, @@ -214,7 +216,11 @@ static int __return_cb(int req_id, const char *pkg_type, else printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d]\n", req_id, pkg_type, pkgid, key, ret_val); - } else + } else if (strncmp(key, "size", strlen("size")) == 0) { + printf("pkg[%s] size = %d\n", pkgid, atoi(val)); + g_main_loop_quit(main_loop); + } + else printf("__return_cb req_id[%d] pkg_type[%s] " "pkgid[%s] key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val); @@ -422,6 +428,7 @@ static void __print_usage() printf("-r, --reinstall reinstall the package\n"); printf("-c, --clear clear user data\n"); printf("-m, --move move package\n"); + printf("-g, --getsize get size of given package\n"); printf("-l, --list display list of installed packages\n"); printf("-s, --show show detail package info\n"); printf("-a, --app-path show app installation path\n"); @@ -443,6 +450,7 @@ static void __print_usage() printf("pkgcmd -s -t -p (-q)\n"); printf("pkgcmd -s -t -n (-q)\n"); printf("pkgcmd -m -t -T -n (-q)\n\n"); + printf("pkgcmd -g -n \n"); printf("Example:\n"); printf("pkgcmd -u -t rpm -n org.tizen.calculator\n"); @@ -456,6 +464,7 @@ static void __print_usage() printf("pkgcmd -a -t rpm -n org.tizen.hello\n"); printf("pkgcmd -l\n"); printf("pkgcmd -l -t tpk\n"); + printf("pkgcmd -g -n com.samsung.calculator\n"); exit(0); @@ -974,6 +983,34 @@ static int __process_request() data.result = PKGCMD_ERR_FATAL_ERROR; break; + case GETSIZE_REQ: + if (data.pkgid[0] == '\0') { + printf("Please provide the arguments.\n"); + printf("use -h option to see usage\n"); + data.result = PKGCMD_ERR_ARGUMENT_INVALID; + break; + } + + g_type_init(); + main_loop = g_main_loop_new(NULL, FALSE); + pc = pkgmgr_client_new(PC_REQUEST); + if (pc == NULL) { + printf("PkgMgr Client Creation Failed\n"); + data.result = PKGCMD_ERR_FATAL_ERROR; + break; + } + + ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, 0, pc, NULL, data.pkgid, NULL, __return_cb, NULL); + if (ret < 0){ + data.result = PKGCMD_ERR_FATAL_ERROR; + if (access(data.pkg_path, F_OK) != 0) + data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND; + break; + } + g_main_loop_run(main_loop); + ret = data.result; + break; + case HELP_REQ: __print_usage(); ret = 0; @@ -1058,6 +1095,10 @@ int main(int argc, char *argv[]) data.request = CLEAR_REQ; break; + case 'g': /* get pkg size */ + data.request = GETSIZE_REQ; + break; + case 'm': /* move */ data.request = MOVE_REQ; break; diff --git a/tool/pkg_getsize.c b/tool/pkg_getsize.c new file mode 100644 index 0000000..11822e0 --- /dev/null +++ b/tool/pkg_getsize.c @@ -0,0 +1,101 @@ +/* + * slp-pkgmgr + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#define _GNU_SOURCE + +#include +#include +#include + +#include + +#include "pkgmgr_installer.h" +#include "pkgmgr-debug.h" + +#undef LOG_TAG +#ifndef LOG_TAG +#define LOG_TAG "PKGMGR" +#endif /* LOG_TAG */ + +#define MAX_PKG_BUF_LEN 128 + +static int _pkg_getsize(int argc, char **argv) +{ + int ret = 0; + char *pkgid = NULL; + char *type = NULL; + pkgmgr_installer *pi = NULL; + pkgmgrinfo_pkginfo_h handle; + int size = 0; + char buf[MAX_PKG_BUF_LEN] = {'\0'}; + + /*make new pkgmgr_installer handle*/ + pi = pkgmgr_installer_new(); + retvm_if(!pi, PMINFO_R_ERROR, "service type is error\n"); + + /*get args*/ + ret = pkgmgr_installer_receive_request(pi, argc, argv); + tryvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgr_installer_receive_request failed"); + + /*get pkgid from installer handle*/ + pkgid = pkgmgr_installer_get_request_info(pi); + tryvm_if(pkgid == NULL, ret = PMINFO_R_ERROR, "pkgmgr_installer_get_request_info failed"); + + /*get pkgmgr handle from pkgid*/ + ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); + tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_pkginfo_get_pkginfo[pkgid=%s] failed", pkgid); + + /*get type info from handle*/ + ret = pkgmgrinfo_pkginfo_get_type(handle, &type); + tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_pkginfo_get_type[pkgid=%s] failed", pkgid); + + /*get size info from handle*/ + ret = pkgmgrinfo_pkginfo_get_total_size(handle, &size); + tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_pkginfo_get_total_size[pkgid=%s] failed", pkgid); + + snprintf(buf, MAX_PKG_BUF_LEN - 1, "%d", size); + + /*send size to dbus*/ + ret =pkgmgr_installer_send_signal(pi, type, pkgid, "size", buf); + tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_installer_send_signal[pkgid=%s] failed", pkgid); + +catch: + + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + pkgmgr_installer_free(pi); + + return ret; +} + +int main(int argc, char *argv[]) +{ + int ret = 0; + + ret = _pkg_getsize(argc, argv); + if (ret < 0) { + _LOGE("_pkg_getsize failed \n"); + return -1; + } + + _LOGE("_pkg_getsize success \n"); + return 0; +}