2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file process_pool_launchpad_util.h
18 * @author Tae-Jeong Lee (taejeong.lee@samsung.com)
20 * @brief Api library to support launchpad operation.
23 #ifndef __PROCESS_POOL_LAUNCHPAD_UTIL_H_
24 #define __PROCESS_POOL_LAUNCHPAD_UTIL_H_
27 #include <launchpad_util.h>
28 #include <smack_labeling_support.h>
29 #include <execute_on_whole_thread_util.h>
32 _static_ int __process_pool_prepare_exec(const char *pkg_name, const char *app_path, app_info_from_db * menu_info, bundle * kb);
33 _static_ void process_pool_launchpad_main_loop(app_pkt_t* pkt, char* out_app_path, int* out_argc, char ***out_argv);
36 _static_ int __process_pool_prepare_exec(const char *pkg_name,
37 const char *app_path, app_info_from_db * menu_info,
40 const char *file_name;
41 char process_name[WRT_AUL_PR_NAME];
44 char pkg_id[PKG_ID_LENGTH];
45 memset(pkg_id, '\0', PKG_ID_LENGTH);
46 snprintf(pkg_id, PKG_ID_LENGTH, "%s", pkg_name);
48 if (set_app_smack_label(app_path) != 0)
50 WrtLogE("set_app_smack_label() failed");
53 if (AccessControl::setPriviledge(pkg_id, menu_info->pkg_type, app_path) < 0) {
54 WrtLogD("fail to set privileges - check your package's credential\n");
58 /* SET INHERIT BIT FOR CAP_MAC_ADMIN TO WHOLE THREAD */
59 EXECUTE_ON_WHOLE_THREAD(__set_inherit_bit_for_CAP_MAC_ADMIN, SIGUSR1);
62 if (app_path == NULL) {
63 WrtLogD("app_path should not be NULL - check menu db");
66 file_name = strrchr(app_path, '/');
67 if (file_name == NULL) {
68 WrtLogD("can't locate file name to execute");
72 memset(process_name, '\0', WRT_AUL_PR_NAME);
73 snprintf(process_name, WRT_AUL_PR_NAME, "%s", file_name + 1);
74 prctl(PR_SET_NAME, process_name);
77 __set_env(menu_info, kb);
83 static bundle *_s_bundle = NULL;
84 static void __at_exit_to_release_bundle()
87 bundle_free(_s_bundle);
92 _static_ void process_pool_launchpad_main_loop(app_pkt_t* pkt, char* out_app_path, int* out_argc, char ***out_argv)
96 app_info_from_db *menu_info = NULL;
98 const char *pkg_name = NULL;
99 const char *app_path = NULL;
101 kb = bundle_decode(pkt->data, pkt->len);
103 WrtLogE("bundle decode error");
107 if (_s_bundle != NULL) {
108 bundle_free(_s_bundle);
111 atexit(__at_exit_to_release_bundle);
113 pkg_name = bundle_get_val(kb, AUL_K_PKG_NAME);
114 SECURE_LOGD("pkg name : %s", pkg_name);
116 menu_info = _get_app_info_from_bundle_by_pkgname(pkg_name, kb);
117 if (menu_info == NULL) {
118 WrtLogD("such pkg no found");
122 app_path = _get_app_path(menu_info);
124 if (app_path == NULL) {
125 WrtLogE("app_path is NULL");
129 if (app_path[0] != '/') {
130 WrtLogE("app_path is not absolute path");
134 __modify_bundle(kb, /*cr.pid - unused parameter*/ 0, menu_info, pkt->cmd);
135 pkg_name = _get_pkgname(menu_info);
136 SECURE_LOGD("pkg name : %s", pkg_name);
138 __process_pool_prepare_exec(pkg_name, app_path, menu_info, kb);
140 if (out_app_path != NULL && out_argc != NULL && out_argv != NULL)
144 sprintf(out_app_path, "%s", app_path);
146 *out_argv = __create_argc_argv(kb, out_argc);
147 (*out_argv)[0] = out_app_path;
149 for (i = 0; i < *out_argc; i++)
151 WrtLogD("input argument %d : %s##", i, (*out_argv)[i]);
159 if (menu_info != NULL) {
160 _free_app_info_from_db(menu_info);
164 #endif // __PROCESS_POOL_LAUNCHPAD_UTIL_H_