This patch contains additions to handle SIGHUP as a restart signal and to
print a backtrace to stderr when a SIGSEGV happens.  The SIGSEGV
implementation does not use the ecore event signal API stuff cuz there is
no SIGSEGV implementation in ecore.  I might wind up tinkering with ecore
and adding it, but I imagine there is a reason it was omitted.

Anyway, if these seem useful I'm sure they'll make their way to the CVS
tree and if not, feel free to slap me with the news paper and say "Bad
coder monkey, no banana for you!"

Thanks.
-- 
Jason Williams
Gaim Assistant < http://gaim-assistant.sf.net >
<[EMAIL PROTECTED]>
diff -uN e17/apps/e/src/bin/e_includes.h e17.new/apps/e/src/bine_includes.h
--- e17/apps/e/src/bin/e_includes.h	2005-01-15 04:50:26.000000000 -0500
+++ e17.new/apps/e/src/bine_includes.h	2005-01-24 11:49:52.000000000 -0500
@@ -28,3 +28,4 @@
 #include "e_iconify.h"
 #include "e_hints.h"
 #include "e_gadman.h"
+#include "e_signals.h"
diff -uN e17/apps/e/src/bin/e_main.c e17.new/apps/e/src/bine_main.c
--- e17/apps/e/src/bin/e_main.c	2005-01-22 00:21:48.000000000 -0500
+++ e17.new/apps/e/src/bine_main.c	2005-01-24 14:39:40.000000000 -0500
@@ -19,6 +19,7 @@
 
 static void _e_main_cb_x_fatal(void *data);
 static int  _e_main_cb_signal_exit(void *data, int ev_type, void *ev);
+static int  _e_main_cb_signal_hup(void *data, int ev_type, void *ev);
 static int  _e_main_cb_x_flusher(void *data);
 static int  _e_main_cb_idler_before(void *data);
 static int  _e_main_cb_idler_after(void *data);
@@ -57,10 +58,17 @@
    int after_restart = 0; 
    char buf[1024];
    char *s;
-   
+   /* install the signal handlers. */ 
+   struct sigaction sigsegv_action;
+   struct sigaction sighup_action;
+   sigsegv_action.sa_sigaction=&e_sigseg_act;
+   sigsegv_action.sa_flags=0;
+   sigaction(SIGSEGV, &sigsegv_action, NULL);
+
+
    /* for debugging by redirecting stdout of e to a log file to tail */
    setvbuf(stdout, NULL, _IONBF, 0);
-   
+      
    if (getenv("NOSPLASH")) nosplash = 1;
    if (getenv("NOSTARTUP")) nostartup = 1;
    if (getenv("NOWELCOME")) nowelcome = 1;
@@ -128,6 +136,12 @@
 			     "Perhaps you are out of memory?");
 	_e_main_shutdown(-1);
      }
+   if(!ecore_event_handler_add(ECORE_EVENT_SIGNAL_HUP, _e_main_cb_signal_hup, NULL))
+     {
+	e_error_message_show("Enlightenment cannot set up a HUP signal handler.\n"
+                             "Perhaps you are out of memory?");
+	_e_main_shutdown(-1);
+     }
 
    /* an idle enterer to be called before all others */
    _e_main_idle_enterer_before = ecore_idle_enterer_add(_e_main_cb_idler_before, NULL);
@@ -785,6 +799,14 @@
    ecore_main_loop_quit();
    return 1;
 }
+static int
+_e_main_cb_signal_hup(void *data, int ev_type, void *ev)
+{
+   /* called on SIGHUP to restart Enlightenment */
+   printf("RESTART ON!\n");
+   restart = 1;
+   ecore_main_loop_quit();
+}
 
 static int
 _e_main_cb_x_flusher(void *data)
@@ -851,3 +873,4 @@
    e_init_hide();
    return 0;
 }
+
diff -uN e17/apps/e/src/bin/e_signals.c e17.new/apps/e/src/bine_signals.c
--- e17/apps/e/src/bin/e_signals.c	1969-12-31 19:00:00.000000000 -0500
+++ e17.new/apps/e/src/bine_signals.c	2005-01-24 14:34:09.000000000 -0500
@@ -0,0 +1,23 @@
+/*
+ * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
+ */
+#include "e.h"
+
+/* a tricky little devil, requires e and it's libs to be built
+ * with the -rdynamic flag to GCC for any sort of decent output. 
+ */
+void e_sigseg_act(int x, siginfo_t *info, void *data){
+
+  void *array[255];
+  size_t size;
+  char **strings;
+  size_t i;
+  write(2, "**** SEGMENTATION FAULT ****\n", 29);
+  write(2, "**** Printing Backtrace... *****\n\n", 34);
+  size = backtrace (array, 255);
+  backtrace_symbols_fd(array, size, 2);
+  exit(-11); 
+}
+
+
+     
diff -uN e17/apps/e/src/bin/e_signals.h e17.new/apps/e/src/bine_signals.h
--- e17/apps/e/src/bin/e_signals.h	1969-12-31 19:00:00.000000000 -0500
+++ e17.new/apps/e/src/bine_signals.h	2005-01-24 14:34:20.000000000 -0500
@@ -0,0 +1,6 @@
+#ifndef E_SIGNALS_H
+#define E_SIGNALS_H
+
+/* signal handler functions for e */
+void e_sigseg_act(int x, siginfo_t *info, void *data);
+#endif
diff -uN e17/apps/e/src/bin/Makefile.am e17.new/apps/e/src/binMakefile.am
--- e17/apps/e/src/bin/Makefile.am	2005-01-15 04:50:13.000000000 -0500
+++ e17.new/apps/e/src/binMakefile.am	2005-01-24 11:30:03.000000000 -0500
@@ -40,7 +40,8 @@
 e_startup.h \
 e_iconify.h \
 e_hints.h \
-e_gadman.h
+e_gadman.h \
+e_signals.h
 
 
 enlightenment_SOURCES = \
@@ -75,6 +76,7 @@
 e_iconify.c \
 e_hints.c \
 e_gadman.c \
+e_signals.c \
 $(ENLIGHTENMENTHEADERS)
 
 enlightenment_LDFLAGS = -export-dynamic @e_libs@ @dlopen_libs@

Reply via email to