summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-06-07 00:54:57 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-06-07 00:54:57 +0100
commit74815ebc9b0ea19a006266e981f0ce48ccd1e63a (patch)
treee69bf00b6c7f8f9d229f37b79acfda7ae7b89184 /src
parent71b5cb3e7c963f10af9be66df958ac98e92f8042 (diff)
e start - save 24k of stack that gets touched then never again.
use less stack with smaller "just big enough" alloca'd string buffers. as e_start hangs around looking after e all day, using a bit less mem is a good thing. @opt
Diffstat (limited to 'src')
-rw-r--r--src/bin/e_start_main.c145
1 files changed, 78 insertions, 67 deletions
diff --git a/src/bin/e_start_main.c b/src/bin/e_start_main.c
index 8534a7a8e..b8c3a145c 100644
--- a/src/bin/e_start_main.c
+++ b/src/bin/e_start_main.c
@@ -33,30 +33,40 @@
33 33
34#include <Eina.h> 34#include <Eina.h>
35 35
36# ifdef E_API 36#define myasprintf(__b, __fmt, args...) do { \
37# undef E_API 37 char __bb[sizeof(__fmt) + 1]; \
38# endif 38 int __cnt = snprintf(__bb, sizeof(__bb), __fmt, ##args); \
39# ifdef WIN32 39 printf("cnt=%i\n", __cnt); \
40# ifdef BUILDING_DLL 40 if (__cnt >= 0) { \
41# define E_API __declspec(dllexport) 41 *(__b) = alloca(__cnt + 1); \
42# else 42 snprintf(*(__b), __cnt + 1, __fmt, ##args); \
43# define E_API __declspec(dllimport) 43 } \
44# endif 44} while (0)
45
46#ifdef E_API
47# undef E_API
48#endif
49#ifdef WIN32
50# ifdef BUILDING_DLL
51# define E_API __declspec(dllexport)
45# else 52# else
46# ifdef __GNUC__ 53# define E_API __declspec(dllimport)
47# if __GNUC__ >= 4 54# endif
55#else
56# ifdef __GNUC__
57# if __GNUC__ >= 4
48/* BROKEN in gcc 4 on amd64 */ 58/* BROKEN in gcc 4 on amd64 */
49# if 0 59# if 0
50# pragma GCC visibility push(hidden) 60# pragma GCC visibility push(hidden)
51# endif
52# define E_API __attribute__ ((visibility("default")))
53# else
54# define E_API
55# endif 61# endif
62# define E_API __attribute__ ((visibility("default")))
56# else 63# else
57# define E_API 64# define E_API
58# endif 65# endif
66# else
67# define E_API
59# endif 68# endif
69#endif
60 70
61static Eina_Bool stop_ptrace = EINA_FALSE; 71static Eina_Bool stop_ptrace = EINA_FALSE;
62 72
@@ -455,26 +465,26 @@ static int
455_e_call_gdb(int child, const char *home, char **backtrace_str) 465_e_call_gdb(int child, const char *home, char **backtrace_str)
456{ 466{
457 int r = 0; 467 int r = 0;
458 char buf[4096]; 468 char *buf = NULL;
459 /* call e_sys gdb */ 469 /* call e_sys gdb */
460 snprintf(buf, sizeof(buf), 470 myasprintf(&buf,
461 "gdb " 471 "gdb "
462 "--pid=%i " 472 "--pid=%i "
463 "-batch " 473 "-batch "
464 "-ex 'set logging file %s/.e-crashdump.txt' " 474 "-ex 'set logging file %s/.e-crashdump.txt' "
465 "-ex 'set logging on' " 475 "-ex 'set logging on' "
466 "-ex 'thread apply all backtrace full' " 476 "-ex 'thread apply all backtrace full' "
467 "-ex detach > /dev/null 2>&1 < /dev/zero", 477 "-ex detach > /dev/null 2>&1 < /dev/zero",
468 child, 478 child,
469 home); 479 home);
470 r = system(buf); 480 r = system(buf);
471 481
472 fprintf(stderr, "called gdb with '%s' = %i\n", 482 fprintf(stderr, "called gdb with '%s' = %i\n",
473 buf, WEXITSTATUS(r)); 483 buf, WEXITSTATUS(r));
474 484
475 snprintf(buf, 4096, 485 myasprintf(&buf,
476 "%s/.e-crashdump.txt", 486 "%s/.e-crashdump.txt",
477 home); 487 home);
478 488
479 *backtrace_str = strdup(buf); 489 *backtrace_str = strdup(buf);
480 return WEXITSTATUS(r); 490 return WEXITSTATUS(r);
@@ -484,17 +494,17 @@ static int
484_e_call_alert(int child, siginfo_t sig, int exit_gdb, const char *backtrace_str, 494_e_call_alert(int child, siginfo_t sig, int exit_gdb, const char *backtrace_str,
485 Eina_Bool susr1) 495 Eina_Bool susr1)
486{ 496{
487 char buf[4096]; 497 char *buf = NULL;
488 498
489 snprintf(buf, sizeof(buf), 499 myasprintf(&buf,
490 backtrace_str ? 500 backtrace_str ?
491 "%s/enlightenment/utils/enlightenment_alert %i %i %i '%s'" : 501 "%s/enlightenment/utils/enlightenment_alert %i %i %i '%s'" :
492 "%s/enlightenment/utils/enlightenment_alert %i %i %i", 502 "%s/enlightenment/utils/enlightenment_alert %i %i %i",
493 eina_prefix_lib_get(pfx), 503 eina_prefix_lib_get(pfx),
494 (sig.si_signo == SIGSEGV && susr1) ? SIGILL : sig.si_signo, 504 (sig.si_signo == SIGSEGV && susr1) ? SIGILL : sig.si_signo,
495 child, 505 child,
496 exit_gdb, 506 exit_gdb,
497 backtrace_str); 507 backtrace_str);
498 return system(buf); 508 return system(buf);
499} 509}
500 510
@@ -575,8 +585,8 @@ main(int argc, char **argv)
575 int i, valgrind_mode = 0; 585 int i, valgrind_mode = 0;
576 int valgrind_tool = 0; 586 int valgrind_tool = 0;
577 int valgrind_gdbserver = 0; 587 int valgrind_gdbserver = 0;
578 char buf[8192], buf2[4096], buf3[4096], **args, *home; 588 char *buf = NULL, *buf2 = NULL, *buf3 = NULL, **args, *home;
579 char valgrind_path[PATH_MAX] = ""; 589 char *valgrind_path = NULL;
580 const char *valgrind_log = NULL; 590 const char *valgrind_log = NULL;
581 const char *bindir; 591 const char *bindir;
582 Eina_Bool really_know = EINA_FALSE; 592 Eina_Bool really_know = EINA_FALSE;
@@ -613,14 +623,14 @@ main(int argc, char **argv)
613 { 623 {
614 const char *dir; 624 const char *dir;
615 625
616 snprintf(buf, sizeof(buf), "/tmp/xdg-XXXXXX"); 626 myasprintf(&buf, "/tmp/xdg-XXXXXX");
617 dir = mkdtemp(buf); 627 dir = mkdtemp(buf);
618 if (!dir) dir = "/tmp"; 628 if (!dir) dir = "/tmp";
619 else 629 else
620 { 630 {
621 FILE *f; 631 FILE *f;
622 632
623 snprintf(buf2, sizeof(buf2), "%s/.e-deleteme", dir); 633 myasprintf(&buf2, "%s/.e-deleteme", dir);
624 f = fopen(buf2, "w"); 634 f = fopen(buf2, "w");
625 if (f) fclose(f); 635 if (f) fclose(f);
626 } 636 }
@@ -705,26 +715,30 @@ main(int argc, char **argv)
705 if (really_know) _env_path_append("PATH", bindir); 715 if (really_know) _env_path_append("PATH", bindir);
706 else _env_path_prepend("PATH", bindir); 716 else _env_path_prepend("PATH", bindir);
707 } 717 }
708 snprintf(buf2, sizeof(buf2), 718 myasprintf(&buf2,
709 "E_ALERT_FONT_DIR=%s/data/fonts", eina_prefix_data_get(pfx)); 719 "E_ALERT_FONT_DIR=%s/data/fonts",
720 eina_prefix_data_get(pfx));
710 putenv(buf2); 721 putenv(buf2);
711 snprintf(buf3, sizeof(buf3), 722 myasprintf(&buf3,
712 "E_ALERT_SYSTEM_BIN=%s/enlightenment/utils/enlightenment_system", eina_prefix_lib_get(pfx)); 723 "E_ALERT_SYSTEM_BIN=%s/enlightenment/utils/enlightenment_system",
724 eina_prefix_lib_get(pfx));
713 putenv(buf3); 725 putenv(buf3);
714 726
715 if ((valgrind_mode || valgrind_tool) && 727 if (valgrind_mode || valgrind_tool)
716 !find_valgrind(valgrind_path, sizeof(valgrind_path)))
717 { 728 {
718 printf("E - valgrind required but no binary found! Ignoring request.\n"); 729 valgrind_path = alloca(PATH_MAX);
719 valgrind_mode = 0; 730 if (!find_valgrind(valgrind_path, PATH_MAX))
731 {
732 printf("E - valgrind required but no binary found! Ignoring request.\n");
733 valgrind_mode = 0;
734 }
720 } 735 }
721 736
722 printf("E - PID=%i, valgrind=%d", getpid(), valgrind_mode); 737 printf("E - PID=%i, valgrind=%d", getpid(), valgrind_mode);
723 if (valgrind_mode) 738 if (valgrind_mode && valgrind_path)
724 { 739 {
725 printf(" valgrind-command='%s'", valgrind_path); 740 printf(" valgrind-command='%s'", valgrind_path);
726 if (valgrind_log) 741 if (valgrind_log) printf(" valgrind-log-file='%s'", valgrind_log);
727 printf(" valgrind-log-file='%s'", valgrind_log);
728 } 742 }
729 putchar('\n'); 743 putchar('\n');
730 744
@@ -733,23 +747,20 @@ main(int argc, char **argv)
733 { 747 {
734 const char *tmps = getenv("XDG_DATA_HOME"); 748 const char *tmps = getenv("XDG_DATA_HOME");
735 749
736 if (tmps) 750 if (tmps) myasprintf(&buf, "%s/Applications/.bin", tmps);
737 snprintf(buf, sizeof(buf), "%s/Applications/.bin", tmps); 751 else myasprintf(&buf, "%s/Applications/.bin", home);
738 else
739 snprintf(buf, sizeof(buf), "%s/Applications/.bin", home);
740 752
741 if (really_know) 753 if (really_know) _env_path_append("PATH", buf);
742 _env_path_append("PATH", buf); 754 else _env_path_prepend("PATH", buf);
743 else
744 _env_path_prepend("PATH", buf);
745 } 755 }
746 756
747 /* run e directly now */ 757 /* run e directly now */
748 snprintf(buf, sizeof(buf), "%s/enlightenment", eina_prefix_bin_get(pfx)); 758 myasprintf(&buf, "%s/enlightenment", eina_prefix_bin_get(pfx));
749 759
750 args = alloca((argc + 2 + VALGRIND_MAX_ARGS) * sizeof(char *)); 760 args = alloca((argc + 2 + VALGRIND_MAX_ARGS) * sizeof(char *));
751 i = valgrind_append(args, valgrind_gdbserver, valgrind_mode, valgrind_tool, 761 i = valgrind_append(args, valgrind_gdbserver, valgrind_mode, valgrind_tool,
752 valgrind_path, valgrind_log); 762 valgrind_path, valgrind_log);
763 printf("== [%s]\n", buf);
753 args[i++] = buf; 764 args[i++] = buf;
754 copy_args(args + i, argv + 1, argc - 1); 765 copy_args(args + i, argv + 1, argc - 1);
755 args[i + argc - 1] = NULL; 766 args[i + argc - 1] = NULL;
@@ -865,7 +876,7 @@ not_done:
865 s = getenv("XDG_RUNTIME_DIR"); 876 s = getenv("XDG_RUNTIME_DIR");
866 if ((s) && (stat(s, &st) == 0) && (S_ISDIR(st.st_mode))) 877 if ((s) && (stat(s, &st) == 0) && (S_ISDIR(st.st_mode)))
867 { 878 {
868 snprintf(buf, sizeof(buf), "%s/.e-deleteme", s); 879 myasprintf(&buf, "%s/.e-deleteme", s);
869 if (stat(buf, &st) == 0) rmrf(s); 880 if (stat(buf, &st) == 0) rmrf(s);
870 } 881 }
871 */ 882 */