2 * Copyright 2013 Samsung Electronics Co., Ltd
5 * Contact: Minsu Seo <minsu15.seo@samsung.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
23 #include <pkgmgr-info.h>
24 #include <pkgmgr_installer_info.h>
29 #include <sys/types.h>
31 #include <sys/xattr.h>
34 #define WORKER "/etc/package-manager/parserlib/worker.sh"
36 #define TZDATA_UPDATE_PARSER_TAG "TZDATA_UPDATE_PARSER"
38 #define DEBUG_LOG(frmt, args...) \
40 SLOG(LOG_DEBUG, TZDATA_UPDATE_PARSER_TAG, \
41 "[tzdata_update_parser] %s: " frmt "\n", __func__, ##args); \
44 #define DEBUG_WARNING(frmt, args...) \
46 SLOG(LOG_WARN, TZDATA_UPDATE_PARSER_TAG, \
47 "[tzdata_update_parser] %s: " frmt "\n", __func__, ##args); \
50 #define DEBUG_ERROR(frmt, args...) \
52 SLOG(LOG_ERROR, TZDATA_UPDATE_PARSER_TAG, \
53 "[tzdata_update_parser] %s: " frmt "\n", __func__, ##args); \
58 SLOG(LOG_DEBUG, TZDATA_UPDATE_PARSER_TAG, \
59 "[ENTER tzdata_update_parser] %s\n", __func__); \
64 SLOG(LOG_DEBUG, TZDATA_UPDATE_PARSER_TAG, \
65 "[LEAVE tzdata_update_parser] %s\n", __func__); \
68 static void alt_system() {
72 // char *const args[2] = {"/home/mjpark", NULL};
74 // extern char **environ;
75 /* ... Sanitize arguments ... */
79 } else if (pid != 0) {
80 while ((ret = waitpid(pid, &status, 0)) == -1) {
86 if ((ret != -1) && (!WIFEXITED(status) || !WEXITSTATUS(status))) {
87 /* Report unexpected child status */
89 DEBUG_LOG(" ----> parent ? : %d ", ret);
91 /* ... Initialize env as a sanitized copy of environ ... */
92 // ret = execl("/home/mjpark/cprog/dir_copy/work.sh", "work.sh", (char *)0);
93 // if (execve("/bin/ls", args, env) == -1) {
94 // ret = execl("/bin/ls", "-1", (char *)0);
95 DEBUG_LOG(" ------------> run execl: %s ", WORKER);
96 ret = execl("/bin/bash", "bash", "-c", WORKER, (char *)NULL);
99 DEBUG_LOG("error occured : %s", WORKER);
100 printf("error occured\n");
103 DEBUG_LOG("run OK !!!!!!!!!!!!!!!!!!!!!!!!!!!!");
108 static int _get_pkgmgrinfo_handle(const char *pkgid,
109 pkgmgrinfo_pkginfo_h handle) {
113 pkgmgr_installer_info_get_target_uid(&uid);
114 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
117 DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
123 static int _pkgmgr_plugin_install(const char *pkgid, const char *appid,
124 GList *list, int upgrade_flag) {
127 pkgmgrinfo_pkginfo_h handle = NULL;
128 const char *app_root_path = NULL;
129 // const char* dest_path = NULL;
132 if (_get_pkgmgrinfo_handle(pkgid, handle) < 0) return -1;
134 ret = pkgmgrinfo_pkginfo_get_root_path(handle, (char **)&app_root_path);
136 DEBUG_ERROR("pkgid[%s] path get fail", pkgid);
141 DEBUG_ERROR("appid is NULL \n");
145 if (upgrade_flag == 1) {
146 DEBUG_LOG("-----------------------------------------------------");
147 DEBUG_LOG("pkgid : %s ", pkgid);
148 DEBUG_LOG("APP root path : %s ", app_root_path);
149 DEBUG_LOG("-----------------------------------------------------");
152 DEBUG_LOG("-----------------------------------------------------");
155 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
160 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
165 // DEBUG_ERROR("srcdir length is not available \n");
166 // DEBUG_LOG("srcdir =%s\n",(char *) srcdir);
167 int COMMON_PKGMGR_PLUGIN_INSTALL(const char *pkgid, const char *appid,
169 return _pkgmgr_plugin_install(pkgid, appid, list, 0);
172 int COMMON_PKGMGR_PLUGIN_UPGRADE(const char *pkgid, const char *appid,
174 return _pkgmgr_plugin_install(pkgid, appid, list, 1);
177 int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid,
180 pkgmgrinfo_pkginfo_h handle = NULL;
181 const char *app_root_path = NULL;
182 // const char *dest_path = NULL;
187 DEBUG_ERROR("appid is NULL \n");
191 if (_get_pkgmgrinfo_handle(pkgid, handle) < 0) return -1;
193 ret = pkgmgrinfo_pkginfo_get_root_path(handle, (char **)&app_root_path);
195 DEBUG_ERROR("pkgid[%s] path get fail", pkgid);
199 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
204 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
210 int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid,
213 return COMMON_PKGMGR_PLUGIN_INSTALL(pkgid, appid, list);
216 int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid,
219 return COMMON_PKGMGR_PLUGIN_UPGRADE(pkgid, appid, list);
222 int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid,
225 return COMMON_PKGMGR_PLUGIN_UNINSTALL(pkgid, appid, list);
229 int PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid,
232 return COMMON_PKGMGR_PLUGIN_INSTALL(pkgid, appid, list);
235 int PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid,
238 return COMMON_PKGMGR_PLUGIN_UPGRADE(pkgid, appid, list);
241 int PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL(const char *pkgid,
242 const char *appid, GList *list) {
244 return COMMON_PKGMGR_PLUGIN_UNINSTALL(pkgid, appid, list);