aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2008-03-22 23:02:30 +0000
committerMike Frysinger <vapier@gentoo.org>2008-03-22 23:02:30 +0000
commitbd34df63613a368698dca3465a2f05273e120c5f (patch)
tree3050599c0dcec840474b1cb8cb29fe641e85b2be /src
parent7beafe361a7f9f06a620a05770821f5650c2c4b0 (diff)
add support for automatic gdb launching when RC_DEBUG is defined to 1 to ease bug reporting / information gathering
Diffstat (limited to 'src')
-rw-r--r--src/rc/Makefile1
-rw-r--r--src/rc/rc.c40
2 files changed, 41 insertions, 0 deletions
diff --git a/src/rc/Makefile b/src/rc/Makefile
index e73cd713..2779a447 100644
--- a/src/rc/Makefile
+++ b/src/rc/Makefile
@@ -33,6 +33,7 @@ CLEANFILES+= ${ALL_LINKS}
LDFLAGS+= -L../librc -L../libeinfo
LDADD+= -lutil -lrc -leinfo
#CFLAGS+= -ggdb
+CPPFLAGS+= $(shell test "x$(DEBUG)" = x && echo -DRC_DEBUG=0 || echo -DRC_DEBUG=1)
LDFLAGS+= $(shell test -d ../../.git && echo -Wl,--rpath=../librc -Wl,--rpath=../libeinfo)
MK= ../../mk
diff --git a/src/rc/rc.c b/src/rc/rc.c
index 499e0dc6..65501c6a 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -898,6 +898,44 @@ interactive_option:
}
+static void catch_a_baddie(int sig)
+{
+ pid_t crashed_pid = getpid();
+
+ switch (fork()) {
+ case -1: _exit(sig);
+ case 0: {
+ char pid[10];
+ sprintf(pid, "%i", crashed_pid);
+ printf("\nAuto launching gdb!\n\n");
+ _exit(execlp("gdb", "gdb", "--quiet", "--pid", pid, "-ex", "bt full", NULL));
+ }
+ default: {
+ int status;
+ wait(&status);
+ }
+ }
+
+ _exit(1);
+}
+static void init_bad_signals(void)
+{
+ struct sigaction sa;
+ sigset_t full;
+
+ if (!RC_DEBUG)
+ return;
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = catch_a_baddie;
+ sigfillset(&full);
+ sa.sa_mask = full;
+
+ sigaction(SIGBUS, &sa, NULL);
+ sigaction(SIGILL, &sa, NULL);
+ sigaction(SIGSEGV, &sa, NULL);
+}
+
#include "_usage.h"
#define getoptstring "o:" getoptstring_COMMON
static const struct option longopts[] = {
@@ -932,6 +970,8 @@ int main(int argc, char **argv)
char *token;
#endif
+ init_bad_signals();
+
applet = basename_c(argv[0]);
LIST_INIT(&service_pids);
atexit(cleanup);