2 * Copyright (c) 2011 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 #ifdef PREEXEC_ACTIVATE
21 #define PREEXEC_FILE SHARE_PREFIX "/preexec_list.txt"
23 static int preexec_initialized = 0;
25 GSList *preexec_list = NULL;
27 typedef struct _preexec_list_t {
30 int (*dl_do_pre_exe)(char *, char *);
33 static void __preexec_list_free()
36 preexec_list_t *type_t;
38 for (iter = preexec_list; iter != NULL; iter = g_slist_next(iter)) {
41 if (type_t->pkg_type) {
42 free(type_t->pkg_type);
44 if (type_t->so_path) {
45 free(type_t->so_path);
50 g_slist_free(preexec_list);
54 static inline void __preexec_init(int argc, char **argv)
59 char line[MAX_LOCAL_BUFSZ] = { 0, };
63 int (*func)(char *, char *) = NULL;
64 preexec_list_t *type_t = NULL;
66 // warning: unused parameter
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) > (char*)0) {
80 if (line[0] == '#' || line[0] == '\0') {
84 type = strtok_r(line, ":\f\n\r\t\v ", &saveptr);
88 sopath = strtok_r(NULL, ",\f\n\r\t\v ", &saveptr);
92 symbol = strtok_r(NULL, ",\f\n\r\t\v ", &saveptr);
97 type_t = (preexec_list_t *) calloc(1, sizeof(preexec_list_t));
99 _E("no available memory\n");
100 __preexec_list_free();
101 fclose(preexec_file);
105 handle = dlopen(sopath, RTLD_NOW);
106 if (handle == NULL) {
110 _D("preexec %s %s# - handle : %x\n", type, sopath, handle);
112 func = dlsym(handle, symbol);
114 _E("failed to get symbol type:%s path:%s\n",
122 type_t->pkg_type = strdup(type);
123 if (type_t->pkg_type == NULL) {
124 _E("no available memory\n");
126 __preexec_list_free();
127 fclose(preexec_file);
130 type_t->so_path = strdup(sopath);
131 if (type_t->so_path == NULL) {
132 _E("no available memory\n");
133 free(type_t->pkg_type);
135 __preexec_list_free();
136 fclose(preexec_file);
139 type_t->dl_do_pre_exe = func;
141 preexec_list = g_slist_append(preexec_list, (void *)type_t);
144 fclose(preexec_file);
145 preexec_initialized = 1;
148 static inline void __preexec_run(const char *pkg_type, const char *pkg_name,
149 const char *app_path)
152 preexec_list_t *type_t;
154 if (!preexec_initialized) {
158 for (iter = preexec_list; iter != NULL; iter = g_slist_next(iter)) {
161 if (!strcmp(pkg_type, type_t->pkg_type)) {
162 if (type_t->dl_do_pre_exe != NULL) {
163 type_t->dl_do_pre_exe((char *)pkg_name,
165 _D("called dl_do_pre_exe() type: %s",
168 _E("no symbol for this type: %s",
178 static inline void __preexec_init(int argc, char **argv)
181 static inline void __preexec_run(const char *pkg_type, const char *pkg_name,
182 const char *app_path)