From d0350f9dcd8e489f02c833c9169fc2a36a140eec Mon Sep 17 00:00:00 2001 From: "junsuk77.oh" Date: Thu, 11 Apr 2013 23:19:13 +0900 Subject: [PATCH] fix root path to have a pkgid, __ps_run_parser to fork child and do dlopen Change-Id: Ia760a763444e97de068bfe24c6313a68b2f51643 Signed-off-by: junsuk77.oh --- packaging/pkgmgr-info.spec | 2 +- parser/pkgmgr_parser.c | 60 +++++++++++++++++++++++++++++++++------------- parser/pkgmgr_parser_db.c | 7 ++++-- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/packaging/pkgmgr-info.spec b/packaging/pkgmgr-info.spec index f2e9cc3..4433883 100755 --- a/packaging/pkgmgr-info.spec +++ b/packaging/pkgmgr-info.spec @@ -1,6 +1,6 @@ Name: pkgmgr-info Summary: Packager Manager infomation api for package -Version: 0.0.97 +Version: 0.0.99 Release: 1 Group: Application Framework/Package Management License: Apache-2.0 diff --git a/parser/pkgmgr_parser.c b/parser/pkgmgr_parser.c index 92097b9..f89917d 100755 --- a/parser/pkgmgr_parser.c +++ b/parser/pkgmgr_parser.c @@ -276,7 +276,10 @@ static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, void *lib_handle = NULL; int (*plugin_install) (xmlDocPtr, const char *); int ret = -1; - char *ac; + char *ac = NULL; + int cpid = -1; + int status = 0; + int w = 0; switch (action) { case ACTION_INSTALL: @@ -296,25 +299,50 @@ static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, if (!lib_path) { goto END; } - - if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) { - DBGE("dlopen is failed lib_path[%s]\n", lib_path); - goto END; - } - - if ((plugin_install = - dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) { - DBGE("can not find symbol \n"); + /*fork a child*/ + cpid = fork(); + switch (cpid) { + case -1: + DBGE("fork() failed\n"); goto END; + case 0: + /*child process*/ + if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) { + DBGE("dlopen is failed lib_path[%s]\n", lib_path); + exit(-1); + } + if ((plugin_install = + dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) { + DBGE("can not find symbol \n"); + if (lib_handle) + dlclose(lib_handle); + exit(-1); + } + ret = plugin_install(docPtr, pkgid); + if (lib_handle) + dlclose(lib_handle); + exit(ret); + default: + /*parent process*/ + do { + w = waitpid(cpid, &status, WUNTRACED | WCONTINUED); + if (w == -1) { + DBGE("waitpid() failed\n"); + break; + } + } while (!WIFEXITED(status) && !WIFSIGNALED(status)); + if (WIFEXITED(status)) + ret = WEXITSTATUS(status); + else if (WIFSIGNALED(status)) + ret = WTERMSIG(status); + else + ret = 0; + DBGE("Child exit status=%d\n", ret); + break; } - - ret = plugin_install(docPtr, pkgid); - - END: +END: if (lib_path) free(lib_path); - if (lib_handle) - dlclose(lib_handle); return ret; } diff --git a/parser/pkgmgr_parser_db.c b/parser/pkgmgr_parser_db.c index a7d9c20..4f9d10b 100755 --- a/parser/pkgmgr_parser_db.c +++ b/parser/pkgmgr_parser_db.c @@ -1440,6 +1440,7 @@ static int __insert_manifest_info_in_db(manifest_x *mfx) privileges_x *pvs = NULL; privilege_x *pv = NULL; char query[MAX_QUERY_LEN] = { '\0' }; + char root[MAX_QUERY_LEN] = { '\0' }; int ret = -1; char *type = NULL; char *path = NULL; @@ -1465,9 +1466,11 @@ static int __insert_manifest_info_in_db(manifest_x *mfx) path = strdup(mfx->root_path); else{ if (strcmp(type,"rpm")==0) - path = strdup("/usr/apps"); + snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->package); else - path = strdup("/opt/usr/apps"); + snprintf(root, MAX_QUERY_LEN - 1, "/opt/usr/apps/%s", mfx->package); + + path = strdup(root); } snprintf(query, MAX_QUERY_LEN, "insert into package_info(package, package_type, package_version, install_location, package_size, " \ -- 2.7.4