4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #ifdef PREEXEC_ACTIVATE
26 #define PREEXEC_FILE SHARE_PREFIX"/preexec_list.txt"
28 static int preexec_initialized = 0;
30 GSList *preexec_list = NULL;
32 typedef struct _preexec_list_t {
35 int (*dl_do_pre_exe) (char *, char *);
38 static void __preexec_list_free()
41 preexec_list_t *type_t;
43 for (iter = preexec_list; iter != NULL; iter = g_slist_next(iter)) {
47 free(type_t->pkg_type);
49 free(type_t->so_path);
53 g_slist_free(preexec_list);
57 static inline void __preexec_init(int argc, char **argv)
62 char line[MAX_LOCAL_BUFSZ];
66 int (*func) (char *, char *) = NULL;
67 preexec_list_t *type_t = NULL;
69 // warning: unused parameter
73 preexec_file = fopen(PREEXEC_FILE, "rt");
74 if (preexec_file == NULL) {
79 _D("preexec start\n");
81 while (fgets(line, MAX_LOCAL_BUFSZ, preexec_file) > (char*)0) {
83 if (line[0] == '#' || line[0] == '\0')
86 type = strtok_r(line, ":\f\n\r\t\v ", &saveptr);
89 sopath = strtok_r(NULL, ",\f\n\r\t\v ", &saveptr);
92 symbol = strtok_r(NULL, ",\f\n\r\t\v ", &saveptr);
96 type_t = (preexec_list_t *) calloc(1, sizeof(preexec_list_t));
98 _E("no available memory\n");
99 __preexec_list_free();
103 handle = dlopen(sopath, RTLD_NOW);
104 if (handle == NULL) {
108 _D("preexec %s %s# - handle : %x\n", type, sopath, handle);
110 func = dlsym(handle, symbol);
112 _E("failed to get symbol type:%s path:%s\n",
119 type_t->pkg_type = strdup(type);
120 if (type_t->pkg_type == NULL) {
121 _E("no available memory\n");
123 __preexec_list_free();
126 type_t->so_path = strdup(sopath);
127 if (type_t->so_path == NULL) {
128 _E("no available memory\n");
129 free(type_t->pkg_type);
131 __preexec_list_free();
134 type_t->dl_do_pre_exe = func;
136 preexec_list = g_slist_append(preexec_list, (void *)type_t);
139 fclose(preexec_file);
140 preexec_initialized = 1;
143 static inline void __preexec_run(const char *pkg_type, const char *pkg_name,
144 const char *app_path)
147 preexec_list_t *type_t;
149 if (!preexec_initialized)
152 for (iter = preexec_list; iter != NULL; iter = g_slist_next(iter)) {
155 if (!strcmp(pkg_type, type_t->pkg_type)) {
156 if (type_t->dl_do_pre_exe != NULL) {
157 type_t->dl_do_pre_exe((char *)pkg_name,
159 _D("called dl_do_pre_exe() type: %s",
162 _E("no symbol for this type: %s",
173 static inline void __preexec_init(int argc, char **argv)
177 static inline void __preexec_run(const char *pkg_type, const char *pkg_name,
178 const char *app_path)