From 4ae43fb42219cf2c2b8e9f1832d6f24aaebc4936 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 12 Nov 2012 09:23:39 +0000 Subject: [PATCH] check for sys/ptrace.h and only use ptrace() in e_start_main.c if it's present ticket #1757 (3/3) SVN revision: 79139 --- configure.ac | 2 +- src/bin/e_start_main.c | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index ef6ffa2ad..a3131bcd1 100644 --- a/configure.ac +++ b/configure.ac @@ -76,7 +76,7 @@ AC_CHECK_FUNCS(unsetenv) efl_version="1.7.0" -AC_CHECK_HEADERS([sys/timerfd.h]) +AC_CHECK_HEADERS([sys/timerfd.h sys/ptrace.h]) dnl AC_CHECK_HEADERS(X11/extensions/shape.h,, AC_MSG_ERROR([Cannot find X11/extensions/shape.h. Make sure your CFLAGS environment variable contains include lines for the location of this file])) diff --git a/src/bin/e_start_main.c b/src/bin/e_start_main.c index d9953888a..d995363ab 100644 --- a/src/bin/e_start_main.c +++ b/src/bin/e_start_main.c @@ -8,7 +8,9 @@ #include #include #include -#include +#ifdef HAVE_SYS_PTRACE_H +# include +#endif #include #include #ifdef HAVE_ALLOCA_H @@ -414,9 +416,10 @@ main(int argc, char **argv) return -1; else if (child == 0) { +#ifdef HAVE_SYS_PTRACE_H /* in the child */ ptrace(PT_TRACE_ME, 0, NULL, NULL); - +#endif execv(args[0], args); return 0; /* We failed, 0 mean normal exit from E with no restart or crash so let exit */ } @@ -426,17 +429,17 @@ main(int argc, char **argv) pid_t result; int status; Eina_Bool done = EINA_FALSE; - +#ifdef HAVE_SYS_PTRACE_H ptrace(PT_ATTACH, child, NULL, NULL); - +#endif result = waitpid(child, &status, 0); - +#ifdef HAVE_SYS_PTRACE_H if (!stop_ptrace) { if (WIFSTOPPED(status)) ptrace(PT_CONTINUE, child, NULL, NULL); } - +#endif while (!done) { Eina_Bool remember_sigill = EINA_FALSE; @@ -451,10 +454,12 @@ main(int argc, char **argv) char buffer[4096]; char *backtrace_str = NULL; siginfo_t sig; - int r; + int r = 0; int back; +#ifdef HAVE_SYS_PTRACE_H r = ptrace(PTRACE_GETSIGINFO, child, NULL, &sig); +#endif back = r == 0 && sig.si_signo != SIGTRAP ? sig.si_signo : 0; @@ -478,13 +483,15 @@ main(int argc, char **argv) sig.si_signo != SIGBUS && sig.si_signo != SIGABRT)) { +#ifdef HAVE_SYS_PTRACE_H ptrace(PT_CONTINUE, child, NULL, back); +#endif continue ; } - +#ifdef HAVE_SYS_PTRACE_H /* E17 should be in pause, we can detach */ ptrace(PT_DETACH, child, NULL, back); - +#endif /* And call gdb if available */ if (home) { @@ -545,7 +552,9 @@ main(int argc, char **argv) { kill(child, SIGSTOP); usleep(200000); +#ifdef HAVE_SYS_PTRACE_H ptrace(PT_DETACH, child, NULL, NULL); +#endif } } }