4 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
8 * Vitaliy Cherepanov <v.cherepanov@samsung.com>
10 * This library is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU Lesser General Public License as published by the
12 * Free Software Foundation; either version 2.1 of the License, or (at your option)
15 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
16 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software Foundation, Inc., 51
22 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 * - Samsung RnD Institute Russia
28 #include <sys/types.h>
34 #include "daforkexec.h"
36 DECLARE(int, execl , const char *path, const char *arg, ...);
37 DECLARE(int, execlp, const char *file, const char *arg, ...);
38 DECLARE(int, execle, const char *path, const char *arg, ...);//, char * const envp[]);
39 DECLARE(int, execv, const char *path, char *const argv[]);
40 DECLARE(int, execve, const char *filename, char *const argv[],char *const envp[]);
41 DECLARE(int, execvp, const char *file, char *const argv[]);
42 DECLARE(int, execvpe, const char *file, char *const argv[],char *const envp[]);
43 DECLARE(pid_t, fork, void);
48 INIT_FUNC_EXEC(execl);
49 INIT_FUNC_EXEC(execlp);
50 INIT_FUNC_EXEC(execle);
51 INIT_FUNC_EXEC(execv);
52 INIT_FUNC_EXEC(execve);
53 INIT_FUNC_EXEC(execvp);
54 INIT_FUNC_EXEC(execvpe);
57 #define prepare_params( FUNCTION , p1, p2) \
62 INIT_FUNC_EXEC( FUNCTION ); \
67 while (va_arg(ap, char *)); \
69 args_count += 2 + 1; \
71 char *arg_arr[args_count]; \
75 arg_arr[0] = (char *)p1; \
76 arg_arr[1] = (char *)p2; \
77 for (i = 2; i < args_count; i++) \
78 arg_arr[i] = va_arg(ap, char *); \
82 int _da_call_original(void *funcp, char *args[], int args_count);
84 #define print_params(buf, p1, p2) \
88 p += sprintf(p, "--> %s ", __FUNCTION__); \
89 p += sprintf(p, "[%d]: <", getpid()); \
90 p += sprintf(p, " \"%s\",", p1); \
91 p += sprintf(p, " \"%s\",", p2); \
93 while ( (pp = va_arg(par, char *)) != NULL) \
94 p += sprintf(p, " \"%s\",", pp); \
98 int execl(const char *path, const char *arg, ...)
101 PRINTMSG("%s [%d] ", __FUNCTION__, getpid());
104 prepare_params(execl, path, arg);
105 res = _da_call_original(&execl_p, arg_arr, args_count);
108 PRINTWRN("%s(%s, ...) return %d", __FUNCTION__, res, path);
112 int execlp(const char *file, const char *arg, ...)
115 PRINTMSG("%s [%d] ", __FUNCTION__, getpid());
118 prepare_params(execlp, file, arg);
119 res = _da_call_original(&execlp_p, arg_arr, args_count);
122 PRINTWRN("%s(%s, ...) return %d", __FUNCTION__, file, res);
126 int execle(const char *path, const char *arg, ...
127 /* original func have one more argument but
128 * i can't leave it in code by compilation reasons
129 * so it is commented:
131 *,__attribute__((unused)) char * const envp[] */
135 PRINTMSG("%s [%d] ", __FUNCTION__, getpid());
138 prepare_params(execle, path, arg);
139 res = _da_call_original(&execle_p, arg_arr, args_count);
142 PRINTWRN("%s(%s, ...) return %d", __FUNCTION__, path, res);
146 int execv(const char *path, char *const argv[])
149 PRINTMSG("%s [%d] ", __FUNCTION__, getpid());
152 res = execv_p(path, argv);
155 PRINTWRN("%s(%s, ...) return %d", __FUNCTION__, path, res);
159 int execvp(const char *file, char *const argv[])
162 PRINTMSG("%s [%d] ", __FUNCTION__, getpid());
165 res = execvp_p(file, argv);
168 PRINTWRN("%s(%s, ...) return %d", __FUNCTION__, file, res);
172 int execve(const char *filename, char *const argv[],char *const envp[])
175 PRINTMSG("%s [%d] ", __FUNCTION__, getpid());
178 res = execve_p(filename, argv, envp);
181 PRINTWRN("%s(%s, ...) return %d", __FUNCTION__, filename, res);
185 int execvpe(const char *file, char *const argv[],char *const envp[])
188 PRINTMSG("%s [%d] ", __FUNCTION__, getpid());
191 res = execvpe_p(file, argv, envp);
194 PRINTWRN("%s(%s, ...) return %d", __FUNCTION__, file, res);
200 pid_t res = fork_p();
202 PRINTMSG("<fork = %d>", res);
204 reset_pid_tid(); /* important reset pid values */
205 if (gTraceInfo.socket.daemonSock >= 0) {
206 close(gTraceInfo.socket.daemonSock);