2006-10-20 22:57:27 -07:00
|
|
|
#include "config.h"
|
2006-03-04 22:23:14 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-10-23 06:49:06 -07:00
|
|
|
#include <dlfcn.h>
|
2006-10-22 03:03:59 -07:00
|
|
|
#include <sys/types.h>
|
2006-12-14 11:27:46 -08:00
|
|
|
#include <sys/wait.h>
|
2006-10-22 03:03:59 -07:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/utsname.h>
|
2012-11-12 01:23:39 -08:00
|
|
|
#ifdef HAVE_SYS_PTRACE_H
|
|
|
|
# include <sys/ptrace.h>
|
|
|
|
#endif
|
2009-07-11 09:27:37 -07:00
|
|
|
#include <limits.h>
|
2006-10-22 03:03:59 -07:00
|
|
|
#include <fcntl.h>
|
2006-10-20 22:57:27 -07:00
|
|
|
#ifdef HAVE_ALLOCA_H
|
2009-07-19 13:30:33 -07:00
|
|
|
# include <alloca.h>
|
2006-10-20 22:57:27 -07:00
|
|
|
#endif
|
2012-10-31 23:23:49 -07:00
|
|
|
#include <signal.h>
|
2012-12-04 18:23:00 -08:00
|
|
|
#include <errno.h>
|
2012-10-31 23:23:49 -07:00
|
|
|
|
2011-08-27 09:25:51 -07:00
|
|
|
#include <Eina.h>
|
2013-02-13 04:50:23 -08:00
|
|
|
#include <Evas.h>
|
2006-03-04 22:23:14 -08:00
|
|
|
|
2013-11-07 23:56:28 -08:00
|
|
|
#if (EVAS_VERSION_MAJOR > 1) || (EVAS_VERSION_MINOR >= 8)
|
|
|
|
# define E_CSERVE
|
|
|
|
#endif
|
|
|
|
|
2012-11-09 07:42:57 -08:00
|
|
|
static Eina_Bool stop_ptrace = EINA_FALSE;
|
2012-10-31 23:23:49 -07:00
|
|
|
|
2006-03-04 22:23:14 -08:00
|
|
|
static void env_set(const char *var, const char *val);
|
2012-10-10 00:31:26 -07:00
|
|
|
EAPI int prefix_determine(char *argv0);
|
2006-03-04 22:23:14 -08:00
|
|
|
|
|
|
|
static void
|
|
|
|
env_set(const char *var, const char *val)
|
|
|
|
{
|
|
|
|
if (val)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SETENV
|
2012-10-10 00:31:26 -07:00
|
|
|
setenv(var, val, 1);
|
2006-03-04 22:23:14 -08:00
|
|
|
#else
|
2012-10-10 00:31:26 -07:00
|
|
|
char *buf;
|
2012-03-28 00:26:22 -07:00
|
|
|
size_t size = strlen(var) + 1 + strlen(val) + 1;
|
2009-07-19 13:30:33 -07:00
|
|
|
|
2012-10-10 00:31:26 -07:00
|
|
|
buf = alloca(size);
|
2012-12-19 06:20:34 -08:00
|
|
|
sprintf(buf, "%s=%s", var, val);
|
2012-10-10 00:31:26 -07:00
|
|
|
if (getenv(var)) putenv(buf);
|
|
|
|
else putenv(strdup(buf));
|
2006-03-04 22:23:14 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef HAVE_UNSETENV
|
2012-10-10 00:31:26 -07:00
|
|
|
unsetenv(var);
|
2006-03-04 22:23:14 -08:00
|
|
|
#else
|
2012-10-10 00:31:26 -07:00
|
|
|
if (getenv(var)) putenv(var);
|
2006-03-04 22:23:14 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* local subsystem globals */
|
2011-08-27 09:25:51 -07:00
|
|
|
static Eina_Prefix *pfx = NULL;
|
2006-03-04 22:23:14 -08:00
|
|
|
|
|
|
|
/* externally accessible functions */
|
2011-08-27 09:25:51 -07:00
|
|
|
EAPI int
|
2006-03-04 22:23:14 -08:00
|
|
|
prefix_determine(char *argv0)
|
|
|
|
{
|
2011-08-27 09:25:51 -07:00
|
|
|
pfx = eina_prefix_new(argv0, prefix_determine,
|
|
|
|
"E", "enlightenment", "AUTHORS",
|
|
|
|
PACKAGE_BIN_DIR, PACKAGE_LIB_DIR,
|
|
|
|
PACKAGE_DATA_DIR, LOCALE_DIR);
|
|
|
|
if (!pfx) return 0;
|
2006-03-04 22:23:14 -08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-07-11 09:27:37 -07:00
|
|
|
static int
|
|
|
|
find_valgrind(char *path, size_t path_len)
|
|
|
|
{
|
2010-01-15 04:01:17 -08:00
|
|
|
const char *env = getenv("PATH");
|
2012-06-20 23:19:43 -07:00
|
|
|
|
2009-07-11 09:27:37 -07:00
|
|
|
while (env)
|
|
|
|
{
|
2012-10-10 00:31:26 -07:00
|
|
|
const char *p = strchr(env, ':');
|
|
|
|
ssize_t p_len;
|
|
|
|
|
|
|
|
if (p) p_len = p - env;
|
|
|
|
else p_len = strlen(env);
|
|
|
|
if (p_len <= 0) goto next;
|
|
|
|
else if (p_len + sizeof("/valgrind") >= path_len)
|
|
|
|
goto next;
|
|
|
|
memcpy(path, env, p_len);
|
|
|
|
memcpy(path + p_len, "/valgrind", sizeof("/valgrind"));
|
|
|
|
if (access(path, X_OK | R_OK) == 0) return 1;
|
2011-08-27 09:25:51 -07:00
|
|
|
next:
|
2012-10-10 00:31:26 -07:00
|
|
|
if (p) env = p + 1;
|
|
|
|
else break;
|
2009-07-11 09:27:37 -07:00
|
|
|
}
|
|
|
|
path[0] = '\0';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* maximum number of arguments added above */
|
2013-05-21 06:58:05 -07:00
|
|
|
#define VALGRIND_MAX_ARGS 11
|
2009-07-11 09:27:37 -07:00
|
|
|
/* bitmask with all supported bits set */
|
|
|
|
#define VALGRIND_MODE_ALL 15
|
|
|
|
|
|
|
|
static int
|
2012-07-15 20:19:37 -07:00
|
|
|
valgrind_append(char **dst, int valgrind_gdbserver, int valgrind_mode, int valgrind_tool, char *valgrind_path, const char *valgrind_log)
|
2009-07-11 09:27:37 -07:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
2010-03-30 08:13:45 -07:00
|
|
|
if (valgrind_tool)
|
|
|
|
{
|
2012-10-10 00:31:26 -07:00
|
|
|
dst[i++] = valgrind_path;
|
|
|
|
switch (valgrind_tool)
|
|
|
|
{
|
|
|
|
case 1: dst[i++] = "--tool=massif"; break;
|
|
|
|
|
|
|
|
case 2: dst[i++] = "--tool=callgrind"; break;
|
|
|
|
}
|
|
|
|
return i;
|
2010-03-30 08:13:45 -07:00
|
|
|
}
|
2012-07-15 20:19:37 -07:00
|
|
|
if (valgrind_gdbserver) dst[i++] = "--db-attach=yes";
|
2011-08-27 09:25:51 -07:00
|
|
|
if (!valgrind_mode) return 0;
|
2009-07-11 09:27:37 -07:00
|
|
|
dst[i++] = valgrind_path;
|
2013-05-21 06:58:05 -07:00
|
|
|
dst[i++] = "--num-callers=40";
|
2009-07-11 09:27:37 -07:00
|
|
|
dst[i++] = "--track-origins=yes";
|
2010-02-26 15:55:12 -08:00
|
|
|
dst[i++] = "--malloc-fill=13"; /* invalid pointer, make it crash */
|
2009-07-11 09:27:37 -07:00
|
|
|
if (valgrind_log)
|
|
|
|
{
|
2012-10-10 00:31:26 -07:00
|
|
|
static char logparam[PATH_MAX + sizeof("--log-file=")];
|
2012-06-20 23:19:43 -07:00
|
|
|
|
2012-10-10 00:31:26 -07:00
|
|
|
snprintf(logparam, sizeof(logparam), "--log-file=%s", valgrind_log);
|
|
|
|
dst[i++] = logparam;
|
2009-07-11 09:27:37 -07:00
|
|
|
}
|
2011-08-27 09:25:51 -07:00
|
|
|
if (valgrind_mode & 2) dst[i++] = "--trace-children=yes";
|
2009-07-11 09:27:37 -07:00
|
|
|
if (valgrind_mode & 4)
|
|
|
|
{
|
2012-10-10 00:31:26 -07:00
|
|
|
dst[i++] = "--leak-check=full";
|
|
|
|
dst[i++] = "--leak-resolution=high";
|
|
|
|
dst[i++] = "--track-fds=yes";
|
2009-07-11 09:27:37 -07:00
|
|
|
}
|
2011-08-27 09:25:51 -07:00
|
|
|
if (valgrind_mode & 8) dst[i++] = "--show-reachable=yes";
|
2009-07-11 09:27:37 -07:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-10-27 10:51:19 -07:00
|
|
|
copy_args(char **dst, char **src, size_t count)
|
2009-07-11 09:27:37 -07:00
|
|
|
{
|
2012-10-10 00:31:26 -07:00
|
|
|
for (; count > 0; count--, dst++, src++)
|
|
|
|
*dst = *src;
|
2009-07-11 09:27:37 -07:00
|
|
|
}
|
2006-10-22 03:03:59 -07:00
|
|
|
|
2012-09-10 02:34:01 -07:00
|
|
|
static void
|
|
|
|
_env_path_prepend(const char *env, const char *path)
|
|
|
|
{
|
2012-10-02 02:26:30 -07:00
|
|
|
char *p, *s;
|
|
|
|
const char *p2;
|
2012-09-10 02:34:01 -07:00
|
|
|
int len = 0, len2 = 0;
|
2012-10-02 02:26:30 -07:00
|
|
|
|
|
|
|
if (!path) return;
|
2012-10-10 00:31:26 -07:00
|
|
|
|
2012-09-10 02:34:01 -07:00
|
|
|
p = getenv(env);
|
2012-10-02 02:26:30 -07:00
|
|
|
p2 = path;
|
|
|
|
len2 = strlen(p2);
|
|
|
|
if (p)
|
2012-09-10 02:34:01 -07:00
|
|
|
{
|
2012-10-02 02:26:30 -07:00
|
|
|
len = strlen(p);
|
2012-09-10 02:34:01 -07:00
|
|
|
// path already there at the start. dont prepend. :)
|
|
|
|
if ((!strcmp(p, p2)) ||
|
|
|
|
((len > len2) &&
|
2012-10-10 00:31:26 -07:00
|
|
|
(!strncmp(p, p2, len2)) &&
|
|
|
|
(p[len2] == ':')))
|
2012-09-10 02:34:01 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
s = malloc(len + 1 + len2 + 1);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
s[0] = 0;
|
2012-10-02 02:26:30 -07:00
|
|
|
strcat(s, p2);
|
|
|
|
if (p)
|
2012-09-10 02:34:01 -07:00
|
|
|
{
|
|
|
|
strcat(s, ":");
|
2012-10-02 02:26:30 -07:00
|
|
|
strcat(s, p);
|
2012-09-10 02:34:01 -07:00
|
|
|
}
|
|
|
|
env_set(env, s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_env_path_append(const char *env, const char *path)
|
|
|
|
{
|
2012-10-02 02:26:30 -07:00
|
|
|
char *p, *s;
|
|
|
|
const char *p2;
|
2012-09-10 02:34:01 -07:00
|
|
|
int len = 0, len2 = 0;
|
2012-10-10 00:31:26 -07:00
|
|
|
|
2012-10-02 02:26:30 -07:00
|
|
|
if (!path) return;
|
2012-10-10 00:31:26 -07:00
|
|
|
|
2012-09-10 02:34:01 -07:00
|
|
|
p = getenv(env);
|
2012-10-02 02:26:30 -07:00
|
|
|
p2 = path;
|
|
|
|
len2 = strlen(p2);
|
|
|
|
if (p)
|
2012-09-10 02:34:01 -07:00
|
|
|
{
|
2012-10-02 02:26:30 -07:00
|
|
|
len = strlen(p);
|
2012-09-10 02:34:01 -07:00
|
|
|
// path already there at the end. dont append. :)
|
|
|
|
if ((!strcmp(p, p2)) ||
|
|
|
|
((len > len2) &&
|
2012-10-10 00:31:26 -07:00
|
|
|
(!strcmp((p + len - len2), p2)) &&
|
|
|
|
(p[len - len2 - 1] == ':')))
|
2012-09-10 02:34:01 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
s = malloc(len + 1 + len2 + 1);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
s[0] = 0;
|
2012-10-02 02:26:30 -07:00
|
|
|
if (p)
|
2012-09-10 02:34:01 -07:00
|
|
|
{
|
2012-10-02 02:26:30 -07:00
|
|
|
strcat(s, p);
|
2012-09-10 02:34:01 -07:00
|
|
|
strcat(s, ":");
|
|
|
|
}
|
2012-10-02 02:26:30 -07:00
|
|
|
strcat(s, p2);
|
2012-09-10 02:34:01 -07:00
|
|
|
env_set(env, s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-14 01:57:11 -08:00
|
|
|
static void
|
2012-11-09 06:49:05 -08:00
|
|
|
_sigusr1(int x __UNUSED__, siginfo_t *info __UNUSED__, void *data __UNUSED__)
|
|
|
|
{
|
2012-11-09 07:42:57 -08:00
|
|
|
struct sigaction action;
|
2012-11-14 01:57:11 -08:00
|
|
|
|
2012-11-09 06:49:05 -08:00
|
|
|
/* release ptrace */
|
2012-11-09 07:42:57 -08:00
|
|
|
stop_ptrace = EINA_TRUE;
|
2012-11-14 01:57:11 -08:00
|
|
|
|
2012-11-09 07:42:57 -08:00
|
|
|
action.sa_sigaction = _sigusr1;
|
|
|
|
action.sa_flags = SA_RESETHAND;
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
sigaction(SIGUSR1, &action, NULL);
|
2012-11-09 06:49:05 -08:00
|
|
|
}
|
|
|
|
|
2013-11-07 23:56:28 -08:00
|
|
|
#ifdef E_CSERVE
|
|
|
|
static pid_t
|
|
|
|
_cserve2_start()
|
|
|
|
{
|
|
|
|
pid_t cs_child;
|
|
|
|
cs_child = fork();
|
|
|
|
if (cs_child == 0)
|
|
|
|
{
|
|
|
|
char *cs_args[2] = { NULL, NULL };
|
|
|
|
|
|
|
|
cs_args[0] = (char *)evas_cserve_path_get();
|
|
|
|
execv(cs_args[0], cs_args);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
else if (cs_child > 0)
|
|
|
|
{
|
|
|
|
putenv("EVAS_CSERVE2=1");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsetenv("EVAS_CSERVE2");
|
|
|
|
}
|
|
|
|
return cs_child;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-03-04 22:23:14 -08:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2012-10-10 00:39:08 -07:00
|
|
|
int i, valgrind_mode = 0;
|
2010-03-30 08:13:45 -07:00
|
|
|
int valgrind_tool = 0;
|
2012-07-15 20:19:37 -07:00
|
|
|
int valgrind_gdbserver = 0;
|
2012-10-31 23:23:49 -07:00
|
|
|
char buf[16384], **args, *home;
|
2010-01-15 04:01:17 -08:00
|
|
|
char valgrind_path[PATH_MAX] = "";
|
|
|
|
const char *valgrind_log = NULL;
|
2012-09-10 02:34:01 -07:00
|
|
|
Eina_Bool really_know = EINA_FALSE;
|
2012-11-09 06:49:05 -08:00
|
|
|
struct sigaction action;
|
2013-02-15 00:18:09 -08:00
|
|
|
pid_t child = -1;
|
2013-11-07 23:56:28 -08:00
|
|
|
#ifdef E_CSERVE
|
2013-02-15 00:18:09 -08:00
|
|
|
pid_t cs_child = -1;
|
2013-11-07 23:56:28 -08:00
|
|
|
Eina_Bool cs_use = EINA_FALSE;
|
2013-02-15 00:18:09 -08:00
|
|
|
#endif
|
2012-11-13 02:54:35 -08:00
|
|
|
#if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__) && \
|
2013-08-24 06:52:27 -07:00
|
|
|
!defined(__FreeBSD_kernel__) && !(defined (__MACH__) && defined (__APPLE__))
|
2012-11-13 02:54:35 -08:00
|
|
|
Eina_Bool restart = EINA_TRUE;
|
|
|
|
#endif
|
|
|
|
|
2013-03-14 20:07:47 -07:00
|
|
|
unsetenv("NOTIFY_SOCKET");
|
|
|
|
|
2012-11-26 19:48:05 -08:00
|
|
|
/* Setup USR1 to detach from the child process and let it get gdb by advanced users */
|
2012-11-09 06:49:05 -08:00
|
|
|
action.sa_sigaction = _sigusr1;
|
2012-11-09 07:42:57 -08:00
|
|
|
action.sa_flags = SA_RESETHAND;
|
2012-11-09 06:49:05 -08:00
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
sigaction(SIGUSR1, &action, NULL);
|
2012-11-14 01:57:11 -08:00
|
|
|
|
2011-08-27 09:25:51 -07:00
|
|
|
eina_init();
|
2012-10-31 23:23:49 -07:00
|
|
|
|
|
|
|
/* reexcute myself with dbus-launch if dbus-launch is not running yet */
|
|
|
|
if ((!getenv("DBUS_SESSION_BUS_ADDRESS")) &&
|
2012-11-14 01:57:11 -08:00
|
|
|
(!getenv("DBUS_LAUNCHD_SESSION_BUS_SOCKET")))
|
2012-10-31 23:23:49 -07:00
|
|
|
{
|
|
|
|
char **dbus_argv;
|
|
|
|
|
2012-11-02 02:50:03 -07:00
|
|
|
dbus_argv = alloca((argc + 3) * sizeof (char *));
|
2012-10-31 23:23:49 -07:00
|
|
|
dbus_argv[0] = "dbus-launch";
|
|
|
|
dbus_argv[1] = "--exit-with-session";
|
|
|
|
copy_args(dbus_argv + 2, argv, argc);
|
|
|
|
dbus_argv[2 + argc] = NULL;
|
|
|
|
execvp("dbus-launch", dbus_argv);
|
|
|
|
}
|
|
|
|
|
2006-03-04 22:23:14 -08:00
|
|
|
prefix_determine(argv[0]);
|
2006-10-20 22:57:27 -07:00
|
|
|
|
|
|
|
env_set("E_START", argv[0]);
|
2009-07-19 13:30:33 -07:00
|
|
|
|
2006-10-23 06:49:06 -07:00
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
2012-10-10 00:39:08 -07:00
|
|
|
if (!strcmp(argv[i], "-valgrind-gdb"))
|
2012-10-10 00:31:26 -07:00
|
|
|
valgrind_gdbserver = 1;
|
|
|
|
else if (!strncmp(argv[i], "-valgrind", sizeof("-valgrind") - 1))
|
|
|
|
{
|
|
|
|
const char *val = argv[i] + sizeof("-valgrind") - 1;
|
|
|
|
|
|
|
|
if (*val == '\0') valgrind_mode = 1;
|
|
|
|
else if (*val == '-')
|
|
|
|
{
|
|
|
|
val++;
|
|
|
|
if (!strncmp(val, "log-file=", sizeof("log-file=") - 1))
|
|
|
|
{
|
|
|
|
valgrind_log = val + sizeof("log-file=") - 1;
|
|
|
|
if (*valgrind_log == '\0') valgrind_log = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*val == '=')
|
|
|
|
{
|
|
|
|
val++;
|
|
|
|
if (!strcmp(val, "all")) valgrind_mode = VALGRIND_MODE_ALL;
|
|
|
|
else valgrind_mode = atoi(val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("Unknown valgrind option: %s\n", argv[i]);
|
|
|
|
}
|
2012-10-31 23:23:49 -07:00
|
|
|
else if (!strcmp(argv[i], "-display"))
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
env_set("DISPLAY", argv[i]);
|
|
|
|
}
|
2012-10-10 00:31:26 -07:00
|
|
|
else if (!strcmp(argv[i], "-massif"))
|
|
|
|
valgrind_tool = 1;
|
|
|
|
else if (!strcmp(argv[i], "-callgrind"))
|
|
|
|
valgrind_tool = 2;
|
2006-10-23 06:57:47 -07:00
|
|
|
else if ((!strcmp(argv[i], "-h")) ||
|
2012-10-10 00:31:26 -07:00
|
|
|
(!strcmp(argv[i], "-help")) ||
|
|
|
|
(!strcmp(argv[i], "--help")))
|
|
|
|
{
|
|
|
|
printf
|
|
|
|
(
|
|
|
|
"Options:\n"
|
|
|
|
"\t-valgrind[=MODE]\n"
|
|
|
|
"\t\tRun enlightenment from inside valgrind, mode is OR of:\n"
|
|
|
|
"\t\t 1 = plain valgrind to catch crashes (default)\n"
|
|
|
|
"\t\t 2 = trace children (thumbnailer, efm slaves, ...)\n"
|
|
|
|
"\t\t 4 = check leak\n"
|
|
|
|
"\t\t 8 = show reachable after processes finish.\n"
|
|
|
|
"\t\t all = all of above\n"
|
|
|
|
"\t-massif\n"
|
|
|
|
"\t\tRun enlightenment from inside massif valgrind tool.\n"
|
|
|
|
"\t-callgrind\n"
|
|
|
|
"\t\tRun enlightenment from inside callgrind valgrind tool.\n"
|
|
|
|
"\t-valgrind-log-file=<FILENAME>\n"
|
|
|
|
"\t\tSave valgrind log to file, see valgrind's --log-file for details.\n"
|
|
|
|
"\n"
|
|
|
|
"Please run:\n"
|
|
|
|
"\tenlightenment %s\n"
|
|
|
|
"for more options.\n",
|
|
|
|
argv[i]);
|
|
|
|
exit(0);
|
|
|
|
}
|
2012-09-10 02:34:01 -07:00
|
|
|
else if (!strcmp(argv[i], "-i-really-know-what-i-am-doing-and-accept-full-responsibility-for-it"))
|
|
|
|
really_know = EINA_TRUE;
|
2006-10-23 06:49:06 -07:00
|
|
|
}
|
2009-07-11 09:27:37 -07:00
|
|
|
|
2012-09-10 02:34:01 -07:00
|
|
|
if (really_know)
|
2012-10-10 02:27:24 -07:00
|
|
|
_env_path_append("PATH", eina_prefix_bin_get(pfx));
|
2012-09-10 02:34:01 -07:00
|
|
|
else
|
2012-10-10 02:27:24 -07:00
|
|
|
_env_path_prepend("PATH", eina_prefix_bin_get(pfx));
|
2012-10-10 00:31:26 -07:00
|
|
|
|
2010-03-30 08:13:45 -07:00
|
|
|
if (valgrind_mode || valgrind_tool)
|
2009-07-11 09:27:37 -07:00
|
|
|
{
|
2012-10-10 00:31:26 -07:00
|
|
|
if (!find_valgrind(valgrind_path, sizeof(valgrind_path)))
|
|
|
|
{
|
|
|
|
printf("E - valgrind required but no binary found! Ignoring request.\n");
|
|
|
|
valgrind_mode = 0;
|
|
|
|
}
|
2009-07-11 09:27:37 -07:00
|
|
|
}
|
2012-06-20 23:19:43 -07:00
|
|
|
|
2012-10-10 00:39:08 -07:00
|
|
|
printf("E - PID=%i, valgrind=%d", getpid(), valgrind_mode);
|
2009-07-11 09:27:37 -07:00
|
|
|
if (valgrind_mode)
|
|
|
|
{
|
2012-10-10 00:31:26 -07:00
|
|
|
printf(" valgrind-command='%s'", valgrind_path);
|
|
|
|
if (valgrind_log) printf(" valgrind-log-file='%s'", valgrind_log);
|
2009-07-11 09:27:37 -07:00
|
|
|
}
|
|
|
|
putchar('\n');
|
2012-06-20 23:19:43 -07:00
|
|
|
|
2011-11-17 02:19:50 -08:00
|
|
|
/* mtrack memory tracker support */
|
2012-10-31 23:23:49 -07:00
|
|
|
home = getenv("HOME");
|
|
|
|
if (home)
|
2011-11-17 02:19:50 -08:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
/* if you have ~/.e-mtrack, then the tracker will be enabled
|
|
|
|
* using the content of this file as the path to the mtrack.so
|
|
|
|
* shared object that is the mtrack preload */
|
2012-10-31 23:23:49 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s/.e-mtrack", home);
|
2011-11-17 02:19:50 -08:00
|
|
|
f = fopen(buf, "r");
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
if (fgets(buf, sizeof(buf), f))
|
|
|
|
{
|
|
|
|
int len = strlen(buf);
|
|
|
|
if ((len > 1) && (buf[len - 1] == '\n'))
|
|
|
|
{
|
|
|
|
buf[len - 1] = 0;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
env_set("LD_PRELOAD", buf);
|
|
|
|
env_set("MTRACK", "track");
|
|
|
|
env_set("E_START_MTRACK", "track");
|
2012-10-31 23:23:49 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s/.e-mtrack.log", home);
|
2011-11-17 02:19:50 -08:00
|
|
|
env_set("MTRACK_TRACE_FILE", buf);
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
}
|
2012-06-20 23:19:43 -07:00
|
|
|
|
2012-10-31 23:23:49 -07:00
|
|
|
/* run e directly now */
|
2011-08-27 09:25:51 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s/enlightenment", eina_prefix_bin_get(pfx));
|
2011-11-17 02:19:50 -08:00
|
|
|
|
2009-07-11 09:27:37 -07:00
|
|
|
args = alloca((argc + 2 + VALGRIND_MAX_ARGS) * sizeof(char *));
|
2012-07-15 20:19:37 -07:00
|
|
|
i = valgrind_append(args, valgrind_gdbserver, valgrind_mode, valgrind_tool, valgrind_path, valgrind_log);
|
2009-07-11 09:27:37 -07:00
|
|
|
args[i++] = buf;
|
|
|
|
copy_args(args + i, argv + 1, argc - 1);
|
|
|
|
args[i + argc - 1] = NULL;
|
2012-10-31 23:23:49 -07:00
|
|
|
|
2012-12-03 02:43:14 -08:00
|
|
|
if (valgrind_tool || valgrind_mode)
|
|
|
|
really_know = EINA_TRUE;
|
|
|
|
|
2012-11-13 02:54:35 -08:00
|
|
|
#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || \
|
2013-08-24 06:52:27 -07:00
|
|
|
defined(__FreeBSD_kernel__) || (defined (__MACH__) && defined (__APPLE__))
|
2012-11-13 02:54:35 -08:00
|
|
|
execv(args[0], args);
|
|
|
|
#endif
|
2012-10-31 23:23:49 -07:00
|
|
|
|
2012-11-13 02:54:35 -08:00
|
|
|
/* not run at the moment !! */
|
2012-10-31 23:23:49 -07:00
|
|
|
|
2012-11-13 02:54:35 -08:00
|
|
|
#if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__) && \
|
2013-08-24 06:52:27 -07:00
|
|
|
!defined(__FreeBSD_kernel__) && !(defined (__MACH__) && defined (__APPLE__))
|
2013-11-07 23:56:28 -08:00
|
|
|
|
|
|
|
#ifdef E_CSERVE
|
|
|
|
if (getenv("E_CSERVE"))
|
|
|
|
{
|
|
|
|
cs_use = EINA_TRUE;
|
|
|
|
cs_child = _cserve2_start();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-31 23:23:49 -07:00
|
|
|
/* Now looping until */
|
|
|
|
while (restart)
|
|
|
|
{
|
2013-01-11 02:34:29 -08:00
|
|
|
stop_ptrace = EINA_FALSE;
|
2013-02-14 20:56:11 -08:00
|
|
|
|
2012-10-31 23:23:49 -07:00
|
|
|
child = fork();
|
|
|
|
|
|
|
|
if (child < 0) /* failed attempt */
|
|
|
|
return -1;
|
|
|
|
else if (child == 0)
|
|
|
|
{
|
2012-11-12 01:23:39 -08:00
|
|
|
#ifdef HAVE_SYS_PTRACE_H
|
2012-11-12 23:46:02 -08:00
|
|
|
if (!really_know)
|
|
|
|
/* in the child */
|
|
|
|
ptrace(PT_TRACE_ME, 0, NULL, NULL);
|
2012-11-12 01:23:39 -08:00
|
|
|
#endif
|
2012-10-31 23:23:49 -07:00
|
|
|
execv(args[0], args);
|
|
|
|
return 0; /* We failed, 0 mean normal exit from E with no restart or crash so let exit */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-12 21:47:36 -08:00
|
|
|
env_set("E_RESTART", "1");
|
2012-10-31 23:23:49 -07:00
|
|
|
/* in the parent */
|
|
|
|
pid_t result;
|
|
|
|
int status;
|
|
|
|
Eina_Bool done = EINA_FALSE;
|
2013-02-13 04:50:23 -08:00
|
|
|
|
2012-11-12 01:23:39 -08:00
|
|
|
#ifdef HAVE_SYS_PTRACE_H
|
2012-11-12 23:46:02 -08:00
|
|
|
if (!really_know)
|
|
|
|
ptrace(PT_ATTACH, child, NULL, NULL);
|
2012-10-31 23:23:49 -07:00
|
|
|
result = waitpid(child, &status, 0);
|
2012-11-12 23:46:02 -08:00
|
|
|
if ((!really_know) && (!stop_ptrace))
|
2012-11-09 07:42:57 -08:00
|
|
|
{
|
|
|
|
if (WIFSTOPPED(status))
|
|
|
|
ptrace(PT_CONTINUE, child, NULL, NULL);
|
|
|
|
}
|
2012-11-12 01:23:39 -08:00
|
|
|
#endif
|
2012-10-31 23:23:49 -07:00
|
|
|
while (!done)
|
|
|
|
{
|
2012-11-14 01:57:11 -08:00
|
|
|
Eina_Bool remember_sigill = EINA_FALSE;
|
|
|
|
Eina_Bool remember_sigusr1 = EINA_FALSE;
|
2012-11-07 12:56:57 -08:00
|
|
|
|
2013-11-07 23:56:28 -08:00
|
|
|
result = waitpid(child, &status, WNOHANG);
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
/* Wait for evas_cserve2 and E */
|
|
|
|
result = waitpid(-1, &status, 0);
|
|
|
|
}
|
2012-10-31 23:23:49 -07:00
|
|
|
|
|
|
|
if (result == child)
|
|
|
|
{
|
2012-11-09 07:42:57 -08:00
|
|
|
if ((WIFSTOPPED(status)) && (!stop_ptrace))
|
2012-10-31 23:23:49 -07:00
|
|
|
{
|
|
|
|
char buffer[4096];
|
2012-11-02 02:50:49 -07:00
|
|
|
char *backtrace_str = NULL;
|
2012-10-31 23:23:49 -07:00
|
|
|
siginfo_t sig;
|
2012-11-12 01:23:39 -08:00
|
|
|
int r = 0;
|
2012-10-31 23:23:49 -07:00
|
|
|
int back;
|
|
|
|
|
2013-12-07 12:59:56 -08:00
|
|
|
memset(&sig, 0, sizeof(siginfo_t));
|
2012-11-12 01:23:39 -08:00
|
|
|
#ifdef HAVE_SYS_PTRACE_H
|
2012-11-14 01:57:11 -08:00
|
|
|
if (!really_know)
|
2012-12-06 18:49:40 -08:00
|
|
|
r = ptrace(PT_GETSIGINFO, child, NULL, &sig);
|
2012-11-12 01:23:39 -08:00
|
|
|
#endif
|
2012-10-31 23:23:49 -07:00
|
|
|
back = r == 0 &&
|
|
|
|
sig.si_signo != SIGTRAP ? sig.si_signo : 0;
|
|
|
|
|
2012-11-14 01:57:11 -08:00
|
|
|
if (sig.si_signo == SIGUSR1)
|
|
|
|
{
|
|
|
|
if (remember_sigill)
|
|
|
|
remember_sigusr1 = EINA_TRUE;
|
|
|
|
}
|
|
|
|
else if (sig.si_signo == SIGILL)
|
|
|
|
{
|
|
|
|
remember_sigill = EINA_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
remember_sigill = EINA_FALSE;
|
|
|
|
}
|
2012-11-07 12:56:57 -08:00
|
|
|
|
2012-10-31 23:23:49 -07:00
|
|
|
if (r != 0 ||
|
|
|
|
(sig.si_signo != SIGSEGV &&
|
|
|
|
sig.si_signo != SIGFPE &&
|
2013-09-03 16:53:14 -07:00
|
|
|
// sig.si_signo != SIGBUS &&
|
2012-10-31 23:23:49 -07:00
|
|
|
sig.si_signo != SIGABRT))
|
|
|
|
{
|
2012-11-12 01:23:39 -08:00
|
|
|
#ifdef HAVE_SYS_PTRACE_H
|
2012-11-12 23:46:02 -08:00
|
|
|
if (!really_know)
|
|
|
|
ptrace(PT_CONTINUE, child, NULL, back);
|
2012-11-12 01:23:39 -08:00
|
|
|
#endif
|
2012-11-14 01:57:11 -08:00
|
|
|
continue;
|
2012-10-31 23:23:49 -07:00
|
|
|
}
|
2012-11-12 01:23:39 -08:00
|
|
|
#ifdef HAVE_SYS_PTRACE_H
|
2012-11-12 23:46:02 -08:00
|
|
|
if (!really_know)
|
2013-06-18 07:39:53 -07:00
|
|
|
/* E18 should be in pause, we can detach */
|
2012-11-12 23:46:02 -08:00
|
|
|
ptrace(PT_DETACH, child, NULL, back);
|
2012-11-12 01:23:39 -08:00
|
|
|
#endif
|
2012-10-31 23:23:49 -07:00
|
|
|
/* And call gdb if available */
|
2012-11-26 19:48:05 -08:00
|
|
|
r = 0;
|
2012-10-31 23:23:49 -07:00
|
|
|
if (home)
|
|
|
|
{
|
|
|
|
/* call e_sys gdb */
|
|
|
|
snprintf(buffer, 4096,
|
2013-11-30 05:26:30 -08:00
|
|
|
"gdb %i %s/.e-crashdump.txt",
|
2012-10-31 23:23:49 -07:00
|
|
|
child,
|
|
|
|
home);
|
|
|
|
r = system(buffer);
|
|
|
|
|
|
|
|
fprintf(stderr, "called gdb with '%s' = %i\n",
|
|
|
|
buffer, WEXITSTATUS(r));
|
|
|
|
|
|
|
|
snprintf(buffer, 4096,
|
2012-11-12 21:47:36 -08:00
|
|
|
"%s/.e-crashdump.txt",
|
2012-10-31 23:23:49 -07:00
|
|
|
home);
|
|
|
|
|
2012-11-02 02:50:49 -07:00
|
|
|
backtrace_str = strdup(buffer);
|
2012-11-26 19:48:05 -08:00
|
|
|
r = WEXITSTATUS(r);
|
2012-10-31 23:23:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* call e_alert */
|
|
|
|
snprintf(buffer, 4096,
|
2012-11-26 19:48:05 -08:00
|
|
|
backtrace_str ?
|
|
|
|
"%s/enlightenment/utils/enlightenment_alert %i %i '%s' %i" :
|
|
|
|
"%s/enlightenment/utils/enlightenment_alert %i %i '%s' %i",
|
2012-10-31 23:23:49 -07:00
|
|
|
eina_prefix_lib_get(pfx),
|
2012-11-07 12:56:57 -08:00
|
|
|
sig.si_signo == SIGSEGV && remember_sigusr1 ? SIGILL : sig.si_signo,
|
2012-10-31 23:23:49 -07:00
|
|
|
child,
|
2012-11-26 19:48:05 -08:00
|
|
|
backtrace_str,
|
|
|
|
r);
|
2012-10-31 23:23:49 -07:00
|
|
|
r = system(buffer);
|
|
|
|
|
|
|
|
/* kill e */
|
|
|
|
kill(child, SIGKILL);
|
|
|
|
|
|
|
|
if (WEXITSTATUS(r) != 1)
|
|
|
|
{
|
|
|
|
restart = EINA_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!WIFEXITED(status))
|
|
|
|
{
|
|
|
|
done = EINA_TRUE;
|
|
|
|
}
|
2012-11-09 07:42:57 -08:00
|
|
|
else if (stop_ptrace)
|
|
|
|
{
|
|
|
|
done = EINA_TRUE;
|
|
|
|
}
|
2012-10-31 23:23:49 -07:00
|
|
|
}
|
2012-11-09 07:42:57 -08:00
|
|
|
else if (result == -1)
|
2012-10-31 23:23:49 -07:00
|
|
|
{
|
2012-11-09 07:42:57 -08:00
|
|
|
if (errno != EINTR)
|
|
|
|
{
|
|
|
|
done = EINA_TRUE;
|
|
|
|
restart = EINA_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (stop_ptrace)
|
|
|
|
{
|
|
|
|
kill(child, SIGSTOP);
|
|
|
|
usleep(200000);
|
2012-11-12 01:23:39 -08:00
|
|
|
#ifdef HAVE_SYS_PTRACE_H
|
2012-11-12 23:46:02 -08:00
|
|
|
if (!really_know)
|
|
|
|
ptrace(PT_DETACH, child, NULL, NULL);
|
2012-11-12 01:23:39 -08:00
|
|
|
#endif
|
2012-11-09 07:42:57 -08:00
|
|
|
}
|
|
|
|
}
|
2012-10-31 23:23:49 -07:00
|
|
|
}
|
2013-11-07 23:56:28 -08:00
|
|
|
#ifdef E_CSERVE
|
|
|
|
else if (cs_use && (result == cs_child))
|
|
|
|
{
|
|
|
|
if (WIFSIGNALED(status))
|
|
|
|
{
|
|
|
|
printf("E - cserve2 terminated with signal %d\n",
|
|
|
|
WTERMSIG(status));
|
|
|
|
cs_child = _cserve2_start();
|
|
|
|
}
|
|
|
|
else if (WIFEXITED(status))
|
|
|
|
{
|
|
|
|
printf("E - cserve2 exited with code %d\n",
|
|
|
|
WEXITSTATUS(status));
|
|
|
|
cs_child = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2012-10-31 23:23:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-13 02:54:35 -08:00
|
|
|
#endif
|
2008-11-02 23:34:44 -08:00
|
|
|
|
2013-11-07 23:56:28 -08:00
|
|
|
#ifdef E_CSERVE
|
|
|
|
if (cs_child > 0)
|
|
|
|
{
|
|
|
|
pid_t result;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
alarm(2);
|
|
|
|
kill(cs_child, SIGINT);
|
|
|
|
result = waitpid(cs_child, &status, 0);
|
|
|
|
if (result != cs_child)
|
|
|
|
{
|
|
|
|
printf("E - cserve2 did not shutdown in 2 seconds, killing!\n");
|
|
|
|
kill(cs_child, SIGKILL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-10-20 22:57:27 -07:00
|
|
|
return -1;
|
2006-03-04 22:23:14 -08:00
|
|
|
}
|
2012-10-10 00:31:26 -07:00
|
|
|
|