Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Tarassov2012-03-20 16:42:07 +0000
committerEugene Tarassov2012-03-20 16:42:07 +0000
commit2b11b7d5e7e3a277223f01de3137e5bcca087cde (patch)
tree55abffe6afba6ac638e22631bd80a0ddc12ce411
parent7388b7f00d18ed51d070d48ec8e500b657467ed1 (diff)
downloadorg.eclipse.tcf.agent-2b11b7d5e7e3a277223f01de3137e5bcca087cde.tar.gz
org.eclipse.tcf.agent-2b11b7d5e7e3a277223f01de3137e5bcca087cde.tar.xz
org.eclipse.tcf.agent-2b11b7d5e7e3a277223f01de3137e5bcca087cde.zip
TCF Agent: starting of test process changed to use execl() - works better with valgrind
-rw-r--r--agent/tcf/main/test.c29
-rw-r--r--agent/tcf/services/processes.c9
2 files changed, 24 insertions, 14 deletions
diff --git a/agent/tcf/main/test.c b/agent/tcf/main/test.c
index 7b2f12f6..5086c306 100644
--- a/agent/tcf/main/test.c
+++ b/agent/tcf/main/test.c
@@ -17,6 +17,10 @@
* Agent self-testing service.
*/
+#if defined(__GNUC__) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+#endif
+
#include <tcf/config.h>
#if ENABLE_RCBP_TEST
@@ -284,17 +288,28 @@ int run_test_process(ContextAttachCallBack * done, void * data) {
assert(taskIsStopped(tid));
return context_attach(tid, done, data, 0);
#else
- /* Create child process to debug */
int pid = fork();
if (pid < 0) return -1;
if (pid == 0) {
- int fd;
+ int fd = sysconf(_SC_OPEN_MAX);
+ while (fd > 3) close(--fd);
if (context_attach_self() < 0) exit(1);
- fd = sysconf(_SC_OPEN_MAX);
- while (fd-- > 2) close(fd);
- if (tkill(getpid(), SIGSTOP) < 0) exit(1);
- test_proc();
- exit(0);
+#if defined(__linux__)
+ {
+ char buf[32];
+ char * fnm = NULL;
+ snprintf(buf, sizeof(buf), "/proc/%d/exe", getpid());
+ fnm = canonicalize_file_name(buf);
+ if (fnm != NULL) execl(fnm, fnm, "-t", (char *)NULL);
+ exit(1);
+ }
+#else
+ {
+ if (tkill(getpid(), SIGSTOP) < 0) exit(1);
+ test_proc();
+ exit(0);
+ }
+#endif
}
return context_attach(pid, done, data, CONTEXT_ATTACH_SELF);
#endif
diff --git a/agent/tcf/services/processes.c b/agent/tcf/services/processes.c
index 73815213..5c9ae931 100644
--- a/agent/tcf/services/processes.c
+++ b/agent/tcf/services/processes.c
@@ -1226,16 +1226,11 @@ static int start_process_imp(Channel * c, char ** envp, const char * dir, const
int fd = -1;
int err = 0;
- if (err == 0) {
- fd = sysconf(_SC_OPEN_MAX);
- if (fd < 0) err = errno;
- }
+ if (!err && (fd = sysconf(_SC_OPEN_MAX)) < 0) err = errno;
if (!err && dup2(p_inp[0], 0) < 0) err = errno;
if (!err && dup2(p_out[1], 1) < 0) err = errno;
if (!err && dup2(p_err[1], 2) < 0) err = errno;
- if (!err) {
- while (fd > 3) close(--fd);
- }
+ while (!err && fd > 3) close(--fd);
if (!err && params->attach && context_attach_self() < 0) err = errno;
if (!err && params->dir != NULL && chdir(params->dir) < 0) err = errno;
if (!err) {

Back to the top