From f08894aa54cc9618c8d2fbc67f36f722db9b36dd Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 26 Feb 2016 13:33:15 +0900 Subject: [PATCH 01/16] Fix getting appinfo Consider widget application also. Change-Id: I789262f7e1c711f5d8db5e7b700337f9e30db01f Signed-off-by: Sangyoon Jang --- src/pkg_info.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pkg_info.c b/src/pkg_info.c index 6eb8605..e5c89d0 100644 --- a/src/pkg_info.c +++ b/src/pkg_info.c @@ -1489,8 +1489,9 @@ int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data) if (apptype) printf("Apptype: %s\n", apptype); - if (component == PMINFO_UI_APP) { - printf("component: uiapp\n"); + if (component == PMINFO_UI_APP || component == PMINFO_WIDGET_APP) { + printf("component: %s\n", component == PMINFO_UI_APP ? "uiapp" : + "widgetapp"); ret = pkgmgrinfo_appinfo_is_multiple(handle, &multiple); if (ret < 0) { printf("Failed to get multiple\n"); @@ -1908,8 +1909,9 @@ static int __get_app_info(char *appid) if (apptype) printf("Apptype: %s\n", apptype); - if (component == PMINFO_UI_APP) { - printf("component: uiapp\n"); + if (component == PMINFO_UI_APP || component == PMINFO_WIDGET_APP) { + printf("component: %s\n", component == PMINFO_UI_APP ? "uiapp" : + "widgetapp"); if (icon) printf("Icon: %s\n", icon); -- 2.7.4 From 89056f1c8901e28309143d8fc8ccfb66478e8607 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Tue, 23 Feb 2016 21:59:04 +0900 Subject: [PATCH 02/16] add a tool for preload tpk install Change-Id: I87fe3e12dae579f3f387d6774981971f5f06b8a3 Signed-off-by: jongmyeongko --- CMakeLists.txt | 4 ++ packaging/pkgmgr-tool.spec | 2 + src/install_preload_tpk.c | 113 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 src/install_preload_tpk.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 8123f61..44cef0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,10 @@ ADD_EXECUTABLE(pkg_initdb src/pkg_initdb.c) TARGET_LINK_LIBRARIES(pkg_initdb ${pkgs_initdb_LDFLAGS}) INSTALL(TARGETS pkg_initdb DESTINATION bin) +ADD_EXECUTABLE(install_preload_tpk src/install_preload_tpk.c) +TARGET_LINK_LIBRARIES(install_preload_tpk ${pkgs_test_LDFLAGS}) +INSTALL(TARGETS install_preload_tpk DESTINATION bin) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/10_package-manager-add.post DESTINATION ${SYSCONF_INSTALL_DIR}/gumd/useradd.d/) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/mime.wac.xml DESTINATION /usr/share/mime/packages/) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index 24e84be..dc4a2a5 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -57,6 +57,7 @@ chsmack -a '*' %{TZ_SYS_RW_PACKAGES} %posttrans pkg_initdb +install_preload_tpk %files %manifest %{name}.manifest @@ -69,6 +70,7 @@ pkg_initdb %{_bindir}/pkg_getsize %{_bindir}/pkg_clearcache %{_bindir}/pkginfo +%attr(0755,root,root) %{_bindir}/install_preload_tpk %{_datadir}/mime/packages/mime.wac.xml %{_datadir}/mime/packages/mime.tpk.xml %attr(0700,root,root) /etc/package-manager/pkgmgr-unzip-tpk.sh diff --git a/src/install_preload_tpk.c b/src/install_preload_tpk.c new file mode 100644 index 0000000..5bdbdce --- /dev/null +++ b/src/install_preload_tpk.c @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 +#include +#include + +#include + +#define OWNER_ROOT 0 +#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) +#define BUFSZE 4096 + +#ifdef _E +#undef _E +#endif +#define _E(fmt, arg...) fprintf(stderr, "[TPK_PRELOAD_INSTALL][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); + +#ifdef _D +#undef _D +#endif +#define _D(fmt, arg...) fprintf(stderr, "[TPK_PRELOAD_INSTALL][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); + +#define BACKEND_CMD "/usr/bin/tpk-backend" + +static int _install_preload_tpk(uid_t uid, const char *directory) +{ + DIR *dir; + struct dirent file_info, *result; + int ret; + char buf[BUFSZE]; + + dir = opendir(directory); + if (!dir) { + _E("Failed to access the [%s] because %s", directory, + strerror_r(errno, buf, sizeof(buf))); + return -1; + } + + _D("Loading tpk files from %s", directory); + + for (ret = readdir_r(dir, &file_info, &result); + ret == 0 && result != NULL; + ret = readdir_r(dir, &file_info, &result)) { + if (file_info.d_name[0] == '.') + continue; + + snprintf(buf, sizeof(buf), "%s/%s", directory, file_info.d_name); + _D("tpk file %s", buf); + + pid_t pid = fork(); + if (pid == 0) { + setuid(uid); + execl(BACKEND_CMD, BACKEND_CMD, "-i", buf, "--preload", + (char*)NULL); + } else if (pid < 0) { + _E("failed to fork and execute %s!", BACKEND_CMD); + closedir(dir); + return -1; + } + if (pid > 0) { + int status = 0; + waitpid(pid, &status, 0); + } + } + + closedir(dir); + + return 0; +} + +static int _is_authorized(uid_t uid) +{ + /* install_preload_tpk should be called by as root privilege. */ + if ((uid_t) OWNER_ROOT == uid) + return 1; + else + return 0; +} + +int main(int argc, char *argv[]) +{ + int ret; + const char *dir = tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-tpk"); + uid_t uid = getuid(); + + if (!_is_authorized(uid)) { + _E("You are not an authorized user!"); + return -1; + } + + return _install_preload_tpk(uid, dir); +} -- 2.7.4 From 2d8ec9343018f417671051a97d92cf2311533792 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Sun, 6 Mar 2016 15:04:09 +0900 Subject: [PATCH 03/16] use strncat instead of strcat for secure code Change-Id: Ia485a0c92c8f0f691c30c462178f23cb234ccdd0 Signed-off-by: Junghyun Yeon --- src/pkg_getsize.c | 14 +++++++------- src/pkg_info.c | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/pkg_getsize.c b/src/pkg_getsize.c index 60acbb3..879b674 100644 --- a/src/pkg_getsize.c +++ b/src/pkg_getsize.c @@ -389,24 +389,24 @@ static char *__get_pkg_size_info_str(const pkg_size_info_t* pkg_size_info) return NULL; } - snprintf(size_info_str, MAX_LONGLONG_LENGTH, "%lld", + snprintf(size_info_str, MAX_SIZE_INFO_SIZE, "%lld", pkg_size_info->data_size); - strcat(size_info_str, ":"); + strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1); snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, "%lld", pkg_size_info->cache_size); - strcat(size_info_str, ":"); + strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1); snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, "%lld", pkg_size_info->app_size); - strcat(size_info_str, ":"); + strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1); snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, "%lld", pkg_size_info->ext_data_size); - strcat(size_info_str, ":"); + strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1); snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, "%lld", pkg_size_info->ext_cache_size); - strcat(size_info_str, ":"); + strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1); snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, "%lld", pkg_size_info->ext_app_size); - strcat(size_info_str, ":"); + strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1); DBG("size_info_str: %s", size_info_str); diff --git a/src/pkg_info.c b/src/pkg_info.c index e5c89d0..a57fd66 100644 --- a/src/pkg_info.c +++ b/src/pkg_info.c @@ -631,7 +631,6 @@ static int __add_app_filter(uid_t uid) break; default: printf("Invalid filter property\n"); - pkgmgrinfo_appinfo_filter_destroy(handle); ret = -1; goto err; } -- 2.7.4 From c473073692ecfe4355e8262e0d66b264da8c4417 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Wed, 9 Mar 2016 18:14:18 +0900 Subject: [PATCH 04/16] add debug-mode option (-G) Change-Id: I0a69aa9eccc92a581605b5a0a49ab40d57568124 Signed-off-by: jongmyeongko --- src/pkg_cmd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pkg_cmd.c b/src/pkg_cmd.c index cd4bb57..6c6d019 100644 --- a/src/pkg_cmd.c +++ b/src/pkg_cmd.c @@ -67,7 +67,7 @@ static int __convert_to_absolute_path(char *path); /* Supported options */ /* Note: 'G' is reserved */ -const char *short_options = "iurmcgCkaADL:lsd:p:t:n:T:S:e:M:X:Y:Z:qh"; +const char *short_options = "iurmcgCkaADL:lsd:p:t:n:T:S:e:M:X:Y:Z:qhG"; const struct option long_options[] = { {"install", 0, NULL, 'i'}, {"uninstall", 0, NULL, 'u'}, @@ -101,6 +101,7 @@ const struct option long_options[] = { {"add-blacklist", 1, NULL, OPTVAL_ADD_BLACKLIST}, {"remove-blacklist", 1, NULL, OPTVAL_REMOVE_BLACKLIST}, {"check-blacklist", 1, NULL, OPTVAL_CHECK_BLACKLIST}, + {"debug-mode", 0, NULL, 'G'}, {0, 0, 0, 0} /* sentinel */ }; @@ -448,6 +449,7 @@ static void __print_usage() printf("--add-blacklist add a package to blacklist\n"); printf("--remove-blacklist remove a package from blacklist\n"); printf("--check-blacklist check if the given package is blacklisted\n"); + printf("-G, --debug-mode install the package with debug mode for sdk\n"); printf("-h, --help . print this help\n\n"); printf("Usage: pkgcmd [options]\n"); @@ -1268,6 +1270,9 @@ int main(int argc, char *argv[]) case 'q': /* quiet mode is removed */ break; + case 'G': /* debug mode */ + break; + case OPTVAL_ADD_BLACKLIST: data.request = ADD_BLACKLIST_REQ; if (optarg) -- 2.7.4 From 96cc6448256a2071d5fab0c11307d07343aae060 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Sat, 12 Mar 2016 14:26:42 +0900 Subject: [PATCH 05/16] suppress build warnings Change-Id: Iea0c6ccb96fbd96d9d3dfffd7a0757b34d3a116e Signed-off-by: Junghyun Yeon --- src/install_preload_tpk.c | 9 +++++-- src/pkg_cmd.c | 64 +++++++++++------------------------------------ src/pkg_initdb.c | 9 ++++++- 3 files changed, 29 insertions(+), 53 deletions(-) diff --git a/src/install_preload_tpk.c b/src/install_preload_tpk.c index 5bdbdce..e9d7e7b 100644 --- a/src/install_preload_tpk.c +++ b/src/install_preload_tpk.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include @@ -70,7 +72,11 @@ static int _install_preload_tpk(uid_t uid, const char *directory) pid_t pid = fork(); if (pid == 0) { - setuid(uid); + if (setuid(uid) != 0) { + _E("failed to set uid"); + closedir(dir); + return -1; + } execl(BACKEND_CMD, BACKEND_CMD, "-i", buf, "--preload", (char*)NULL); } else if (pid < 0) { @@ -100,7 +106,6 @@ static int _is_authorized(uid_t uid) int main(int argc, char *argv[]) { - int ret; const char *dir = tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-tpk"); uid_t uid = getuid(); diff --git a/src/pkg_cmd.c b/src/pkg_cmd.c index 6c6d019..1540353 100644 --- a/src/pkg_cmd.c +++ b/src/pkg_cmd.c @@ -339,8 +339,7 @@ static int __convert_to_absolute_tep_path(char *path) } strncpy(temp, path, PATH_MAX - 1); if (strchr(path, '/') == NULL) { - getcwd(abs, PATH_MAX - 1); - if (abs[0] == '\0') { + if (getcwd(abs, PATH_MAX - 1) == NULL || abs[0] == '\0') { printf("getcwd() failed\n"); return -1; } @@ -350,8 +349,7 @@ static int __convert_to_absolute_tep_path(char *path) } if (strncmp(path, "./", 2) == 0) { ptr = temp; - getcwd(abs, PATH_MAX - 1); - if (abs[0] == '\0') { + if (getcwd(abs, PATH_MAX - 1) == NULL || abs[0] == '\0') { printf("getcwd() failed\n"); return -1; } @@ -381,48 +379,6 @@ static int __is_app_installed(char *pkgid, uid_t uid) return 0; } -static char *__get_pkgid_from_tep(const char *filename) -{ - char *pkg_type = NULL; - char pkg_file[PATH_MAX] = { '\0', }; - char *tmp = NULL; - char *pkgid = NULL; - size_t pkgid_len = 0; - - if (strrchr(filename, '/')) { - strncpy(pkg_file, strrchr(filename, '/') + 1, PATH_MAX - 1); - } else { - strncpy(pkg_file, filename, PATH_MAX - 1); - } - - pkg_type = strrchr(pkg_file, '.'); - if (pkg_type == NULL) { - printf("pkg_type is null[%s]\n", filename); - return NULL; - } else { - pkg_type++; - } - - if (strcmp(pkg_type, "tep") != 0) - return NULL; - - tmp = strrchr(pkg_file, '-'); - if (tmp == NULL || strlen(tmp) == 0) { - printf("Invalid tep file name!!!\n"); - return NULL; - } - - pkgid_len = tmp - pkg_file; - pkgid = calloc(1, pkgid_len + 1); - if (pkgid == NULL) { - printf("Insufficient Memory\n"); - return NULL; - } - memcpy((void *)pkgid, (const void *)pkg_file, pkgid_len); - - return pkgid; -} - static void __print_usage() { printf("\nPackage Manager Tool Version: %s\n\n", PKG_TOOL_VERSION); @@ -554,7 +510,6 @@ static int __process_request(uid_t uid) char pkg_old[PATH_MAX] = {0, }; char pkg_new[PATH_MAX] = {0, }; bool blacklist; - pkgmgrinfo_pkginfo_h pkginfo; #if !GLIB_CHECK_VERSION(2,35,0) g_type_init(); @@ -1204,7 +1159,10 @@ int main(int argc, char *argv[]) if (optarg) { strncpy(data.pkg_old, optarg, PATH_MAX - 1); } - realpath(data.pkg_old, data.resolved_path_pkg_old); + if (realpath(data.pkg_old, data.resolved_path_pkg_old) == NULL) { + printf("failed to set realpath\n"); + return -1; + } printf("pkg_old abs path is %s\n", data.resolved_path_pkg_old); break; @@ -1212,7 +1170,10 @@ int main(int argc, char *argv[]) if (optarg) { strncpy(data.pkg_new, optarg, PATH_MAX - 1); } - realpath(data.pkg_new, data.resolved_path_pkg_new); + if (realpath(data.pkg_new, data.resolved_path_pkg_new) == NULL) { + printf("failed to set realpath\n"); + return -1; + } printf("pkg_new abs path is %s\n", data.resolved_path_pkg_new); break; @@ -1221,7 +1182,10 @@ int main(int argc, char *argv[]) strncpy(data.delta_pkg, optarg, PATH_MAX - 1); } printf("delta_pkg is %s\n", data.delta_pkg); - realpath(data.delta_pkg, data.resolved_path_delta_pkg); + if (realpath(data.delta_pkg, data.resolved_path_delta_pkg) == NULL) { + printf("failed to set realpath\n"); + return -1; + } printf("delta_pkg abs path is %s\n",data.resolved_path_delta_pkg); break; case 'd': /* descriptor path */ diff --git a/src/pkg_initdb.c b/src/pkg_initdb.c index 9c0ecac..1dfcb8e 100644 --- a/src/pkg_initdb.c +++ b/src/pkg_initdb.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include @@ -84,7 +86,12 @@ static int _initdb_load_directory(uid_t uid, const char *directory) pid_t pid = fork(); if (pid == 0) { - setuid(uid); + if (setuid(uid) != 0) { + _E("failed to set uid"); + closedir(dir); + return -1; + } + execl(PKGINSTALLMANIFEST_CMD, PKGINSTALLMANIFEST_CMD, "-x", buf, (char*)NULL); } else if (pid < 0) { -- 2.7.4 From 97950153398cb2e96830aa39c09dd24f24ff0651 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Mon, 7 Mar 2016 17:48:48 +0900 Subject: [PATCH 06/16] fix coding styles and change keyword 'entry' to more readable one. Change-Id: I7603251b6fce3881aec3ad379e6e565e956ce283 Signed-off-by: jongmyeongko --- CMakeLists.txt | 2 +- src/delta.c | 407 +++++++++++++++++++++++----------------------- src/delta.h | 12 +- src/install_preload_tpk.c | 2 +- src/pkg_clearcache.c | 8 +- src/pkg_cmd.c | 169 ++++++++++--------- src/pkg_getsize.c | 75 ++++----- src/pkg_info.c | 352 +++++++++++++++++++-------------------- src/pkg_initdb.c | 18 +- 9 files changed, 529 insertions(+), 516 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44cef0b..bb688e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ ENDFOREACH(flag) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs -pie" ) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall -Werror") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -fPIE") SET(CMAKE_C_FLAGS_RELEASE "-O2 -fPIE") diff --git a/src/delta.c b/src/delta.c index dba2a27..a71a212 100644 --- a/src/delta.c +++ b/src/delta.c @@ -29,101 +29,96 @@ #include #include "delta.h" -static GList * __list_directory(const char * dir_name, const char * tpk_path, GList * list); -static int __compare_files(char * path1, char * path2); -static void __print_to_file(char* msg); -static void __free_g_list(GList * list); +static GList *__list_directory(const char *dir_name, const char *tpk_path, GList *list); +static int __compare_files(char *path1, char *path2); +static void __print_to_file(char *msg); +static void __free_g_list(GList *list); -static void __free_g_list(GList * list) +static void __free_g_list(GList *list) { - GList * iter = NULL; - for (iter = list; iter != NULL; iter = iter->next) - { + GList *iter = NULL; + + for (iter = list; iter != NULL; iter = iter->next) { if (iter->data) free(iter->data); } g_list_free(list); + return; } -static GList * __list_directory (const char * dir_name, const char * tpk_path, GList * list) +static GList *__list_directory(const char *dir_name, const char *tpk_path, GList *list) { - DIR *dir = NULL; - struct dirent entry, *result; - int flag = 0; - char path[PATH_MAX] = {0, }; - char rel_path_old_tpk_file[PATH_MAX] = {0, }; - char *file_path = NULL; - char buf[BUF_SIZE] = {0}; - - dir = opendir(dir_name); - if (!dir) - { - if (strerror_r(errno, buf, sizeof(buf)) == 0) { - printf ("Cannot open directory '%s': %s\n", dir_name, buf); - } - exit (EXIT_FAILURE); - } - while (1) - { - const char * d_name = NULL; - int ret = 0; - ret = readdir_r(dir, &entry, &result); /* "Readdir" gets subsequent entries from "d". */ - if (ret != 0 || result == NULL)/* There are no more entries in this directory, so break out of the while loop. */ - { - flag++; - break; - } - d_name = entry.d_name; - if (!(entry.d_type & DT_DIR)) - { - snprintf(rel_path_old_tpk_file, PATH_MAX, "%s/%s", dir_name, d_name); - strncpy(path, rel_path_old_tpk_file+strlen(tpk_path), strlen(rel_path_old_tpk_file)); - file_path = strndup(path, sizeof(path)); - list = g_list_append(list, file_path); - memset(path, 0, PATH_MAX); - memset(rel_path_old_tpk_file, 0, PATH_MAX); - - } - - if (entry.d_type & DT_DIR) /* Check that the directory is not "d" or d's parent. */ - { - if (strcmp(d_name, "..") != 0 && strcmp (d_name, ".") != 0) - { - int path_length; - path_length = snprintf (path, PATH_MAX, "%s/%s", dir_name, d_name); - if (path_length >= PATH_MAX) - { - printf("Path length has got too long.\n"); - exit(EXIT_FAILURE); - } - list = __list_directory (path, tpk_path, list); - memset(path, 0, PATH_MAX);/* Recursively call "list_dir" with the new path. */ - } - } - } - if(flag == 1) - { - snprintf (rel_path_old_tpk_file, PATH_MAX, "%s/", dir_name); - strncpy(path, rel_path_old_tpk_file+strlen(tpk_path), strlen(rel_path_old_tpk_file)); - file_path = strndup(path, sizeof(path)); - list = g_list_prepend(list, file_path); - memset(path, 0, PATH_MAX); - memset(rel_path_old_tpk_file, 0, PATH_MAX); - } - if (closedir(dir)) - { - if (strerror_r(errno, buf, sizeof(buf)) == 0) { - printf("Could not close '%s': %s\n", dir_name, buf); - } - exit(EXIT_FAILURE); - } - return list; + DIR *dir = NULL; + struct dirent file_info; + struct dirent *result; + int flag = 0; + char path[PATH_MAX] = {0, }; + char rel_path_old_tpk_file[PATH_MAX] = {0, }; + char *file_path = NULL; + char buf[BUF_SIZE] = {0}; + const char *d_name = NULL; + int ret = 0; + int path_length; + + dir = opendir(dir_name); + if (!dir) { + if (strerror_r(errno, buf, sizeof(buf)) == 0) + printf("Cannot open directory '%s': %s\n", dir_name, buf); + exit(EXIT_FAILURE); + } + + while (1) { + ret = readdir_r(dir, &file_info, &result); + if (ret != 0 || result == NULL) { + flag++; + break; + } + + d_name = file_info.d_name; + if (!(file_info.d_type & DT_DIR)) { + snprintf(rel_path_old_tpk_file, PATH_MAX, "%s/%s", dir_name, d_name); + strncpy(path, rel_path_old_tpk_file + strlen(tpk_path), + strlen(rel_path_old_tpk_file)); + file_path = strndup(path, sizeof(path)); + list = g_list_append(list, file_path); + memset(path, 0, PATH_MAX); + memset(rel_path_old_tpk_file, 0, PATH_MAX); + } + + if (file_info.d_type & DT_DIR) { + if (strcmp(d_name, "..") != 0 && strcmp(d_name, ".") != 0) { + path_length = snprintf(path, PATH_MAX, "%s/%s", dir_name, d_name); + if (path_length >= PATH_MAX) { + printf("Path length has got too long.\n"); + exit(EXIT_FAILURE); + } + list = __list_directory(path, tpk_path, list); + memset(path, 0, PATH_MAX); + } + } + } + + if (flag == 1) { + snprintf(rel_path_old_tpk_file, PATH_MAX, "%s/", dir_name); + strncpy(path, rel_path_old_tpk_file+strlen(tpk_path), + strlen(rel_path_old_tpk_file)); + file_path = strndup(path, sizeof(path)); + list = g_list_prepend(list, file_path); + } + + if (closedir(dir)) { + if (strerror_r(errno, buf, sizeof(buf)) == 0) + printf("Could not close '%s': %s\n", dir_name, buf); + exit(EXIT_FAILURE); + } + + return list; } -static char * __create_md5Hash(char * file_name) +static char *__create_md5Hash(char *file_name) { - FILE *inFile = fopen (file_name, "rb"); + FILE *inFile = fopen(file_name, "rb"); unsigned char data[1024] = {0, }; int bytes = 0; @@ -143,14 +138,12 @@ static char * __create_md5Hash(char * file_name) return 0; } - while ((bytes = fread(data, 1, 1024, inFile)) != 0) { + while ((bytes = fread(data, 1, 1024, inFile)) != 0) g_checksum_update(checksum, (const guchar *)data, bytes); - } checksum_val = (char *)g_checksum_get_string(checksum); - if (checksum_val) { + if (checksum_val) return_val = strdup(checksum_val); - } g_checksum_free(checksum); fclose(inFile); @@ -158,190 +151,204 @@ static char * __create_md5Hash(char * file_name) return return_val; } -static int __compare_files(char * old_file, char * new_file) +static int __compare_files(char *old_file, char *new_file) { char *md5_old_file = NULL; char *md5_new_file = NULL; + md5_old_file = __create_md5Hash(old_file); - if(md5_old_file == NULL) - { - printf("md5checksum failed for %s.\n", old_file ); + if (md5_old_file == NULL) { + printf("md5checksum failed for %s.\n", old_file); exit(EXIT_FAILURE); } + md5_new_file = __create_md5Hash(new_file); - if(md5_new_file == NULL) - { - printf("md5checksum failed for %s.\n", new_file ); + if (md5_new_file == NULL) { + printf("md5checksum failed for %s.\n", new_file); exit(EXIT_FAILURE); } - if(strcmp(md5_old_file, md5_new_file) == 0) - { + + if (strcmp(md5_old_file, md5_new_file) == 0) { free(md5_old_file); free(md5_new_file); return 0; - } - else - { + } else { free(md5_old_file); free(md5_new_file); return 1; } } -static void __print_to_file(char* msg) +static void __print_to_file(char *msg) { FILE *fp; + fp = fopen(DIFF_FILE, "a"); - if (fp == NULL) - { + + if (fp == NULL) { printf("Cannot open %s for writing ", DIFF_FILE); exit(1); } + fprintf(fp, "%s \n", msg); memset(msg, 0, MAX_MESSAGE_LEN); fclose(fp); } -void __create_diff_file(char * old_tpk_path, char * new_tpk_path) +void __create_diff_file(char *old_tpk_path, char *new_tpk_path) { - char rel_path_old_tpk_file[PATH_MAX] = {0, }, rel_path_new_tpk_file[PATH_MAX] = {0, }; - GList *list_dir_old_tpk = NULL, *list_dir_new_tpk = NULL, *iterator_old_tpk = NULL, *iterator_new_tpk = NULL, *next_iterator_old_tpk = NULL, *next_iterator_new_tpk = NULL; - int ret = -1; - - list_dir_old_tpk = __list_directory (old_tpk_path, old_tpk_path, list_dir_old_tpk); - list_dir_new_tpk = __list_directory (new_tpk_path, new_tpk_path, list_dir_new_tpk); - if(list_dir_old_tpk == NULL) - { - printf("Could Not read %s\n", old_tpk_path); - return; - } + char rel_path_old_tpk_file[PATH_MAX] = {0, }; + char rel_path_new_tpk_file[PATH_MAX] = {0, }; + GList *list_dir_old_tpk = NULL; + GList *list_dir_new_tpk = NULL; + GList *iterator_old_tpk = NULL; + GList *iterator_new_tpk = NULL; + GList *next_iterator_old_tpk = NULL; + GList *next_iterator_new_tpk = NULL; + int ret = -1; - if(list_dir_new_tpk == NULL) - { - printf("Could Not read %s\n", new_tpk_path); - return; - } + list_dir_old_tpk = __list_directory(old_tpk_path, old_tpk_path, list_dir_old_tpk); + list_dir_new_tpk = __list_directory(new_tpk_path, new_tpk_path, list_dir_new_tpk); + if (list_dir_old_tpk == NULL) { + printf("Could Not read %s\n", old_tpk_path); + return; + } - iterator_old_tpk = list_dir_old_tpk; - iterator_new_tpk = list_dir_new_tpk; + if (list_dir_new_tpk == NULL) { + printf("Could Not read %s\n", new_tpk_path); + return; + } + + iterator_old_tpk = list_dir_old_tpk; + iterator_new_tpk = list_dir_new_tpk; - while(iterator_old_tpk != NULL) - { + while (iterator_old_tpk != NULL) { next_iterator_old_tpk = iterator_old_tpk->next; iterator_new_tpk = list_dir_new_tpk; - while(iterator_new_tpk != NULL) - { + while (iterator_new_tpk != NULL) { next_iterator_new_tpk = iterator_new_tpk->next; - if(strcmp((char *)iterator_old_tpk->data, (char *)iterator_new_tpk->data) == 0) - { - snprintf(rel_path_old_tpk_file, PATH_MAX,"%s%s", old_tpk_path,(char *)iterator_old_tpk->data); - snprintf(rel_path_new_tpk_file, PATH_MAX,"%s%s", new_tpk_path,(char *)iterator_new_tpk->data); - ret = 0; - if(rel_path_new_tpk_file[strlen(rel_path_new_tpk_file) - 1] != '/') - { - ret = __compare_files(rel_path_old_tpk_file, rel_path_new_tpk_file); - if (ret == 1) - { - snprintf(message, MAX_MESSAGE_LEN, "Files %s and %s differ", rel_path_old_tpk_file, rel_path_new_tpk_file); - __print_to_file(message); - } - } - list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk, iterator_new_tpk); - list_dir_old_tpk = g_list_delete_link(list_dir_old_tpk, iterator_old_tpk); - iterator_new_tpk = next_iterator_new_tpk; - iterator_old_tpk = next_iterator_old_tpk; - break; - } - iterator_new_tpk = next_iterator_new_tpk; - } - iterator_old_tpk = next_iterator_old_tpk; - } + if (strcmp((char *)iterator_old_tpk->data, + (char *)iterator_new_tpk->data) == 0) { + snprintf(rel_path_old_tpk_file, PATH_MAX, "%s%s", old_tpk_path, + (char *)iterator_old_tpk->data); + snprintf(rel_path_new_tpk_file, PATH_MAX, "%s%s", new_tpk_path, + (char *)iterator_new_tpk->data); + ret = 0; + if (rel_path_new_tpk_file[strlen(rel_path_new_tpk_file) - 1] + != '/') { + ret = __compare_files(rel_path_old_tpk_file, + rel_path_new_tpk_file); + if (ret == 1) { + snprintf(message, MAX_MESSAGE_LEN, + "Files %s and %s differ", + rel_path_old_tpk_file, + rel_path_new_tpk_file); + __print_to_file(message); + } + } + list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk, + iterator_new_tpk); + list_dir_old_tpk = g_list_delete_link(list_dir_old_tpk, + iterator_old_tpk); + iterator_new_tpk = next_iterator_new_tpk; + iterator_old_tpk = next_iterator_old_tpk; + break; + } + iterator_new_tpk = next_iterator_new_tpk; + } + iterator_old_tpk = next_iterator_old_tpk; + } - //find if new file or new directory + /* find if new file or new directory */ iterator_old_tpk = list_dir_old_tpk; - while(iterator_old_tpk != NULL) - { + while (iterator_old_tpk != NULL) { iterator_new_tpk = iterator_old_tpk->next; - while(iterator_new_tpk != NULL) - { + while (iterator_new_tpk != NULL) { next_iterator_new_tpk = iterator_new_tpk->next; if (strstr(iterator_new_tpk->data, iterator_old_tpk->data) != NULL) - list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk, iterator_new_tpk); + list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk, + iterator_new_tpk); iterator_new_tpk = next_iterator_new_tpk; } iterator_old_tpk = iterator_old_tpk->next; } iterator_old_tpk = list_dir_new_tpk; - while(iterator_old_tpk != NULL) - { + while (iterator_old_tpk != NULL) { iterator_new_tpk = iterator_old_tpk->next; - while(iterator_new_tpk != NULL) - { + while (iterator_new_tpk != NULL) { next_iterator_new_tpk = iterator_new_tpk->next; if (strstr(iterator_new_tpk->data, iterator_old_tpk->data) != NULL) - list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk, iterator_new_tpk); + list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk, + iterator_new_tpk); iterator_new_tpk = next_iterator_new_tpk; } iterator_old_tpk = iterator_old_tpk->next; } iterator_old_tpk = list_dir_old_tpk; - while(iterator_old_tpk != NULL) - { - snprintf(message, MAX_MESSAGE_LEN, "Only in %s%s", old_tpk_path, (char *)iterator_old_tpk->data); + while (iterator_old_tpk != NULL) { + snprintf(message, MAX_MESSAGE_LEN, "Only in %s%s", old_tpk_path, + (char *)iterator_old_tpk->data); __print_to_file(message); iterator_old_tpk = iterator_old_tpk->next; } + iterator_new_tpk = list_dir_new_tpk; - while(iterator_new_tpk != NULL) - { - snprintf(message, MAX_MESSAGE_LEN, "Only in %s%s", new_tpk_path, (char *)iterator_new_tpk->data); + while (iterator_new_tpk != NULL) { + snprintf(message, MAX_MESSAGE_LEN, "Only in %s%s", new_tpk_path, + (char *)iterator_new_tpk->data); __print_to_file(message); iterator_new_tpk = iterator_new_tpk->next; } - /*to free GSList*/ + /* to free GSList */ __free_g_list(list_dir_old_tpk); __free_g_list(list_dir_new_tpk); } int __xsystem(const char *argv[]) { - int status = 0; - pid_t pid; - pid = fork(); - switch (pid) { - case -1: - perror("fork failed"); - return -1; - case 0: - /* child */ - if (execvp(argv[0], (char *const *)argv) < 0) { - char buf[BUF_SIZE] = {0}; - if (strerror_r(errno, buf, sizeof(buf)) == 0) { - fprintf(stderr, "execvp failed %d....%s\n", errno, buf); /*Don't use d_msg_app2sd */ - } - } - _exit(-1); - default: - /* parent */ - break; - } - if (waitpid(pid, &status, 0) == -1) { - perror("waitpid failed"); - return -1; - } - if (WIFSIGNALED(status)) { - perror("signal"); - return -1; - } - if (!WIFEXITED(status)) { - /* shouldn't happen */ - perror("should not happen"); - return -1; - } - return WEXITSTATUS(status); + char buf[BUF_SIZE] = {0}; + int status = 0; + pid_t pid; + + pid = fork(); + + switch (pid) { + case -1: + perror("fork failed"); + return -1; + case 0: + /* child */ + if (execvp(argv[0], (char *const *)argv) < 0) { + if (strerror_r(errno, buf, sizeof(buf)) == 0) + fprintf(stderr, "execvp failed %d....%s\n", errno, buf); + } + _exit(-1); + default: + /* parent */ + break; + } + + if (waitpid(pid, &status, 0) == -1) { + perror("waitpid failed"); + return -1; + } + + if (WIFSIGNALED(status)) { + perror("signal"); + return -1; + } + + if (!WIFEXITED(status)) { + /* shouldn't happen */ + perror("should not happen"); + return -1; + } + + return WEXITSTATUS(status); } + diff --git a/src/delta.h b/src/delta.h index 699a937..4d1d171 100644 --- a/src/delta.h +++ b/src/delta.h @@ -20,14 +20,14 @@ #ifndef DELTA_H_ #define DELTA_H_ -#define DIFF_FILE "/opt/usr/temp_delta/difffile.txt" -#define TEMP_DELTA_REPO "/opt/usr/temp_delta/" -#define UNZIPFILE "_FILES" -#define MAX_MESSAGE_LEN 1024 -#define BUF_SIZE 1024 +#define DIFF_FILE "/opt/usr/temp_delta/difffile.txt" +#define TEMP_DELTA_REPO "/opt/usr/temp_delta/" +#define UNZIPFILE "_FILES" +#define MAX_MESSAGE_LEN 1024 +#define BUF_SIZE 1024 char message[MAX_MESSAGE_LEN]; -void __create_diff_file(char * old_tpk_path, char * new_tpk_path); +void __create_diff_file(char *old_tpk_path, char *new_tpk_path); int __xsystem(const char *argv[]); #endif /* DELTA_H_ */ diff --git a/src/install_preload_tpk.c b/src/install_preload_tpk.c index e9d7e7b..3694f6b 100644 --- a/src/install_preload_tpk.c +++ b/src/install_preload_tpk.c @@ -78,7 +78,7 @@ static int _install_preload_tpk(uid_t uid, const char *directory) return -1; } execl(BACKEND_CMD, BACKEND_CMD, "-i", buf, "--preload", - (char*)NULL); + (char *)NULL); } else if (pid < 0) { _E("failed to fork and execute %s!", BACKEND_CMD); closedir(dir); diff --git a/src/pkg_clearcache.c b/src/pkg_clearcache.c index ee8e593..14181e2 100644 --- a/src/pkg_clearcache.c +++ b/src/pkg_clearcache.c @@ -119,12 +119,12 @@ static int __clear_cache_dir(const char *pkgid) int ret = 0; char dirname[PATH_MAX] = {0,}; - if(pkgid == NULL) { + if (pkgid == NULL) { LOGE("pkgid is NULL\n"); return -1; } - // cache internal + /* cache internal */ snprintf(dirname, sizeof(dirname), "%s/%s%s", INTERNAL_CACHE_PATH_PREFIX, pkgid, CACHE_PATH_POSTFIX); @@ -132,7 +132,7 @@ static int __clear_cache_dir(const char *pkgid) if (ret < 0) LOGE("Failed to clear internal cache dir."); - // shared/cache internal + /* shared/cache internal */ snprintf(dirname, sizeof(dirname), "%s/%s%s", INTERNAL_CACHE_PATH_PREFIX, pkgid, SHARED_PATH_POSTFIX); @@ -158,7 +158,7 @@ static int __clear_all_cache_dir_cb(const pkgmgrinfo_pkginfo_h handle, } res = __clear_cache_dir(pkgid); - if (res != 0) { // error flag + if (res != 0) { LOGE("Failed to clear cache dir of %s", pkgid); --(*err_cnt); return 0; diff --git a/src/pkg_cmd.c b/src/pkg_cmd.c index 1540353..1966d96 100644 --- a/src/pkg_cmd.c +++ b/src/pkg_cmd.c @@ -158,7 +158,7 @@ static void __error_no_to_string(int errnumber, char **errstr) if (errstr == NULL) return; switch (errnumber) { - case PKGCMD_ERRCODE_UNZIP_ERROR: + case PKGCMD_ERRCODE_UNZIP_ERROR: *errstr = PKGCMD_ERRCODE_UNZIP_ERROR_STR; break; case PKGCMD_ERRCODE_SECURITY_ERROR: @@ -249,10 +249,9 @@ static int __return_cb(uid_t target_uid, int req_id, const char *pkg_type, data.result = ret_val; ret_result = strstr((char *)val, delims); - if (ret_result){ + if (ret_result) printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d] error message: %s\n", req_id, pkg_type, pkgid, key, ret_val, ret_result); - } 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); @@ -262,9 +261,8 @@ static int __return_cb(uid_t target_uid, int req_id, const char *pkg_type, req_id, pkg_type, pkgid, key, val); if (strncmp(key, "end", strlen("end")) == 0) { - if ((strncmp(val, "fail", strlen("fail")) == 0) && data.result == 0){ + if ((strncmp(val, "fail", strlen("fail")) == 0) && data.result == 0) data.result = PKGCMD_ERRCODE_ERROR; - } g_main_loop_quit(main_loop); } @@ -370,11 +368,12 @@ static int __is_app_installed(char *pkgid, uid_t uid) else ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); - if(ret < 0) { + if (ret < 0) { printf("package is not in pkgmgr_info DB\n"); return -1; - } else + } else { pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + } return 0; } @@ -439,7 +438,7 @@ static void __print_usage() } -static int __pkgmgr_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data) +static int __pkgmgr_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data) { int ret = -1; char *pkgid = NULL; @@ -473,7 +472,8 @@ static int __pkgmgr_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data) return ret; } - printf("%s\tpkg_type [%s]\tpkgid [%s]\tname [%s]\tversion [%s]\n", for_all_users ? "system apps" : "user apps ", pkg_type, pkgid, pkg_label, pkg_version); + printf("%s\tpkg_type [%s]\tpkgid [%s]\tname [%s]\tversion [%s]\n", + for_all_users ? "system apps" : "user apps ", pkg_type, pkgid, pkg_label, pkg_version); return ret; } @@ -484,14 +484,16 @@ static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data) pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle; ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid); - if(ret < 0) { + if (ret < 0) printf("pkgmgrinfo_pkginfo_get_pkgid() failed\n"); - } - if (uid_info->uid != GLOBAL_USER) - ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE, (pkgmgr_client *)user_data, NULL, pkgid, uid_info->uid, NULL, NULL, NULL); - else - ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE, (pkgmgr_client *)user_data, NULL, pkgid, NULL, NULL, NULL); - if (ret < 0){ + + if (uid_info->uid != GLOBAL_USER) + ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE, + (pkgmgr_client *)user_data, NULL, pkgid, uid_info->uid, NULL, NULL, NULL); + else + ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE, + (pkgmgr_client *)user_data, NULL, pkgid, NULL, NULL, NULL); + if (ret < 0) { printf("pkgmgr_client_request_service Failed\n"); return -1; } @@ -511,7 +513,7 @@ static int __process_request(uid_t uid) char pkg_new[PATH_MAX] = {0, }; bool blacklist; -#if !GLIB_CHECK_VERSION(2,35,0) +#if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init(); #endif switch (data.request) { @@ -533,19 +535,16 @@ static int __process_request(uid_t uid) if (data.tep_path[0] != '\0') pkgmgr_client_set_tep_path(pc, data.tep_path, data.tep_move); - if (data.des_path[0] == '\0') { - ret = - pkgmgr_client_usr_install(pc, data.pkg_type, NULL, - data.pkg_path, NULL, PM_QUIET, - __return_cb, pc, uid); - } else { - ret = - pkgmgr_client_usr_install(pc, data.pkg_type, - data.des_path, data.pkg_path, - NULL, PM_QUIET, __return_cb, pc, uid); + if (data.des_path[0] == '\0') + ret = pkgmgr_client_usr_install(pc, data.pkg_type, NULL, + data.pkg_path, NULL, PM_QUIET, + __return_cb, pc, uid); + else + ret = pkgmgr_client_usr_install(pc, data.pkg_type, + data.des_path, data.pkg_path, + NULL, PM_QUIET, __return_cb, pc, uid); - } - if (ret < 0){ + if (ret < 0) { data.result = PKGCMD_ERRCODE_ERROR; if (access(data.pkg_path, F_OK) != 0) data.result = PKGCMD_ERRCODE_PACKAGE_NOT_FOUND; @@ -556,15 +555,17 @@ static int __process_request(uid_t uid) break; case CREATE_DELTA: printf("CREATE_DELTA\n"); - if (data.pkg_old[0] == '\0' || data.pkg_new[0] == '\0' ) { + if (data.pkg_old[0] == '\0' || data.pkg_new[0] == '\0') { printf("tpk pkg missing\n"); break; } - if(data.delta_pkg[0] == '\0') { + if (data.delta_pkg[0] == '\0') { snprintf(data.resolved_path_delta_pkg, PATH_MAX, "/tmp/delta_pkg"); printf("output file will be /tmp/delta_pkg.delta\n"); } - const char *unzip_argv[] = {"sh", "/etc/package-manager/pkgmgr-unzip-tpk.sh", "-a", data.resolved_path_pkg_old, "-b", data.resolved_path_pkg_new, "-p", data.resolved_path_delta_pkg, NULL}; + const char *unzip_argv[] = {"sh", "/etc/package-manager/pkgmgr-unzip-tpk.sh", "-a", + data.resolved_path_pkg_old, "-b", data.resolved_path_pkg_new, "-p", + data.resolved_path_delta_pkg, NULL}; ret = __xsystem(unzip_argv); if (ret != 0) { printf("unzip is fail .\n"); @@ -586,11 +587,13 @@ static int __process_request(uid_t uid) } ptr_new_tpk++; - snprintf(pkg_old, PATH_MAX,"%s%s%s", TEMP_DELTA_REPO, ptr_old_tpk, UNZIPFILE); - snprintf(pkg_new, PATH_MAX,"%s%s%s", TEMP_DELTA_REPO, ptr_new_tpk, UNZIPFILE); + snprintf(pkg_old, PATH_MAX, "%s%s%s", TEMP_DELTA_REPO, ptr_old_tpk, UNZIPFILE); + snprintf(pkg_new, PATH_MAX, "%s%s%s", TEMP_DELTA_REPO, ptr_new_tpk, UNZIPFILE); __create_diff_file(pkg_old, pkg_new); - const char *delta_argv[] = {"sh", "/etc/package-manager/pkgmgr-create-delta.sh", "-a", data.resolved_path_pkg_old, "-b", data.resolved_path_pkg_new, "-p", data.resolved_path_delta_pkg, NULL}; + const char *delta_argv[] = {"sh", "/etc/package-manager/pkgmgr-create-delta.sh", "-a", + data.resolved_path_pkg_old, "-b", data.resolved_path_pkg_new, "-p", + data.resolved_path_delta_pkg, NULL}; ret = __xsystem(delta_argv); if (ret != 0) { printf("create delta script fail .\n"); @@ -612,17 +615,16 @@ static int __process_request(uid_t uid) data.result = PKGCMD_ERRCODE_ERROR; break; } -//if global + ret = __is_app_installed(data.pkgid, uid); if (ret == -1) { printf("package is not installed\n"); break; } - ret = - pkgmgr_client_usr_uninstall(pc, data.pkg_type, data.pkgid, - PM_QUIET, __return_cb, NULL,uid); - if (ret < 0){ + ret = pkgmgr_client_usr_uninstall(pc, data.pkg_type, data.pkgid, + PM_QUIET, __return_cb, NULL, uid); + if (ret < 0) { data.result = PKGCMD_ERRCODE_ERROR; if (access(data.pkg_path, F_OK) != 0) data.result = PKGCMD_ERRCODE_PACKAGE_NOT_FOUND; @@ -648,7 +650,7 @@ static int __process_request(uid_t uid) } ret = pkgmgr_client_usr_reinstall(pc, data.pkg_type, data.pkgid, NULL, PM_QUIET, __return_cb, pc, uid); - if (ret < 0){ + if (ret < 0) { data.result = PKGCMD_ERRCODE_ERROR; if (access(data.pkg_path, F_OK) != 0) data.result = PKGCMD_ERRCODE_PACKAGE_NOT_FOUND; @@ -678,7 +680,7 @@ static int __process_request(uid_t uid) break; } ret = pkgmgr_client_usr_clear_user_data(pc, data.pkg_type, - data.pkgid, PM_QUIET, uid); + data.pkgid, PM_QUIET, uid); if (ret < 0) break; ret = data.result; @@ -700,7 +702,7 @@ static int __process_request(uid_t uid) break; } - if (strcmp(data.pkg_type, "app") == 0 ) { + if (strcmp(data.pkg_type, "app") == 0) { if (data.global) /* enable global app for this user only */ ret = pkgmgr_client_activate_global_app_for_uid(pc, data.pkgid, __app_return_cb, getuid()); @@ -742,7 +744,7 @@ static int __process_request(uid_t uid) break; } - if (strcmp(data.pkg_type, "app") == 0 ) { + if (strcmp(data.pkg_type, "app") == 0) { if (data.global) /* disable global app for this user only*/ ret = pkgmgr_client_deactivate_global_app_for_uid(pc, data.pkgid, __app_return_cb, getuid()); @@ -840,7 +842,7 @@ static int __process_request(uid_t uid) if (data.request == KILLAPP_REQ) { ret = pkgmgr_client_usr_request_service(PM_REQUEST_KILL_APP, 0, pc, NULL, data.pkgid, uid, NULL, NULL, &pid); - if (ret < 0){ + if (ret < 0) { data.result = PKGCMD_ERRCODE_ERROR; break; } @@ -851,7 +853,7 @@ static int __process_request(uid_t uid) } else if (data.request == CHECKAPP_REQ) { ret = pkgmgr_client_usr_request_service(PM_REQUEST_CHECK_APP, 0, pc, NULL, data.pkgid, uid, NULL, NULL, &pid); - if (ret < 0){ + if (ret < 0) { data.result = PKGCMD_ERRCODE_ERROR; break; } @@ -867,35 +869,39 @@ static int __process_request(uid_t uid) case LIST_REQ: if (data.pkg_type[0] == '\0') { ret = 0; - if (uid != GLOBAL_USER) { + if (uid != GLOBAL_USER) ret = pkgmgrinfo_pkginfo_get_usr_list(__pkgmgr_list_cb, NULL, uid); - } else { + else ret = pkgmgrinfo_pkginfo_get_list(__pkgmgr_list_cb, NULL); - } - if (ret == -1) - printf("no packages found\n"); - break; + + if (ret == -1) + printf("no packages found\n"); + break; } else { pkgmgrinfo_pkginfo_filter_h handle; + ret = pkgmgrinfo_pkginfo_filter_create(&handle); if (ret == -1) { printf("Failed to get package filter handle\n"); break; } + ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_TYPE, data.pkg_type); if (ret == -1) { printf("Failed to add package type filter\n"); pkgmgrinfo_pkginfo_filter_destroy(handle); break; } - if (uid != GLOBAL_USER) { + + if (uid != GLOBAL_USER) ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, __pkgmgr_list_cb, NULL, uid); - } else { + else ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkgmgr_list_cb, NULL); - } - if (ret != PMINFO_R_OK) - printf("no package filter list\n"); - pkgmgrinfo_pkginfo_filter_destroy(handle); + + if (ret != PMINFO_R_OK) + printf("no package filter list\n"); + + pkgmgrinfo_pkginfo_filter_destroy(handle); break; } @@ -905,7 +911,8 @@ static int __process_request(uid_t uid) break; case CSC_REQ: - ret = pkgmgr_client_usr_request_service(PM_REQUEST_CSC, 0, NULL, NULL, NULL, uid, data.des_path, NULL, (void *)data.pkg_path); + ret = pkgmgr_client_usr_request_service(PM_REQUEST_CSC, 0, NULL, NULL, NULL, uid, + data.des_path, NULL, (void *)data.pkg_path); if (ret < 0) data.result = PKGCMD_ERRCODE_ERROR; break; @@ -929,8 +936,9 @@ static int __process_request(uid_t uid) ret = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, (void *)pc, uid); break; } - ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, data.type, pc, NULL, data.pkgid, uid, NULL, NULL, NULL); - if (ret < 0){ + ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, data.type, + pc, NULL, data.pkgid, uid, NULL, NULL, NULL); + if (ret < 0) { data.result = PKGCMD_ERRCODE_ERROR; break; } @@ -951,12 +959,14 @@ static int __process_request(uid_t uid) ret = -1; break; } + pc = pkgmgr_client_new(PC_REQUEST); if (pc == NULL) { printf("PkgMgr Client Creation Failed\n"); data.result = PKGCMD_ERRCODE_ERROR; break; } + ret = pkgmgr_client_usr_add_blacklist(pc, data.pkgid, uid); if (ret < 0) { data.result = PKGCMD_ERRCODE_ERROR; @@ -973,12 +983,14 @@ static int __process_request(uid_t uid) ret = -1; break; } + pc = pkgmgr_client_new(PC_REQUEST); if (pc == NULL) { printf("PkgMgr Client Creation Failed\n"); data.result = PKGCMD_ERRCODE_ERROR; break; } + ret = pkgmgr_client_usr_remove_blacklist(pc, data.pkgid, uid); if (ret < 0) { data.result = PKGCMD_ERRCODE_ERROR; @@ -995,12 +1007,14 @@ static int __process_request(uid_t uid) ret = -1; break; } + pc = pkgmgr_client_new(PC_REQUEST); if (pc == NULL) { printf("PkgMgr Client Creation Failed\n"); data.result = PKGCMD_ERRCODE_ERROR; break; } + ret = pkgmgr_client_usr_check_blacklist(pc, data.pkgid, &blacklist, uid); if (ret < 0) { data.result = PKGCMD_ERRCODE_ERROR; @@ -1011,6 +1025,7 @@ static int __process_request(uid_t uid) printf("%s is blacklisted\n", data.pkgid); else printf("%s is not blacklisted\n", data.pkgid); + ret = data.result; break; @@ -1039,7 +1054,6 @@ int main(int argc, char *argv[]) struct timeval tv; bool is_root_cmd = false; - if (argc == 1) __print_usage(); @@ -1061,7 +1075,7 @@ int main(int argc, char *argv[]) memset(data.tep_path, '\0', PATH_MAX); memset(data.tep_move, '\0', PKG_NAME_STRING_LEN_MAX); - data.global = 0; //By default pkg_cmd will manage for the current user + data.global = 0; /* By default pkg_cmd will manage for the current user */ data.result = 0; data.type = -1; while (1) { @@ -1156,9 +1170,9 @@ int main(int argc, char *argv[]) case 'X': /* old_tpk */ data.request = CREATE_DELTA; is_root_cmd = true; - if (optarg) { + if (optarg) strncpy(data.pkg_old, optarg, PATH_MAX - 1); - } + if (realpath(data.pkg_old, data.resolved_path_pkg_old) == NULL) { printf("failed to set realpath\n"); return -1; @@ -1167,9 +1181,9 @@ int main(int argc, char *argv[]) break; case 'Y': /* new_tpk */ - if (optarg) { + if (optarg) strncpy(data.pkg_new, optarg, PATH_MAX - 1); - } + if (realpath(data.pkg_new, data.resolved_path_pkg_new) == NULL) { printf("failed to set realpath\n"); return -1; @@ -1178,15 +1192,15 @@ int main(int argc, char *argv[]) break; case 'Z': /* delta_tpk */ - if (optarg) { + if (optarg) strncpy(data.delta_pkg, optarg, PATH_MAX - 1); - } + printf("delta_pkg is %s\n", data.delta_pkg); if (realpath(data.delta_pkg, data.resolved_path_delta_pkg) == NULL) { printf("failed to set realpath\n"); return -1; } - printf("delta_pkg abs path is %s\n",data.resolved_path_delta_pkg); + printf("delta_pkg abs path is %s\n", data.resolved_path_delta_pkg); break; case 'd': /* descriptor path */ if (optarg) @@ -1214,7 +1228,8 @@ int main(int argc, char *argv[]) case 'M': /*tep move*/ if (optarg) - strncpy(data.tep_move, (atoi(optarg) == 1)?"tep_move":"tep_copy", PKG_NAME_STRING_LEN_MAX - 1); + strncpy(data.tep_move, (atoi(optarg) == 1) ? "tep_move" : "tep_copy", + PKG_NAME_STRING_LEN_MAX - 1); break; case 't': /* package type */ @@ -1271,19 +1286,21 @@ int main(int argc, char *argv[]) } } + uid_t uid = getuid(); - if(!is_root_cmd && uid == OWNER_ROOT) { + if (!is_root_cmd && uid == OWNER_ROOT) { printf("Current User is Root! : Only regular users are allowed\n"); return -1; } - if(data.global == 1) { + + if (data.global == 1) uid = GLOBAL_USER; - } + ret = __process_request(uid); if ((ret < 0) && (data.result == 0)) { - printf("Undefined error(%d)", ret); + printf("Undefined error(%d)", ret); data.result = PKGCMD_ERRCODE_UNDEFINED_ERROR; - } + } if (ret != 0) { __error_no_to_string(data.result, &errstr); diff --git a/src/pkg_getsize.c b/src/pkg_getsize.c index 879b674..d27a32d 100644 --- a/src/pkg_getsize.c +++ b/src/pkg_getsize.c @@ -43,13 +43,13 @@ #undef LOG_TAG #ifndef LOG_TAG #define LOG_TAG "PKGMGR_GETSIZE" -#endif /* LOG_TAG */ +#endif /* LOG_TAG */ #define MAX_PKG_BUF_LEN 1024 -#define BLOCK_SIZE 4096 /*in bytes*/ -#define MAX_PATH_LENGTH 512 -#define MAX_LONGLONG_LENGTH 32 -#define MAX_SIZE_INFO_SIZE 128 +#define BLOCK_SIZE 4096 /*in bytes*/ +#define MAX_PATH_LENGTH 512 +#define MAX_LONGLONG_LENGTH 32 +#define MAX_SIZE_INFO_SIZE 128 #define OWNER_ROOT 0 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) @@ -58,8 +58,7 @@ #define APP_BASE_EXTERNAL_PATH "" #endif -typedef enum -{ +typedef enum { STORAGE_TYPE_INTERNAL, STORAGE_TYPE_EXTERNAL, STORAGE_TYPE_MAX = 255, @@ -70,9 +69,8 @@ long long __stat_size(struct stat *s) long long blksize = s->st_blksize; long long size = (long long)s->st_blocks * 512; - if (blksize) { + if (blksize) size = (size + blksize - 1) & (~(blksize - 1)); - } return size; } @@ -85,12 +83,12 @@ static long long __calculate_directory_size(int dfd, bool include_itself) int ret; DIR *dir; struct dirent *dent; - const char *entry; + const char *file_info; if (include_itself) { ret = fstat(dfd, &st); if (ret < 0) { - ERR("fstat() failed, entry: ., errno: %d (%s)", errno, + ERR("fstat() failed, file_info: ., errno: %d (%s)", errno, strerror(errno)); return -1; } @@ -105,30 +103,30 @@ static long long __calculate_directory_size(int dfd, bool include_itself) } while ((dent = readdir(dir))) { - entry = dent->d_name; - if (entry[0] == '.') { - if (entry[1] == '\0') + file_info = dent->d_name; + if (file_info[0] == '.') { + if (file_info[1] == '\0') continue; - if ((entry[1] == '.') && (entry[2] == '\0')) + if ((file_info[1] == '.') && (file_info[2] == '\0')) continue; } if (dent->d_type == DT_DIR) { - subfd = openat(dfd, entry, O_RDONLY | O_DIRECTORY); + subfd = openat(dfd, file_info, O_RDONLY | O_DIRECTORY); if (subfd < 0) { - ERR("openat() failed, entry:%s, errno: %d(%s)", - entry, errno, strerror(errno)); + ERR("openat() failed, file_info:%s, errno: %d(%s)", + file_info, errno, strerror(errno)); goto error; } - DBG("traverse entry: %s", entry); + DBG("traverse file_info: %s", file_info); size += __calculate_directory_size(subfd, true); close(subfd); } else { - ret = fstatat(dfd, entry, &st, AT_SYMLINK_NOFOLLOW); + ret = fstatat(dfd, file_info, &st, AT_SYMLINK_NOFOLLOW); if (ret < 0) { - ERR("fstatat() failed, entry:%s, errno: %d(%s)", - entry, errno, strerror(errno)); + ERR("fstatat() failed, file_info:%s, errno: %d(%s)", + file_info, errno, strerror(errno)); goto error; } size += __stat_size(&st); @@ -167,7 +165,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir, app_root_dir, errno, strerror(errno)); goto error; } - *app_size += __stat_size(&st); // shared directory + *app_size += __stat_size(&st); /* shared directory */ DBG("app_size: %lld", *app_size); DBG("traverse path: %s/shared/data", app_root_dir); @@ -175,8 +173,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir, subfd = openat(fd, "data", O_RDONLY | O_DIRECTORY); if (subfd >= 0) { size = __calculate_directory_size(subfd, true); - if (size < 0) - { + if (size < 0) { ERR("Calculating shared/data directory failed."); goto error; } @@ -184,7 +181,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir, DBG("data_size: %lld", *data_size); close(subfd); } else if (subfd < 0 && errno != ENOENT) { - ERR("openat() failed, entry: data, errno: %d (%s)", + ERR("openat() failed, file_info: data, errno: %d (%s)", errno, strerror(errno)); goto error; } @@ -202,7 +199,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir, DBG("data_size: %lld", *data_size); close(subfd); } else if (subfd < 0 && errno != ENOENT) { - DBG("openat() failed, entry: trusted, errno: %d (%s)", + DBG("openat() failed, file_info: trusted, errno: %d (%s)", errno, strerror(errno)); goto error; } @@ -220,7 +217,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir, DBG("app_size: %lld", *app_size); close(subfd); } else if (subfd < 0 && errno != ENOENT) { - ERR("openat() failed, entry: res, errno: %d (%s)", + ERR("openat() failed, file_info: res, errno: %d (%s)", errno, strerror(errno)); goto error; } @@ -238,7 +235,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir, DBG("data_size: %lld", *data_size); close(subfd); } else if (subfd < 0 && errno != ENOENT) { - ERR("openat() failed, entry: data, errno: %d (%s)", + ERR("openat() failed, file_info: data, errno: %d (%s)", errno, strerror(errno)); goto error; } @@ -391,22 +388,22 @@ static char *__get_pkg_size_info_str(const pkg_size_info_t* pkg_size_info) snprintf(size_info_str, MAX_SIZE_INFO_SIZE, "%lld", pkg_size_info->data_size); - strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1); + strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1); snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, "%lld", pkg_size_info->cache_size); - strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1); + strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1); snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, "%lld", pkg_size_info->app_size); - strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1); + strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1); snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, "%lld", pkg_size_info->ext_data_size); - strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1); + strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1); snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, "%lld", pkg_size_info->ext_cache_size); - strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1); + strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1); snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, "%lld", pkg_size_info->ext_app_size); - strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str)- 1); + strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1); DBG("size_info_str: %s", size_info_str); @@ -560,10 +557,10 @@ int main(int argc, char *argv[]) pkgmgr_installer *pi; pkg_size_info_t info = {0, }; - // argv has bellowed meaning - // argv[1] = pkgid - // argv[2] = get type - // argv[4] = req_key + /* argv has bellowed meaning */ + /* argv[1] = pkgid */ + /* argv[2] = get type */ + /* argv[4] = req_key */ if (argv[1] == NULL) { ERR("pkgid is NULL"); diff --git a/src/pkg_info.c b/src/pkg_info.c index a57fd66..d7f42f5 100644 --- a/src/pkg_info.c +++ b/src/pkg_info.c @@ -54,7 +54,7 @@ static int __get_certinfo_from_db(char *pkgid, uid_t uid); static int __del_certinfo_from_db(char *pkgid); static int __get_integer_input_data(void); char *__get_string_input_data(void); -static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data); +static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data); static int __app_category_list_cb(const char *category_name, void *user_data); static int __app_control_list_cb(const char *operation, const char *uri, const char *mime, void *user_data); static int __app_metadata_list_cb(const char *metadata_name, const char *metadata_value, void *user_data); @@ -82,119 +82,102 @@ static void __get_pkgmgrinfo_pkginfo(const pkgmgrinfo_pkginfo_h handle, void *us int installed_time = -1; ret = pkgmgrinfo_pkginfo_get_type(handle, &type); - if (ret < 0) { + if (ret < 0) printf("Failed to get pkg type\n"); - } if (type) printf("Type: %s\n", type); ret = pkgmgrinfo_pkginfo_get_version(handle, &version); - if (ret < 0) { + if (ret < 0) printf("Failed to get version\n"); - } if (version) printf("Version: %s\n", version); ret = pkgmgrinfo_pkginfo_get_install_location(handle, &location); - if (ret < 0) { + if (ret < 0) printf("Failed to get install location\n"); - } printf("Install Location: %d\n", location); ret = pkgmgrinfo_pkginfo_get_icon(handle, &icon); - if (ret < 0) { + if (ret < 0) printf("Failed to get icon\n"); - } if (icon) printf("Icon: %s\n", icon); ret = pkgmgrinfo_pkginfo_get_label(handle, &label); - if (ret < 0) { + if (ret < 0) printf("Failed to get label\n"); - } if (label) printf("Label: %s\n", label); ret = pkgmgrinfo_pkginfo_get_description(handle, &desc); - if (ret < 0) { + if (ret < 0) printf("Failed to get description\n"); - } if (desc) printf("Description: %s\n", desc); ret = pkgmgrinfo_pkginfo_get_author_name(handle, &author_name); - if (ret < 0) { + if (ret < 0) printf("Failed to get author name\n"); - } if (author_name) printf("Author Name: %s\n", author_name); ret = pkgmgrinfo_pkginfo_get_author_email(handle, &author_email); - if (ret < 0) { + if (ret < 0) printf("Failed to get author email\n"); - } if (author_email) printf("Author Email: %s\n", author_email); ret = pkgmgrinfo_pkginfo_get_author_href(handle, &author_href); - if (ret < 0) { + if (ret < 0) printf("Failed to get author href\n"); - } if (author_href) printf("Author Href: %s\n", author_href); ret = pkgmgrinfo_pkginfo_get_root_path(handle, &root_path); - if (ret < 0) { + if (ret < 0) printf("Failed to get root_path\n"); - } - if (author_href) + if (root_path) printf("root_path : %s\n", root_path); ret = pkgmgrinfo_pkginfo_get_mainappid(handle, &mainappid); - if (ret < 0) { + if (ret < 0) printf("Failed to get mainappid\n"); - } - if (author_href) + if (mainappid) printf("mainappid : %s\n", mainappid); ret = pkgmgrinfo_pkginfo_get_installed_time(handle, &installed_time); - if (ret < 0) { + if (ret < 0) printf("Failed to get install time\n"); - } printf("Install time: %d\n", installed_time); ret = pkgmgrinfo_pkginfo_is_removable(handle, &removable); - if (ret < 0) { + if (ret < 0) printf("Failed to get removable\n"); - } else printf("Removable: %d\n", removable); ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload); - if (ret < 0) { + if (ret < 0) printf("Failed to get preload\n"); - } else printf("Preload: %d\n", preload); ret = pkgmgrinfo_pkginfo_is_readonly(handle, &readonly); - if (ret < 0) { + if (ret < 0) printf("Failed to get readonly\n"); - } else printf("Readonly: %d\n", readonly); ret = pkgmgrinfo_pkginfo_is_update(handle, &update); - if (ret < 0) { + if (ret < 0) printf("Failed to get update\n"); - } else printf("update: %d\n", update); ret = pkgmgrinfo_pkginfo_is_system(handle, &system); - if (ret < 0) { + if (ret < 0) printf("Failed to get system\n"); - } else printf("system: %d\n", system); } @@ -206,14 +189,12 @@ int __get_app_id(const pkgmgrinfo_appinfo_h handle, void *user_data) int ret = -1; ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); - if (ret < 0) { + if (ret < 0) printf("Failed to get appid\n"); - } ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype); - if (ret < 0) { + if (ret < 0) printf("Failed to get package\n"); - } printf("apptype [%s]\t appid [%s]\n", apptype, appid); return 0; @@ -245,11 +226,13 @@ char *__get_string_input_data(void) printf("Malloc Failed\n"); return NULL; } - if (fgets(data,1024,stdin) == NULL){ + + if (fgets(data, 1024, stdin) == NULL) { printf("Buffer overflow!!! try again\n"); exit(-1); } data[strlen(data) - 1] = '\0'; + return data; } @@ -319,8 +302,10 @@ static void __print_arg_filter_usage() static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data) { char *appid = NULL; + pkgmgrinfo_appinfo_get_appid(handle, &appid); printf("appid : %s\n", appid); + return 0; } @@ -332,7 +317,7 @@ static int __add_metadata_filter() char *value = NULL; ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle); - if (ret != PMINFO_R_OK){ + if (ret != PMINFO_R_OK) { printf("pkgmgrinfo_appinfo_metadata_filter_create() failed\n"); return ret; } @@ -345,13 +330,13 @@ static int __add_metadata_filter() printf("filter condition : key=[%s], value=[%s]\n", key, value); ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, key, value); - if (ret != PMINFO_R_OK){ + if (ret != PMINFO_R_OK) { printf("pkgmgrinfo_appinfo_metadata_filter_add() failed\n"); goto err; } ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, __app_list_cb, NULL); - if (ret != PMINFO_R_OK){ + if (ret != PMINFO_R_OK) { printf("pkgmgrinfo_appinfo_metadata_filter_add() failed\n"); goto err; } @@ -377,13 +362,14 @@ static int __add_app_filter(uid_t uid) int val = -1; int count = 0; pkgmgrinfo_appinfo_filter_h handle; + ret = pkgmgrinfo_appinfo_filter_create(&handle); if (ret > 0) { printf("appinfo filter handle create failed\n"); return -1; } - while (choice != 0 && choice != 1) - { + + while (choice != 0 && choice != 1) { printf("Enter Choice\n"); printf("0 --> Finalize filter and get count of apps\n"); printf("1 --> Finalize filter and get list of apps\n"); @@ -659,8 +645,8 @@ static int __add_pkg_filter(uid_t uid) printf("pkginfo filter handle create failed\n"); return -1; } - while (choice != 0 && choice !=1) - { + + while (choice != 0 && choice != 1) { printf("Enter Choice\n"); printf("0 --> Finalize filter and get count of packages\n"); printf("1 --> Finalize filter and get list of packages\n"); @@ -1083,18 +1069,20 @@ static int __get_certinfo_from_db(char *pkgid, uid_t uid) int i = 0; const char *value = NULL; pkgmgrinfo_certinfo_h handle = NULL; + ret = pkgmgrinfo_pkginfo_create_certinfo(&handle); if (ret < 0) { printf("pkgmgrinfo_pkginfo_create_certinfo failed\n"); return -1; } + ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle, uid); if (ret < 0) { printf("pkgmgrinfo_pkginfo_load_certinfo failed\n"); return -1; } - while (choice != 10) - { + + while (choice != 10) { printf("Enter the choice to get\n"); printf("0 --> to get all cert values\n"); printf("1 --> author root certificate\n"); @@ -1110,8 +1098,7 @@ static int __get_certinfo_from_db(char *pkgid, uid_t uid) choice = __get_integer_input_data(); switch (choice) { case 0: - for (i = 0; i < 9; i++) - { + for (i = 0; i < 9; i++) { pkgmgrinfo_pkginfo_get_cert_value(handle, i, &value); if (value) printf("cert type[%d] value = %s\n", i, value); @@ -1162,9 +1149,8 @@ static int __compare_pkg_certinfo_from_db(char *lhs_pkgid, char *rhs_pkgid, uid_ ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_pkgid, rhs_pkgid, uid, &result); else ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lhs_pkgid, rhs_pkgid, &result); - if (ret != PMINFO_R_OK) { + if (ret != PMINFO_R_OK) return -1; - } printf("Compare [match=0, mismatch=1, lhs_no=2, rhs_no=3, both_no=4]\n"); printf("pkgid =[%s] and [%s] compare result = [%d] \n", lhs_pkgid, rhs_pkgid, result); @@ -1184,9 +1170,8 @@ static int __compare_app_certinfo_from_db(char *lhs_appid, char *rhs_appid, uid_ ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(lhs_appid, rhs_appid, uid, &result); else ret = pkgmgrinfo_pkginfo_compare_app_cert_info(lhs_appid, rhs_appid, &result); - if (ret != PMINFO_R_OK) { + if (ret != PMINFO_R_OK) return -1; - } printf("Compare [match=0, mismatch=1, lhs_no=2, rhs_no=3, both_no=4]\n"); printf("appid =[%s] and [%s] compare result = [%d] \n", lhs_appid, rhs_appid, result); @@ -1203,13 +1188,14 @@ static int __set_certinfo_in_db(char *pkgid, uid_t uid) int choice = -1; char *value = NULL; pkgmgr_instcertinfo_h handle = NULL; + ret = pkgmgr_installer_create_certinfo_set_handle(&handle); if (ret < 0) { printf("pkgmgr_installer_create_certinfo_set_handle failed\n"); return -1; } - while (choice != 0) - { + + while (choice != 0) { printf("Enter the choice you want to set\n"); printf("0 --> to set data in DB\n"); printf("1 --> author root certificate\n"); @@ -1421,70 +1407,63 @@ static int __remove_manifest_from_db(char *manifest, uid_t uid) int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data) { + int ret = -1; char *appid; char *data = NULL; - if (user_data) { - data = (char *)user_data; - } - int ret = -1; char *exec = NULL; char *icon = NULL; char *label = NULL; - pkgmgrinfo_app_component component = 0; char *apptype = NULL; + char *package = NULL; bool nodisplay = 0; bool multiple = 0; bool taskmanage = 0; - pkgmgrinfo_app_hwacceleration hwacceleration; - pkgmgrinfo_app_screenreader screenreader; bool onboot = 0; bool autorestart = 0; - char *package = NULL; + pkgmgrinfo_app_component component = 0; + pkgmgrinfo_app_hwacceleration hwacceleration; + pkgmgrinfo_app_screenreader screenreader; + + if (user_data) + data = (char *)user_data; ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); - if (ret < 0) { + if (ret < 0) printf("Failed to get appid\n"); - } if (appid) printf("Appid: %s\n", appid); ret = pkgmgrinfo_appinfo_get_pkgid(handle, &package); - if (ret < 0) { + if (ret < 0) printf("Failed to get package\n"); - } if (package) printf("Package: %s\n", package); ret = pkgmgrinfo_appinfo_get_exec(handle, &exec); - if (ret < 0) { + if (ret < 0) printf("Failed to get exec\n"); - } if (exec) printf("Exec: %s\n", exec); ret = pkgmgrinfo_appinfo_get_icon(handle, &icon); - if (ret < 0) { + if (ret < 0) printf("Failed to get icon\n"); - } if (icon) printf("Icon: %s\n", icon); ret = pkgmgrinfo_appinfo_get_label(handle, &label); - if (ret < 0) { + if (ret < 0) printf("Failed to get label\n"); - } if (label) printf("Label: %s\n", label); ret = pkgmgrinfo_appinfo_get_component(handle, &component); - if (ret < 0) { + if (ret < 0) printf("Failed to get component\n"); - } ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype); - if (ret < 0) { + if (ret < 0) printf("Failed to get apptype\n"); - } if (apptype) printf("Apptype: %s\n", apptype); @@ -1492,57 +1471,51 @@ int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data) printf("component: %s\n", component == PMINFO_UI_APP ? "uiapp" : "widgetapp"); ret = pkgmgrinfo_appinfo_is_multiple(handle, &multiple); - if (ret < 0) { + if (ret < 0) printf("Failed to get multiple\n"); - } else { + else printf("Multiple: %d\n", multiple); - } ret = pkgmgrinfo_appinfo_is_nodisplay(handle, &nodisplay); - if (ret < 0) { + if (ret < 0) printf("Failed to get nodisplay\n"); - } else { + else printf("Nodisplay: %d \n", nodisplay); - } ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage); - if (ret < 0) { + if (ret < 0) printf("Failed to get taskmanage\n"); - } else { + else printf("Taskmanage: %d\n", taskmanage); - } ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacceleration); - if (ret < 0) { + if (ret < 0) printf("Failed to get hwacceleration\n"); - } else { + else printf("hw-acceleration: %d\n", hwacceleration); - } ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader); - if (ret < 0) { + if (ret < 0) printf("Failed to get screenreader\n"); - } else { + else printf("screenreader: %d\n", screenreader); - } - } + if (component == PMINFO_SVC_APP) { printf("component: svcapp\n"); ret = pkgmgrinfo_appinfo_is_onboot(handle, &onboot); - if (ret < 0) { + if (ret < 0) printf("Failed to get onboot\n"); - } else { + else printf("Onboot: %d\n", onboot); - } ret = pkgmgrinfo_appinfo_is_autorestart(handle, &autorestart); - if (ret < 0) { + if (ret < 0) printf("Failed to get autorestart\n"); - } else { + else printf("Autorestart: %d \n", autorestart); - } } + if (data) printf("user_data : %s\n\n", data); @@ -1550,38 +1523,36 @@ int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data) } -static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data) +static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data) { - char *test_data = "test data"; int ret = -1; + int installed_time = -1; + char *test_data = "test data"; char *pkgid; char *pkg_type; char *pkg_version; bool preload = 0; - int installed_time = -1; pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle; ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid); - if(ret < 0) { + if (ret < 0) printf("pkgmgrinfo_pkginfo_get_pkgid() failed\n"); - } + ret = pkgmgrinfo_pkginfo_get_type(handle, &pkg_type); - if(ret < 0) { + if (ret < 0) printf("pkgmgrinfo_pkginfo_get_type() failed\n"); - } + ret = pkgmgrinfo_pkginfo_get_version(handle, &pkg_version); - if(ret < 0) { + if (ret < 0) printf("pkgmgrinfo_pkginfo_get_version() failed\n"); - } + ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload); - if(ret < 0) { + if (ret < 0) printf("pkgmgrinfo_pkginfo_is_preload() failed\n"); - } + ret = pkgmgrinfo_pkginfo_get_installed_time(handle, &installed_time); - if(ret < 0) { + if (ret < 0) printf("pkgmgrinfo_pkginfo_get_installed_time() failed\n"); - } - printf("---------------------------------------\n"); printf("pkg_type [%s]\tpkgid [%s]\tversion [%s]\tpreload [%d]\tinstalled_time [%d]\n", pkg_type, @@ -1590,25 +1561,23 @@ static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data) if (uid_info->uid != GLOBAL_USER) { printf("**List of Ui-Apps**\n"); ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_UI_APP, app_func, (void *)test_data, uid_info->uid); - if (ret < 0) { + if (ret < 0) printf("pkgmgr_get_info_app() failed\n"); - } + printf("**List of Svc-Apps**\n"); ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data, uid_info->uid); - if (ret < 0) { + if (ret < 0) printf("pkgmgr_get_info_app() failed\n"); - } } else { printf("**List of Ui-Apps**\n"); ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, app_func, (void *)test_data); - if (ret < 0) { + if (ret < 0) printf("pkgmgr_get_info_app() failed\n"); - } + printf("**List of Svc-Apps**\n"); ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data); - if (ret < 0) { + if (ret < 0) printf("pkgmgr_get_info_app() failed\n"); - } } printf("---------------------------------------\n"); @@ -1618,6 +1587,7 @@ static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data) static int __get_pkg_list(uid_t uid) { int ret = -1; + if (uid != GLOBAL_USER) ret = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, NULL, uid); else @@ -1626,13 +1596,15 @@ static int __get_pkg_list(uid_t uid) printf("pkgmgrinfo_pkginfo_get_list() failed\n"); return -1; } + return 0; } static int __get_installed_app_list(uid_t uid) { int ret = -1; - if(uid != GLOBAL_USER) + + if (uid != GLOBAL_USER) ret = pkgmgrinfo_appinfo_get_usr_installed_list(app_func, uid, NULL); else ret = pkgmgrinfo_appinfo_get_installed_list(app_func, NULL); @@ -1640,6 +1612,7 @@ static int __get_installed_app_list(uid_t uid) printf("pkgmgrinfo_appinfo_get_installed_list() failed\n"); return -1; } + return 0; } @@ -1676,18 +1649,22 @@ static int __get_app_category_list(char *appid) { int ret = -1; pkgmgrinfo_appinfo_h handle; + ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle); if (ret < 0) { printf("Failed to get handle\n"); return -1; } + ret = pkgmgrinfo_appinfo_foreach_category(handle, __app_category_list_cb, NULL); if (ret < 0) { printf("pkgmgrinfo_appinfo_foreach_category() failed\n"); pkgmgrinfo_appinfo_destroy_appinfo(handle); return -1; } + pkgmgrinfo_appinfo_destroy_appinfo(handle); + return 0; } @@ -1695,18 +1672,22 @@ static int __get_app_metadata_list(char *appid) { int ret = -1; pkgmgrinfo_appinfo_h handle; + ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle); if (ret < 0) { printf("Failed to get handle\n"); return -1; } + ret = pkgmgrinfo_appinfo_foreach_metadata(handle, __app_metadata_list_cb, NULL); if (ret < 0) { printf("pkgmgrinfo_appinfo_foreach_metadata() failed\n"); pkgmgrinfo_appinfo_destroy_appinfo(handle); return -1; } + pkgmgrinfo_appinfo_destroy_appinfo(handle); + return 0; } @@ -1714,38 +1695,45 @@ static int __get_app_control_list(char *appid) { int ret = -1; pkgmgrinfo_appinfo_h handle; + ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle); if (ret < 0) { printf("Failed to get handle\n"); return -1; } + ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, __app_control_list_cb, NULL); if (ret < 0) { printf("pkgmgrinfo_appinfo_foreach_appcontrol() failed\n"); pkgmgrinfo_appinfo_destroy_appinfo(handle); return -1; } + pkgmgrinfo_appinfo_destroy_appinfo(handle); + return 0; } static int __set_app_enabled(char *appid, bool enabled) { int ret = -1; + ret = pkgmgrinfo_appinfo_set_state_enabled(appid, enabled); if (ret < 0) { printf("Failed to get handle\n"); return -1; } + return 0; } static int __get_app_list(char *pkgid, uid_t uid) { - pkgmgrinfo_pkginfo_h handle; int ret = -1; char *test_data = "test data"; - if(uid != GLOBAL_USER) + pkgmgrinfo_pkginfo_h handle; + + if (uid != GLOBAL_USER) ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); else ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); @@ -1753,40 +1741,41 @@ static int __get_app_list(char *pkgid, uid_t uid) printf("Failed to get handle\n"); return -1; } + if (uid != GLOBAL_USER) { printf("List of Ui-Apps\n\n"); ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_UI_APP, app_func, (void *)test_data, uid); - if (ret < 0) { + if (ret < 0) printf("pkgmgrinfo_appinfo_get_list() failed\n"); - } + printf("List of Svc-Apps\n\n"); ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data, uid); - if (ret < 0) { + if (ret < 0) printf("pkgmgrinfo_appinfo_get_list() failed\n"); - } } else { printf("List of Ui-Apps\n\n"); ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, app_func, (void *)test_data); - if (ret < 0) { + if (ret < 0) printf("pkgmgrinfo_appinfo_get_list() failed\n"); - } + printf("List of Svc-Apps\n\n"); ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data); - if (ret < 0) { + if (ret < 0) printf("pkgmgrinfo_appinfo_get_list() failed\n"); - } } + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + return 0; } static int __get_pkg_info(char *pkgid, uid_t uid) { - pkgmgrinfo_pkginfo_h handle; int ret = -1; + pkgmgrinfo_pkginfo_h handle; printf("Get Pkg Info Called [%s]\n", pkgid); - if(uid != GLOBAL_USER) + if (uid != GLOBAL_USER) ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); else ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); @@ -1798,30 +1787,32 @@ static int __get_pkg_info(char *pkgid, uid_t uid) __get_pkgmgrinfo_pkginfo(handle, NULL); pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + return 0; } static int __get_app_info(char *appid) { - printf("Get App Info Called [%s]\n", appid); + int ret = -1; char *exec = NULL; char *app_id = NULL; char *apptype = NULL; char *icon = NULL; char *label = NULL; char *package = NULL; - pkgmgrinfo_app_component component = 0; bool nodisplay = 0; bool multiple = 0; bool taskmanage = 0; - pkgmgrinfo_app_hwacceleration hwacceleration; - pkgmgrinfo_app_screenreader screenreader; bool onboot = 0; bool autorestart = 0; bool enabled = 0; bool preload = 0; pkgmgrinfo_appinfo_h handle; - int ret = -1; + pkgmgrinfo_app_component component = 0; + pkgmgrinfo_app_hwacceleration hwacceleration; + pkgmgrinfo_app_screenreader screenreader; + + printf("Get App Info Called [%s]\n", appid); ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle); if (ret < 0) { @@ -1830,72 +1821,68 @@ static int __get_app_info(char *appid) } ret = pkgmgrinfo_appinfo_get_pkgid(handle, &package); - if (ret < 0) { + if (ret < 0) printf("Failed to get package\n"); - } ret = pkgmgrinfo_appinfo_get_appid(handle, &app_id); - if (ret < 0) { + if (ret < 0) printf("Failed to get exec\n"); - } ret = pkgmgrinfo_appinfo_get_label(handle, &label); - if (ret < 0) { + if (ret < 0) printf("Failed to get label\n"); - } + ret = pkgmgrinfo_appinfo_get_icon(handle, &icon); - if (ret < 0) { + if (ret < 0) printf("Failed to get icon\n"); - } ret = pkgmgrinfo_appinfo_get_exec(handle, &exec); - if (ret < 0) { + if (ret < 0) printf("Failed to get exec\n"); - } + ret = pkgmgrinfo_appinfo_get_component(handle, &component); - if (ret < 0) { + if (ret < 0) printf("Failed to get component\n"); - } + ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype); - if (ret < 0) { + if (ret < 0) printf("Failed to get apptype\n"); - } + ret = pkgmgrinfo_appinfo_is_nodisplay(handle, &nodisplay); - if (ret < 0) { + if (ret < 0) printf("Failed to get nodisplay\n"); - } + ret = pkgmgrinfo_appinfo_is_multiple(handle, &multiple); - if (ret < 0) { + if (ret < 0) printf("Failed to get multiple\n"); - } + ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage); - if (ret < 0) { + if (ret < 0) printf("Failed to get taskmanage\n"); - } + ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacceleration); - if (ret < 0) { + if (ret < 0) printf("Failed to get hwacceleration\n"); - } + ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader); - if (ret < 0) { + if (ret < 0) printf("Failed to get screenreader\n"); - } + ret = pkgmgrinfo_appinfo_is_onboot(handle, &onboot); - if (ret < 0) { + if (ret < 0) printf("Failed to get onboot\n"); - } + ret = pkgmgrinfo_appinfo_is_autorestart(handle, &autorestart); - if (ret < 0) { + if (ret < 0) printf("Failed to get autorestart\n"); - } + ret = pkgmgrinfo_appinfo_is_enabled(handle, &enabled); - if (ret < 0) { + if (ret < 0) printf("Failed to get enabled\n"); - } + ret = pkgmgrinfo_appinfo_is_preload(handle, &preload); - if (ret < 0) { + if (ret < 0) printf("Failed to get preload\n"); - } if (app_id) printf("Appid: %s\n", app_id); @@ -1905,6 +1892,7 @@ static int __get_app_info(char *appid) if (exec) printf("Exec: %s\n", exec); + if (apptype) printf("Apptype: %s\n", apptype); @@ -1940,22 +1928,25 @@ static int __get_app_info(char *appid) printf("Preload: %d\n", preload); pkgmgrinfo_appinfo_destroy_appinfo(handle); - return 0; + return 0; } static int __check_manifest_validation(char *manifest) { int ret = 0; + if (manifest == NULL) { printf("Manifest file is NULL\n"); return -1; } + ret = pkgmgr_parser_check_manifest_validation(manifest); if (ret < 0) { printf("check manifest validation failed\n"); return -1; } + return 0; } @@ -2015,16 +2006,16 @@ int main(int argc, char *argv[]) ret = -1; goto end; } - }else if (argc == 4) { + } else if (argc == 4) { if (strcmp(argv[1], "--setappenabled") == 0) { - ret = __set_app_enabled(argv[2], (strcmp(argv[3], "0")==0)?false:true); + ret = __set_app_enabled(argv[2], (strcmp(argv[3], "0") == 0) ? false : true); if (ret == -1) { printf("set app enabled failed\n"); goto end; } goto end; - } else if(strcmp(argv[1], "--setpkgenabled") == 0) { - ret = __set_app_enabled(argv[2], (strcmp(argv[3], "0")==0)?false:true); + } else if (strcmp(argv[1], "--setpkgenabled") == 0) { + ret = __set_app_enabled(argv[2], (strcmp(argv[3], "0") == 0) ? false : true); if (ret == -1) { printf("set pkg enabled failed\n"); goto end; @@ -2151,7 +2142,6 @@ int main(int argc, char *argv[]) __print_usage(); end: - gettimeofday(&tv, NULL); endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l; diff --git a/src/pkg_initdb.c b/src/pkg_initdb.c index 1dfcb8e..558f7c3 100644 --- a/src/pkg_initdb.c +++ b/src/pkg_initdb.c @@ -45,12 +45,14 @@ #ifdef _E #undef _E #endif -#define _E(fmt, arg...) fprintf(stderr, "[PKG_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); +#define _E(fmt, arg...) fprintf(stderr, "[PKG_INITDB][E][%s,%d] "fmt"\n", \ + __FUNCTION__, __LINE__, ##arg); #ifdef _D #undef _D #endif -#define _D(fmt, arg...) fprintf(stderr, "[PKG_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); +#define _D(fmt, arg...) fprintf(stderr, "[PKG_INITDB][D][%s,%d] "fmt"\n", \ + __FUNCTION__, __LINE__, ##arg); #define PKGINSTALLMANIFEST_CMD "/usr/bin/pkg-install-manifest" @@ -62,7 +64,7 @@ static int _is_global(uid_t uid) static int _initdb_load_directory(uid_t uid, const char *directory) { DIR *dir; - struct dirent entry, *result; + struct dirent file_info, *result; int ret; char buf[BUFSZE]; @@ -75,13 +77,13 @@ static int _initdb_load_directory(uid_t uid, const char *directory) _D("Loading manifest files from %s", directory); - for (ret = readdir_r(dir, &entry, &result); + for (ret = readdir_r(dir, &file_info, &result); ret == 0 && result != NULL; - ret = readdir_r(dir, &entry, &result)) { - if (entry.d_name[0] == '.') + ret = readdir_r(dir, &file_info, &result)) { + if (file_info.d_name[0] == '.') continue; - snprintf(buf, sizeof(buf), "%s/%s", directory, entry.d_name); + snprintf(buf, sizeof(buf), "%s/%s", directory, file_info.d_name); _D("manifest file %s", buf); pid_t pid = fork(); @@ -93,7 +95,7 @@ static int _initdb_load_directory(uid_t uid, const char *directory) } execl(PKGINSTALLMANIFEST_CMD, PKGINSTALLMANIFEST_CMD, "-x", buf, - (char*)NULL); + (char *)NULL); } else if (pid < 0) { _E("failed to fork and execute %s!", PKGINSTALLMANIFEST_CMD); closedir(dir); -- 2.7.4 From f6eb6080e222b85ea1de58bc52db5aad612c0c7a Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 15 Mar 2016 17:39:51 +0900 Subject: [PATCH 07/16] change functions for thread-safe Change-Id: I5d512626df6b532914b5d9a548cfd16ef8846b54 Signed-off-by: Junghyun Yeon --- src/pkg_clearcache.c | 16 ++++++++++------ src/pkg_getsize.c | 50 ++++++++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/pkg_clearcache.c b/src/pkg_clearcache.c index 14181e2..07250d2 100644 --- a/src/pkg_clearcache.c +++ b/src/pkg_clearcache.c @@ -49,7 +49,8 @@ static int __clear_dir(const char *dirname) { int ret = 0; DIR *dp = NULL; - struct dirent *ep = NULL; + char buf[1024] = {0, }; + struct dirent ep, *result; char *abs_filename = NULL; struct stat stFileInfo; @@ -64,18 +65,21 @@ static int __clear_dir(const char *dirname) dp = opendir(dirname); if (dp == NULL) { LOGE("Couldn't open the directory. errno : %d (%s)\n", errno, - strerror(errno)); + strerror_r(errno, buf, sizeof(buf))); goto err; } - while ((ep = readdir(dp))) { + + for (ret = readdir_r(dp, &ep, &result); + ret == 0 && result != NULL; + ret = readdir_r(dp, &ep, &result)) { snprintf(abs_filename, PATH_MAX - 1, "%s/%s", dirname, - ep->d_name); + ep.d_name); if (lstat(abs_filename, &stFileInfo) < 0) perror(abs_filename); 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 = __clear_dir(abs_filename); if (ret != 0) LOGE("Couldn't remove the directory. " diff --git a/src/pkg_getsize.c b/src/pkg_getsize.c index d27a32d..6ac2ddf 100644 --- a/src/pkg_getsize.c +++ b/src/pkg_getsize.c @@ -82,14 +82,15 @@ static long long __calculate_directory_size(int dfd, bool include_itself) int subfd; int ret; DIR *dir; - struct dirent *dent; + struct dirent dent, *result; const char *file_info; + char buf[1024] = {0, }; if (include_itself) { ret = fstat(dfd, &st); if (ret < 0) { ERR("fstat() failed, file_info: ., errno: %d (%s)", errno, - strerror(errno)); + strerror_r(errno, buf, sizeof(buf))); return -1; } size += __stat_size(&st); @@ -98,12 +99,14 @@ static long long __calculate_directory_size(int dfd, bool include_itself) dir = fdopendir(dfd); if (dir == NULL) { ERR("fdopendir() failed, errno: %d (%s)", errno, - strerror(errno)); + strerror_r(errno, buf, sizeof(buf))); return -1; } - while ((dent = readdir(dir))) { - file_info = dent->d_name; + for (ret = readdir_r(dir, &dent, &result); + ret == 0 && result != NULL; + ret = readdir_r(dir, &dent, &result)) { + file_info = dent.d_name; if (file_info[0] == '.') { if (file_info[1] == '\0') continue; @@ -111,11 +114,11 @@ static long long __calculate_directory_size(int dfd, bool include_itself) continue; } - if (dent->d_type == DT_DIR) { + if (dent.d_type == DT_DIR) { subfd = openat(dfd, file_info, O_RDONLY | O_DIRECTORY); if (subfd < 0) { ERR("openat() failed, file_info:%s, errno: %d(%s)", - file_info, errno, strerror(errno)); + file_info, errno, strerror_r(errno, buf, sizeof(buf))); goto error; } @@ -126,7 +129,7 @@ static long long __calculate_directory_size(int dfd, bool include_itself) ret = fstatat(dfd, file_info, &st, AT_SYMLINK_NOFOLLOW); if (ret < 0) { ERR("fstatat() failed, file_info:%s, errno: %d(%s)", - file_info, errno, strerror(errno)); + file_info, errno, strerror_r(errno, buf, sizeof(buf))); goto error; } size += __stat_size(&st); @@ -149,20 +152,21 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir, long long size = 0; struct stat st; int ret; + char buf[1024] = {0, }; DBG("traverse path: %s/shared", app_root_dir); fd = openat(dfd, "shared", O_RDONLY | O_DIRECTORY); if (fd < 0) { ERR("openat() failed, path: %s/shared, errno: %d (%s)", - app_root_dir, errno, strerror(errno)); + app_root_dir, errno, strerror_r(errno, buf, sizeof(buf))); return -1; } ret = fstat(fd, &st); if (ret < 0) { ERR("fstat() failed, path: %s/shared, errno: %d (%s)", - app_root_dir, errno, strerror(errno)); + app_root_dir, errno, strerror_r(errno, buf, sizeof(buf))); goto error; } *app_size += __stat_size(&st); /* shared directory */ @@ -182,7 +186,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir, close(subfd); } else if (subfd < 0 && errno != ENOENT) { ERR("openat() failed, file_info: data, errno: %d (%s)", - errno, strerror(errno)); + errno, strerror_r(errno, buf, sizeof(buf))); goto error; } @@ -200,7 +204,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir, close(subfd); } else if (subfd < 0 && errno != ENOENT) { DBG("openat() failed, file_info: trusted, errno: %d (%s)", - errno, strerror(errno)); + errno, strerror_r(errno, buf, sizeof(buf))); goto error; } @@ -218,7 +222,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir, close(subfd); } else if (subfd < 0 && errno != ENOENT) { ERR("openat() failed, file_info: res, errno: %d (%s)", - errno, strerror(errno)); + errno, strerror_r(errno, buf, sizeof(buf))); goto error; } @@ -236,7 +240,7 @@ static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir, close(subfd); } else if (subfd < 0 && errno != ENOENT) { ERR("openat() failed, file_info: data, errno: %d (%s)", - errno, strerror(errno)); + errno, strerror_r(errno, buf, sizeof(buf))); goto error; } @@ -263,12 +267,13 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, const char *pkgid, { uid_t uid = getuid(); char app_root_dir[MAX_PATH_LENGTH] = {0, }; + char buf[1024] = {0, }; DIR *dir; int dfd; int subfd = -1; struct stat st; int ret; - struct dirent *ent; + struct dirent ent, *result; long long size = 0; if (type == STORAGE_TYPE_INTERNAL) { @@ -291,7 +296,7 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, const char *pkgid, dir = opendir(app_root_dir); if (dir == NULL) { ERR("opendir() failed, path: %s, errno: %d (%s)", - app_root_dir, errno, strerror(errno)); + app_root_dir, errno, strerror_r(errno, buf, sizeof(buf))); return -1; } @@ -299,13 +304,14 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, const char *pkgid, ret = fstat(dfd, &st); if (ret < 0) { ERR("fstat() failed, path: %s, errno: %d (%s)", app_root_dir, - errno, strerror(errno)); + errno, strerror_r(errno, buf, sizeof(buf))); goto error; } *app_size += __stat_size(&st); - - while ((ent = readdir(dir))) { - const char *name = ent->d_name; + for (ret = readdir_r(dir, &ent, &result); + ret == 0 && result != NULL; + ret = readdir_r(dir, &ent, &result)) { + const char *name = ent.d_name; if (name[0] == '.') { if (name[1] == '\0') continue; @@ -313,14 +319,14 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, const char *pkgid, continue; } - if (ent->d_type != DT_DIR) + if (ent.d_type != DT_DIR) continue; subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY); if (subfd < 0) { if (errno != ENOENT) { ERR("openat() failed, errno: %d (%s)", - errno, strerror(errno)); + errno, strerror_r(errno, buf, sizeof(buf))); goto error; } continue; -- 2.7.4 From f36aea3c4e00e9f3e3887d56d6be54af28724ad2 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 18 Mar 2016 14:32:43 +0900 Subject: [PATCH 08/16] Handle error case on execl failed Change-Id: I02b91937306a44affb17cf7e7b404a08215dcf2b Signed-off-by: Sangyoon Jang --- src/pkg_initdb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pkg_initdb.c b/src/pkg_initdb.c index 558f7c3..9bc70c9 100644 --- a/src/pkg_initdb.c +++ b/src/pkg_initdb.c @@ -96,6 +96,8 @@ static int _initdb_load_directory(uid_t uid, const char *directory) execl(PKGINSTALLMANIFEST_CMD, PKGINSTALLMANIFEST_CMD, "-x", buf, (char *)NULL); + _E("failed to execute: %s", strerror_r(errno, buf, sizeof(buf))); + exit(EXIT_FAILURE); } else if (pid < 0) { _E("failed to fork and execute %s!", PKGINSTALLMANIFEST_CMD); closedir(dir); -- 2.7.4 From 275faada18aeda29784b5c03eb35f3c2d1bc13ca Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Tue, 15 Mar 2016 19:16:12 +0900 Subject: [PATCH 09/16] handle postscrpt fail. Should be merged with: https://review.tizen.org/gerrit/#/c/61686/ Change-Id: Ie025fbb28c96d979a794c6893067da732db98c3c Signed-off-by: jongmyeongko --- packaging/pkgmgr-tool.spec | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index dc4a2a5..b91991f 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -58,6 +58,14 @@ chsmack -a '*' %{TZ_SYS_RW_PACKAGES} %posttrans pkg_initdb install_preload_tpk +if [ -f /tmp/.preload_install_error ] +then + if [ ! -d /tmp/.postscript/error ] + then + mkdir -p /tmp/.postscript/error + fi + echo "preload install failed" > /tmp/.postscript/error/%{name}_error +fi %files %manifest %{name}.manifest -- 2.7.4 From c558e1b01ad7584689d930892f8adae84110c883 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Wed, 16 Mar 2016 17:40:07 +0900 Subject: [PATCH 10/16] do not support parsing and db-control via pkginfo. Change-Id: I5acd2205ca77a4cd8b3ce7653e6fa0510410e2f0 Signed-off-by: jongmyeongko --- src/pkg_info.c | 78 +++++----------------------------------------------------- 1 file changed, 6 insertions(+), 72 deletions(-) diff --git a/src/pkg_info.c b/src/pkg_info.c index d7f42f5..9b84209 100644 --- a/src/pkg_info.c +++ b/src/pkg_info.c @@ -47,8 +47,6 @@ static int __get_pkg_list(uid_t uid); static int __get_installed_app_list(uid_t uid); static int __add_app_filter(uid_t uid); static int __add_pkg_filter(uid_t uid); -static int __insert_manifest_in_db(char *manifest, uid_t uid); -static int __remove_manifest_from_db(char *manifest, uid_t uid); static int __set_certinfo_in_db(char *pkgid, uid_t uid); static int __get_certinfo_from_db(char *pkgid, uid_t uid); static int __del_certinfo_from_db(char *pkgid); @@ -1350,61 +1348,6 @@ err: return ret; } -static int __insert_manifest_in_db(char *manifest, uid_t uid) -{ - int ret = 0; - if (manifest == NULL) { - printf("Manifest file is NULL\n"); - return -1; - } - if (uid == GLOBAL_USER || uid == OWNER_ROOT) - ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL); - else - ret = pkgmgr_parser_parse_usr_manifest_for_installation(manifest, uid, NULL); - if (ret < 0) { - printf("insert in db failed\n"); - return -1; - } - return 0; -} - -static int __fota_insert_manifest_in_db(char *manifest, uid_t uid) -{ - int ret = 0; - - if (manifest == NULL) { - printf("Manifest file is NULL\n"); - return -1; - } - if (uid != GLOBAL_USER) - ret = pkgmgr_parser_parse_usr_manifest_for_installation(manifest, uid, NULL); - else - ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL); - if (ret < 0) { - printf("insert in db failed\n"); - return -1; - } - return 0; -} - -static int __remove_manifest_from_db(char *manifest, uid_t uid) -{ - int ret = 0; - if (manifest == NULL) { - printf("Manifest file is NULL\n"); - return -1; - } - if (uid != GLOBAL_USER) - ret = pkgmgr_parser_parse_usr_manifest_for_uninstallation(manifest, uid, NULL); - else - ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL); - if (ret < 0) { - printf("remove from db failed\n"); - return -1; - } - return 0; -} - int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data) { int ret = -1; @@ -2079,23 +2022,14 @@ int main(int argc, char *argv[]) goto end; } } else if (strcmp(argv[1], "--imd") == 0) { - ret = __insert_manifest_in_db(argv[2], getuid()); - if (ret == -1) { - printf("insert in db failed\n"); - goto end; - } + printf("Not supported!\n"); + goto end; } else if (strcmp(argv[1], "--fota") == 0) { - ret = __fota_insert_manifest_in_db(argv[2], getuid()); - if (ret == -1) { - printf("insert in db failed\n"); - goto end; - } + printf("Not supported!\n"); + goto end; } else if (strcmp(argv[1], "--rmd") == 0) { - ret = __remove_manifest_from_db(argv[2], getuid()); - if (ret == -1) { - printf("remove from db failed\n"); - goto end; - } + printf("Not supported!\n"); + goto end; } else if (strcmp(argv[1], "--setcert") == 0) { ret = __set_certinfo_in_db(argv[2], getuid()); if (ret == -1) { -- 2.7.4 From 5673ae324aa793581240430b52ff7e816ce320ba Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Thu, 17 Mar 2016 17:08:16 +0900 Subject: [PATCH 11/16] fix wrong path for processing RW packages Change-Id: I79c15d790cb4cbffef94366fb6c7f0f41323c0a3 Signed-off-by: jongmyeongko --- src/pkg_initdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg_initdb.c b/src/pkg_initdb.c index 9bc70c9..6e00960 100644 --- a/src/pkg_initdb.c +++ b/src/pkg_initdb.c @@ -192,7 +192,7 @@ int main(int argc, char *argv[]) dir_rw = tzplatform_getenv(TZ_SYS_RW_PACKAGES); if (dir && dir_rw) if (strcmp(dir, dir_rw)) - ret = _initdb_load_directory(uid, dir); + ret = _initdb_load_directory(uid, dir_rw); } else { /* specified user location */ tzplatform_set_user(uid); -- 2.7.4 From 13d6091d11c50294f259c79588692309cc3cd765 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 22 Mar 2016 17:37:46 +0900 Subject: [PATCH 12/16] Fix coding style Change-Id: Ibb9d241adafabd1023a52880d304f6e4827d8416 Signed-off-by: Sangyoon Jang --- src/pkg_initdb.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/pkg_initdb.c b/src/pkg_initdb.c index 6e00960..b61abbb 100644 --- a/src/pkg_initdb.c +++ b/src/pkg_initdb.c @@ -64,9 +64,11 @@ static int _is_global(uid_t uid) static int _initdb_load_directory(uid_t uid, const char *directory) { DIR *dir; - struct dirent file_info, *result; - int ret; + struct dirent file_info; + struct dirent *result; char buf[BUFSZE]; + pid_t pid; + int status; dir = opendir(directory); if (!dir) { @@ -77,16 +79,17 @@ static int _initdb_load_directory(uid_t uid, const char *directory) _D("Loading manifest files from %s", directory); - for (ret = readdir_r(dir, &file_info, &result); - ret == 0 && result != NULL; - ret = readdir_r(dir, &file_info, &result)) { - if (file_info.d_name[0] == '.') + while (readdir_r(dir, &file_info, &result) == 0) { + if (result == NULL) + break; + if (file_info.d_type != DT_REG) continue; - snprintf(buf, sizeof(buf), "%s/%s", directory, file_info.d_name); + snprintf(buf, sizeof(buf), "%s/%s", directory, + file_info.d_name); _D("manifest file %s", buf); - pid_t pid = fork(); + pid = fork(); if (pid == 0) { if (setuid(uid) != 0) { _E("failed to set uid"); @@ -94,17 +97,17 @@ static int _initdb_load_directory(uid_t uid, const char *directory) return -1; } - execl(PKGINSTALLMANIFEST_CMD, PKGINSTALLMANIFEST_CMD, "-x", buf, - (char *)NULL); - _E("failed to execute: %s", strerror_r(errno, buf, sizeof(buf))); + execl(PKGINSTALLMANIFEST_CMD, PKGINSTALLMANIFEST_CMD, + "-x", buf, (char *)NULL); + _E("failed to execute: %s", + strerror_r(errno, buf, sizeof(buf))); exit(EXIT_FAILURE); } else if (pid < 0) { - _E("failed to fork and execute %s!", PKGINSTALLMANIFEST_CMD); + _E("failed to fork and execute %s!", + PKGINSTALLMANIFEST_CMD); closedir(dir); return -1; - } - if (pid > 0) { - int status = 0; + } else { waitpid(pid, &status, 0); } } -- 2.7.4 From b1291f59ffb6cbde45795a2a73332fceed54bf60 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Wed, 23 Mar 2016 16:35:19 +0900 Subject: [PATCH 13/16] add watchapp for pkginfo Change-Id: Ic93ea2d96f8477d205bf1b83669b202ff79c0cbb Signed-off-by: jongmyeongko --- src/pkg_info.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/pkg_info.c b/src/pkg_info.c index 9b84209..b8ec796 100644 --- a/src/pkg_info.c +++ b/src/pkg_info.c @@ -1410,9 +1410,11 @@ int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data) if (apptype) printf("Apptype: %s\n", apptype); - if (component == PMINFO_UI_APP || component == PMINFO_WIDGET_APP) { - printf("component: %s\n", component == PMINFO_UI_APP ? "uiapp" : - "widgetapp"); + if (component == PMINFO_UI_APP || component == PMINFO_WIDGET_APP || + component == PMINFO_WATCH_APP) { + printf("component: %s\n", component == PMINFO_UI_APP ? + "uiapp" : component == PMINFO_WIDGET_APP ? + "widgetapp" : "watchapp"); ret = pkgmgrinfo_appinfo_is_multiple(handle, &multiple); if (ret < 0) printf("Failed to get multiple\n"); @@ -1839,15 +1841,15 @@ static int __get_app_info(char *appid) if (apptype) printf("Apptype: %s\n", apptype); - if (component == PMINFO_UI_APP || component == PMINFO_WIDGET_APP) { - printf("component: %s\n", component == PMINFO_UI_APP ? "uiapp" : - "widgetapp"); - + if (component == PMINFO_UI_APP || component == PMINFO_WIDGET_APP || + component == PMINFO_WATCH_APP) { + printf("component: %s\n", component == PMINFO_UI_APP ? + "uiapp" : component == PMINFO_WIDGET_APP ? + "widgetapp": "watchapp"); if (icon) printf("Icon: %s\n", icon); if (label) printf("Label: %s\n", label); - printf("Nodisplay: %d\n", nodisplay); printf("Multiple: %d\n", multiple); printf("Taskmanage: %d\n", taskmanage); -- 2.7.4 From 7605ab2b88b5402ead3111c7b31e69bebf0cbef0 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Fri, 25 Mar 2016 18:19:43 +0900 Subject: [PATCH 14/16] change functions for thread-safe Change-Id: I3838b267dda0cbbc82a444a389255412ddaf89b3 Signed-off-by: Junghyun Yeon --- src/pkg_clearcache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pkg_clearcache.c b/src/pkg_clearcache.c index 07250d2..c6ff634 100644 --- a/src/pkg_clearcache.c +++ b/src/pkg_clearcache.c @@ -84,7 +84,7 @@ static int __clear_dir(const char *dirname) if (ret != 0) LOGE("Couldn't remove the directory. " "errno : %d (%s)\n", - errno, strerror(errno)); + errno, strerror_r(errno, buf, sizeof(buf))); ret = remove(abs_filename); if (ret != 0) { @@ -99,7 +99,7 @@ static int __clear_dir(const char *dirname) if (ret != 0) { LOGE("Couldn't remove the directory. errno : " "%d (%s)\n", errno, - strerror(errno)); + strerror_r(errno, buf, sizeof(buf))); goto err; } } -- 2.7.4 From 47e9e2737133a1abd62efbf0275672411318cc3a Mon Sep 17 00:00:00 2001 From: Myungki Lee Date: Mon, 28 Mar 2016 14:04:34 +0900 Subject: [PATCH 15/16] Use thread-safe function Change-Id: If3d7bbff9d3e5e6466851a473300a6205d51ff65 Signed-off-by: Myungki Lee --- src/pkg_clearcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg_clearcache.c b/src/pkg_clearcache.c index c6ff634..ba7f110 100644 --- a/src/pkg_clearcache.c +++ b/src/pkg_clearcache.c @@ -90,7 +90,7 @@ static int __clear_dir(const char *dirname) if (ret != 0) { LOGE("Couldn't remove the directory. " "errno : %d (%s)\n", - errno, strerror(errno)); + errno, strerror_r(errno, buf, sizeof(buf))); goto err; } } -- 2.7.4 From 1b5fa04f5f1f6fcbae684d277dc878ed97b151f8 Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Thu, 24 Mar 2016 11:52:10 +0100 Subject: [PATCH 16/16] Modify scripts to create proper delta package for wgt-backend Always add "config.xml" and "tizen-manifest.xml" file to delta package. Change-Id: Iae8f1fa193334de8993fdf6fce3da1b7422994b6 --- CMakeLists.txt | 4 +- data/pkgmgr-create-delta.sh.in | 159 ++++++++++++++++++++++++----------------- data/pkgmgr-unzip-pkg.sh.in | 78 ++++++++++++++++++++ data/pkgmgr-unzip-tpk.sh.in | 78 -------------------- packaging/pkgmgr-tool.spec | 2 +- src/delta.c | 6 ++ src/pkg_cmd.c | 26 +++---- 7 files changed, 192 insertions(+), 161 deletions(-) create mode 100644 data/pkgmgr-unzip-pkg.sh.in delete mode 100644 data/pkgmgr-unzip-tpk.sh.in diff --git a/CMakeLists.txt b/CMakeLists.txt index bb688e6..4661309 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,7 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/mime.tpk.xml DESTINATION /usr/sha CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/pkgmgr.patch.sh.in pkgmgr.patch.sh @ONLY) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgmgr.patch.sh DESTINATION ${SYSCONF_INSTALL_DIR}/opt/upgrade/) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/pkgmgr-unzip-tpk.sh.in pkgmgr-unzip-tpk.sh @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgmgr-unzip-tpk.sh DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/pkgmgr-unzip-pkg.sh.in pkgmgr-unzip-pkg.sh @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgmgr-unzip-pkg.sh DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/data/pkgmgr-create-delta.sh.in pkgmgr-create-delta.sh @ONLY) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgmgr-create-delta.sh DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/) diff --git a/data/pkgmgr-create-delta.sh.in b/data/pkgmgr-create-delta.sh.in index 747ddc0..b22963e 100644 --- a/data/pkgmgr-create-delta.sh.in +++ b/data/pkgmgr-create-delta.sh.in @@ -4,22 +4,22 @@ usage() cat < - -b|--new_tpk= - -p|--delta_tpk= + -a|--old_pkg= + -b|--new_pkg= + -p|--delta_pkg= [-o|--option=