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);
54 preexec_initialized = 0;
58 static inline void __preexec_init(int argc, char **argv)
63 char line[MAX_LOCAL_BUFSZ];
67 int (*func) (char *, char *) = NULL;
68 preexec_list_t *type_t = NULL;
70 preexec_file = fopen(PREEXEC_FILE, "rt");
71 if (preexec_file == NULL) {
76 _D("preexec start\n");
78 while (fgets(line, MAX_LOCAL_BUFSZ, preexec_file) > 0) {
80 if (line[0] == '#' || line[0] == '\0')
83 type = strtok_r(line, ":\f\n\r\t\v ", &saveptr);
86 sopath = strtok_r(NULL, ",\f\n\r\t\v ", &saveptr);
89 symbol = strtok_r(NULL, ",\f\n\r\t\v ", &saveptr);
93 type_t = (preexec_list_t *) calloc(1, sizeof(preexec_list_t));
95 _E("no available memory\n");
96 __preexec_list_free();
101 handle = dlopen(sopath, RTLD_NOW);
102 if (handle == NULL) {
106 _D("preexec %s %s# - handle : %x\n", type, sopath, handle);
108 func = dlsym(handle, symbol);
110 _E("failed to get symbol type:%s path:%s\n",
118 type_t->pkg_type = strdup(type);
119 if (type_t->pkg_type == NULL) {
120 _E("no available memory\n");
122 __preexec_list_free();
123 fclose(preexec_file);
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();
132 fclose(preexec_file);
135 type_t->dl_do_pre_exe = func;
137 preexec_list = g_slist_append(preexec_list, (void *)type_t);
140 fclose(preexec_file);
141 preexec_initialized = 1;
144 static inline void __preexec_run(const char *pkg_type, const char *pkg_name,
145 const char *app_path)
148 preexec_list_t *type_t;
150 if (!preexec_initialized)
153 for (iter = preexec_list; iter != NULL; iter = g_slist_next(iter)) {
156 if (!strcmp(pkg_type, type_t->pkg_type)) {
157 if (type_t->dl_do_pre_exe != NULL) {
158 type_t->dl_do_pre_exe((char *)pkg_name,
160 _D("called dl_do_pre_exe() type: %s",
163 _E("no symbol for this type: %s",
174 static void __preexec_list_free()
178 static inline void __preexec_init(int argc, char **argv)
182 static inline void __preexec_run(const char *pkg_type, const char *pkg_name,
183 const char *app_path)