formatting

SVN revision: 77704
This commit is contained in:
Mike Blumenkrantz 2012-10-10 07:31:26 +00:00
parent c5e5f1e5fb
commit 1cdf725b70
1 changed files with 196 additions and 188 deletions

View File

@ -16,7 +16,7 @@
#include <Eina.h> #include <Eina.h>
static void env_set(const char *var, const char *val); static void env_set(const char *var, const char *val);
EAPI int prefix_determine(char *argv0); EAPI int prefix_determine(char *argv0);
static void static void
env_set(const char *var, const char *val) env_set(const char *var, const char *val)
@ -24,23 +24,23 @@ env_set(const char *var, const char *val)
if (val) if (val)
{ {
#ifdef HAVE_SETENV #ifdef HAVE_SETENV
setenv(var, val, 1); setenv(var, val, 1);
#else #else
char *buf; char *buf;
size_t size = strlen(var) + 1 + strlen(val) + 1; size_t size = strlen(var) + 1 + strlen(val) + 1;
buf = alloca(size); buf = alloca(size);
snprintf(buf, size, "%s=%s", var, val); snprintf(buf, size, "%s=%s", var, val);
if (getenv(var)) putenv(buf); if (getenv(var)) putenv(buf);
else putenv(strdup(buf)); else putenv(strdup(buf));
#endif #endif
} }
else else
{ {
#ifdef HAVE_UNSETENV #ifdef HAVE_UNSETENV
unsetenv(var); unsetenv(var);
#else #else
if (getenv(var)) putenv(var); if (getenv(var)) putenv(var);
#endif #endif
} }
} }
@ -80,43 +80,45 @@ precache(void)
// rewind(f); // rewind(f);
while (fgets(buf, sizeof(buf), f)) while (fgets(buf, sizeof(buf), f))
{ {
l = strlen(buf); l = strlen(buf);
if (l > 0) buf[l - 1] = 0; if (l > 0) buf[l - 1] = 0;
if (!fork()) if (!fork())
{ {
if (buf[0] == 's') stat(buf + 2, &st); if (buf[0] == 's') stat(buf + 2, &st);
else if (buf[0] == 'o') else if (buf[0] == 'o')
{ {
fd = open(buf + 2, O_RDONLY); fd = open(buf + 2, O_RDONLY);
if (fd >= 0) if (fd >= 0)
{ {
while (read(fd, tbuf, 256 * 1024) > 0); while (read(fd, tbuf, 256 * 1024) > 0)
close(fd); ;
} close(fd);
} }
else if (buf[0] == 'd') }
{ else if (buf[0] == 'd')
fd = open(buf + 2, O_RDONLY); {
if (fd >= 0) fd = open(buf + 2, O_RDONLY);
{ if (fd >= 0)
while (read(fd, tbuf, 256 * 1024) > 0); {
close(fd); while (read(fd, tbuf, 256 * 1024) > 0)
} ;
} close(fd);
exit(0); }
} }
children++; exit(0);
if (children > 400) }
{ children++;
wait(&cret); if (children > 400)
children--; {
} wait(&cret);
children--;
}
} }
fclose(f); fclose(f);
while (children > 0) while (children > 0)
{ {
wait(&cret); wait(&cret);
children--; children--;
} }
exit(0); exit(0);
} }
@ -128,25 +130,25 @@ find_valgrind(char *path, size_t path_len)
while (env) while (env)
{ {
const char *p = strchr(env, ':'); const char *p = strchr(env, ':');
ssize_t p_len; ssize_t p_len;
if (p) p_len = p - env; if (p) p_len = p - env;
else p_len = strlen(env); else p_len = strlen(env);
if (p_len <= 0) goto next; if (p_len <= 0) goto next;
else if (p_len + sizeof("/valgrind") >= path_len) goto next; else if (p_len + sizeof("/valgrind") >= path_len)
memcpy(path, env, p_len); goto next;
memcpy(path + p_len, "/valgrind", sizeof("/valgrind")); memcpy(path, env, p_len);
if (access(path, X_OK | R_OK) == 0) return 1; memcpy(path + p_len, "/valgrind", sizeof("/valgrind"));
if (access(path, X_OK | R_OK) == 0) return 1;
next: next:
if (p) env = p + 1; if (p) env = p + 1;
else break; else break;
} }
path[0] = '\0'; path[0] = '\0';
return 0; return 0;
} }
/* maximum number of arguments added above */ /* maximum number of arguments added above */
#define VALGRIND_MAX_ARGS 10 #define VALGRIND_MAX_ARGS 10
/* bitmask with all supported bits set */ /* bitmask with all supported bits set */
@ -159,13 +161,14 @@ valgrind_append(char **dst, int valgrind_gdbserver, int valgrind_mode, int valgr
if (valgrind_tool) if (valgrind_tool)
{ {
dst[i++] = valgrind_path; dst[i++] = valgrind_path;
switch (valgrind_tool) switch (valgrind_tool)
{ {
case 1: dst[i++] = "--tool=massif"; break; case 1: dst[i++] = "--tool=massif"; break;
case 2: dst[i++] = "--tool=callgrind"; break;
} case 2: dst[i++] = "--tool=callgrind"; break;
return i; }
return i;
} }
if (valgrind_gdbserver) dst[i++] = "--db-attach=yes"; if (valgrind_gdbserver) dst[i++] = "--db-attach=yes";
if (!valgrind_mode) return 0; if (!valgrind_mode) return 0;
@ -174,17 +177,17 @@ valgrind_append(char **dst, int valgrind_gdbserver, int valgrind_mode, int valgr
dst[i++] = "--malloc-fill=13"; /* invalid pointer, make it crash */ dst[i++] = "--malloc-fill=13"; /* invalid pointer, make it crash */
if (valgrind_log) if (valgrind_log)
{ {
static char logparam[PATH_MAX + sizeof("--log-file=")]; static char logparam[PATH_MAX + sizeof("--log-file=")];
snprintf(logparam, sizeof(logparam), "--log-file=%s", valgrind_log); snprintf(logparam, sizeof(logparam), "--log-file=%s", valgrind_log);
dst[i++] = logparam; dst[i++] = logparam;
} }
if (valgrind_mode & 2) dst[i++] = "--trace-children=yes"; if (valgrind_mode & 2) dst[i++] = "--trace-children=yes";
if (valgrind_mode & 4) if (valgrind_mode & 4)
{ {
dst[i++] = "--leak-check=full"; dst[i++] = "--leak-check=full";
dst[i++] = "--leak-resolution=high"; dst[i++] = "--leak-resolution=high";
dst[i++] = "--track-fds=yes"; dst[i++] = "--track-fds=yes";
} }
if (valgrind_mode & 8) dst[i++] = "--show-reachable=yes"; if (valgrind_mode & 8) dst[i++] = "--show-reachable=yes";
return i; return i;
@ -193,7 +196,8 @@ valgrind_append(char **dst, int valgrind_gdbserver, int valgrind_mode, int valgr
static void static void
copy_args(char **dst, char **src, size_t count) copy_args(char **dst, char **src, size_t count)
{ {
for (; count > 0; count--, dst++, src++) *dst = *src; for (; count > 0; count--, dst++, src++)
*dst = *src;
} }
static void static void
@ -214,8 +218,8 @@ _env_path_prepend(const char *env, const char *path)
// path already there at the start. dont prepend. :) // path already there at the start. dont prepend. :)
if ((!strcmp(p, p2)) || if ((!strcmp(p, p2)) ||
((len > len2) && ((len > len2) &&
(!strncmp(p, p2, len2)) && (!strncmp(p, p2, len2)) &&
(p[len2] == ':'))) (p[len2] == ':')))
return; return;
} }
s = malloc(len + 1 + len2 + 1); s = malloc(len + 1 + len2 + 1);
@ -251,8 +255,8 @@ _env_path_append(const char *env, const char *path)
// path already there at the end. dont append. :) // path already there at the end. dont append. :)
if ((!strcmp(p, p2)) || if ((!strcmp(p, p2)) ||
((len > len2) && ((len > len2) &&
(!strcmp((p + len - len2), p2)) && (!strcmp((p + len - len2), p2)) &&
(p[len - len2 - 1] == ':'))) (p[len - len2 - 1] == ':')))
return; return;
} }
s = malloc(len + 1 + len2 + 1); s = malloc(len + 1 + len2 + 1);
@ -288,62 +292,65 @@ main(int argc, char **argv)
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
if (!strcmp(argv[i], "-no-precache")) do_precache = 0; if (!strcmp(argv[i], "-no-precache")) do_precache = 0;
else if (!strcmp(argv[i], "-valgrind-gdb")) valgrind_gdbserver = 1; else if (!strcmp(argv[i], "-valgrind-gdb"))
else if (!strncmp(argv[i], "-valgrind", sizeof("-valgrind") - 1)) valgrind_gdbserver = 1;
{ else if (!strncmp(argv[i], "-valgrind", sizeof("-valgrind") - 1))
const char *val = argv[i] + sizeof("-valgrind") - 1; {
const char *val = argv[i] + sizeof("-valgrind") - 1;
if (*val == '\0') valgrind_mode = 1; if (*val == '\0') valgrind_mode = 1;
else if (*val == '-') else if (*val == '-')
{ {
val++; val++;
if (!strncmp(val, "log-file=", sizeof("log-file=") - 1)) if (!strncmp(val, "log-file=", sizeof("log-file=") - 1))
{ {
valgrind_log = val + sizeof("log-file=") - 1; valgrind_log = val + sizeof("log-file=") - 1;
if (*valgrind_log == '\0') valgrind_log = NULL; if (*valgrind_log == '\0') valgrind_log = NULL;
} }
} }
else if (*val == '=') else if (*val == '=')
{ {
val++; val++;
if (!strcmp(val, "all")) valgrind_mode = VALGRIND_MODE_ALL; if (!strcmp(val, "all")) valgrind_mode = VALGRIND_MODE_ALL;
else valgrind_mode = atoi(val); else valgrind_mode = atoi(val);
} }
else else
printf("Unknown valgrind option: %s\n", argv[i]); printf("Unknown valgrind option: %s\n", argv[i]);
} }
else if (!strcmp(argv[i], "-massif")) valgrind_tool = 1; else if (!strcmp(argv[i], "-massif"))
else if (!strcmp(argv[i], "-callgrind")) valgrind_tool = 2; valgrind_tool = 1;
else if (!strcmp(argv[i], "-callgrind"))
valgrind_tool = 2;
else if ((!strcmp(argv[i], "-h")) || else if ((!strcmp(argv[i], "-h")) ||
(!strcmp(argv[i], "-help")) || (!strcmp(argv[i], "-help")) ||
(!strcmp(argv[i], "--help"))) (!strcmp(argv[i], "--help")))
{ {
printf printf
( (
"Options:\n" "Options:\n"
"\t-no-precache\n" "\t-no-precache\n"
"\t\tDisable pre-caching of files\n" "\t\tDisable pre-caching of files\n"
"\t-valgrind[=MODE]\n" "\t-valgrind[=MODE]\n"
"\t\tRun enlightenment from inside valgrind, mode is OR of:\n" "\t\tRun enlightenment from inside valgrind, mode is OR of:\n"
"\t\t 1 = plain valgrind to catch crashes (default)\n" "\t\t 1 = plain valgrind to catch crashes (default)\n"
"\t\t 2 = trace children (thumbnailer, efm slaves, ...)\n" "\t\t 2 = trace children (thumbnailer, efm slaves, ...)\n"
"\t\t 4 = check leak\n" "\t\t 4 = check leak\n"
"\t\t 8 = show reachable after processes finish.\n" "\t\t 8 = show reachable after processes finish.\n"
"\t\t all = all of above\n" "\t\t all = all of above\n"
"\t-massif\n" "\t-massif\n"
"\t\tRun enlightenment from inside massif valgrind tool.\n" "\t\tRun enlightenment from inside massif valgrind tool.\n"
"\t-callgrind\n" "\t-callgrind\n"
"\t\tRun enlightenment from inside callgrind valgrind tool.\n" "\t\tRun enlightenment from inside callgrind valgrind tool.\n"
"\t-valgrind-log-file=<FILENAME>\n" "\t-valgrind-log-file=<FILENAME>\n"
"\t\tSave valgrind log to file, see valgrind's --log-file for details.\n" "\t\tSave valgrind log to file, see valgrind's --log-file for details.\n"
"\n" "\n"
"Please run:\n" "Please run:\n"
"\tenlightenment %s\n" "\tenlightenment %s\n"
"for more options.\n", "for more options.\n",
argv[i]); argv[i]);
exit(0); exit(0);
} }
else if (!strcmp(argv[i], "-i-really-know-what-i-am-doing-and-accept-full-responsibility-for-it")) else if (!strcmp(argv[i], "-i-really-know-what-i-am-doing-and-accept-full-responsibility-for-it"))
really_know = EINA_TRUE; really_know = EINA_TRUE;
} }
@ -361,75 +368,75 @@ main(int argc, char **argv)
if (valgrind_mode || valgrind_tool) if (valgrind_mode || valgrind_tool)
{ {
if (!find_valgrind(valgrind_path, sizeof(valgrind_path))) if (!find_valgrind(valgrind_path, sizeof(valgrind_path)))
{ {
printf("E - valgrind required but no binary found! Ignoring request.\n"); printf("E - valgrind required but no binary found! Ignoring request.\n");
valgrind_mode = 0; valgrind_mode = 0;
} }
} }
printf("E - PID=%i, do_precache=%i, valgrind=%d", getpid(), do_precache, valgrind_mode); printf("E - PID=%i, do_precache=%i, valgrind=%d", getpid(), do_precache, valgrind_mode);
if (valgrind_mode) if (valgrind_mode)
{ {
printf(" valgrind-command='%s'", valgrind_path); printf(" valgrind-command='%s'", valgrind_path);
if (valgrind_log) printf(" valgrind-log-file='%s'", valgrind_log); if (valgrind_log) printf(" valgrind-log-file='%s'", valgrind_log);
} }
putchar('\n'); putchar('\n');
if (do_precache) if (do_precache)
{ {
void *lib, *func; void *lib, *func;
/* sanity checks - if precache might fail - check here first */ /* sanity checks - if precache might fail - check here first */
lib = dlopen("libeina.so", RTLD_GLOBAL | RTLD_LAZY); lib = dlopen("libeina.so", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) dlopen("libeina.so.1", RTLD_GLOBAL | RTLD_LAZY); if (!lib) dlopen("libeina.so.1", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) goto done; if (!lib) goto done;
func = dlsym(lib, "eina_init"); func = dlsym(lib, "eina_init");
if (!func) goto done; if (!func) goto done;
lib = dlopen("libecore.so", RTLD_GLOBAL | RTLD_LAZY); lib = dlopen("libecore.so", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) dlopen("libecore.so.1", RTLD_GLOBAL | RTLD_LAZY); if (!lib) dlopen("libecore.so.1", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) goto done; if (!lib) goto done;
func = dlsym(lib, "ecore_init"); func = dlsym(lib, "ecore_init");
if (!func) goto done; if (!func) goto done;
lib = dlopen("libecore_file.so", RTLD_GLOBAL | RTLD_LAZY); lib = dlopen("libecore_file.so", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) dlopen("libecore_file.so.1", RTLD_GLOBAL | RTLD_LAZY); if (!lib) dlopen("libecore_file.so.1", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) goto done; if (!lib) goto done;
func = dlsym(lib, "ecore_file_init"); func = dlsym(lib, "ecore_file_init");
if (!func) goto done; if (!func) goto done;
lib = dlopen("libecore_x.so", RTLD_GLOBAL | RTLD_LAZY); lib = dlopen("libecore_x.so", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) dlopen("libecore_x.so.1", RTLD_GLOBAL | RTLD_LAZY); if (!lib) dlopen("libecore_x.so.1", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) goto done; if (!lib) goto done;
func = dlsym(lib, "ecore_x_init"); func = dlsym(lib, "ecore_x_init");
if (!func) goto done; if (!func) goto done;
lib = dlopen("libevas.so", RTLD_GLOBAL | RTLD_LAZY); lib = dlopen("libevas.so", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) dlopen("libevas.so.1", RTLD_GLOBAL | RTLD_LAZY); if (!lib) dlopen("libevas.so.1", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) goto done; if (!lib) goto done;
func = dlsym(lib, "evas_init"); func = dlsym(lib, "evas_init");
if (!func) goto done; if (!func) goto done;
lib = dlopen("libedje.so", RTLD_GLOBAL | RTLD_LAZY); lib = dlopen("libedje.so", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) dlopen("libedje.so.1", RTLD_GLOBAL | RTLD_LAZY); if (!lib) dlopen("libedje.so.1", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) goto done; if (!lib) goto done;
func = dlsym(lib, "edje_init"); func = dlsym(lib, "edje_init");
if (!func) goto done; if (!func) goto done;
lib = dlopen("libeet.so", RTLD_GLOBAL | RTLD_LAZY); lib = dlopen("libeet.so", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) dlopen("libeet.so.0", RTLD_GLOBAL | RTLD_LAZY); if (!lib) dlopen("libeet.so.0", RTLD_GLOBAL | RTLD_LAZY);
if (!lib) goto done; if (!lib) goto done;
func = dlsym(lib, "eet_init"); func = dlsym(lib, "eet_init");
if (!func) goto done; if (!func) goto done;
/* precache SHOULD work */ /* precache SHOULD work */
snprintf(buf, sizeof(buf), "%s/enlightenment/preload/e_precache.so", snprintf(buf, sizeof(buf), "%s/enlightenment/preload/e_precache.so",
eina_prefix_lib_get(pfx)); eina_prefix_lib_get(pfx));
env_set("LD_PRELOAD", buf); env_set("LD_PRELOAD", buf);
printf("E - PRECACHE GOING NOW...\n"); printf("E - PRECACHE GOING NOW...\n");
fflush(stdout); fflush(stdout);
precache(); precache();
} }
done: done:
@ -471,14 +478,14 @@ done:
if ((!getenv("DBUS_SESSION_BUS_ADDRESS")) && if ((!getenv("DBUS_SESSION_BUS_ADDRESS")) &&
(!getenv("DBUS_LAUNCHD_SESSION_BUS_SOCKET"))) (!getenv("DBUS_LAUNCHD_SESSION_BUS_SOCKET")))
{ {
args[0] = "dbus-launch"; args[0] = "dbus-launch";
args[1] = "--exit-with-session"; args[1] = "--exit-with-session";
i = 2 + valgrind_append(args + 2, valgrind_gdbserver, valgrind_mode, valgrind_tool, valgrind_path, valgrind_log); i = 2 + valgrind_append(args + 2, valgrind_gdbserver, valgrind_mode, valgrind_tool, valgrind_path, valgrind_log);
args[i++] = buf; args[i++] = buf;
copy_args(args + i, argv + 1, argc - 1); copy_args(args + i, argv + 1, argc - 1);
args[i + argc - 1] = NULL; args[i + argc - 1] = NULL;
execvp("dbus-launch", args); execvp("dbus-launch", args);
} }
/* dbus-launch failed - run e direct */ /* dbus-launch failed - run e direct */
@ -493,3 +500,4 @@ done:
perror("execv"); perror("execv");
return -1; return -1;
} }