changeset 15646:61b42cf81aa4

Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
author Evan Schoenberg <evan.s@dreskin.net>
date Sun, 18 Feb 2007 18:16:57 +0000
parents 602eb093e4c0
children 552be3958d6a
files libpurple/dnsquery.c libpurple/dnssrv.c libpurple/util.c libpurple/util.h
diffstat 4 files changed, 34 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/dnsquery.c	Thu Feb 15 23:25:50 2007 +0000
+++ b/libpurple/dnsquery.c	Sun Feb 18 18:16:57 2007 +0000
@@ -157,11 +157,7 @@
 #endif
 
 #ifdef HAVE_SIGNAL_H
-	signal(SIGHUP, SIG_DFL);
-	signal(SIGINT, SIG_DFL);
-	signal(SIGQUIT, SIG_DFL);
-	signal(SIGCHLD, SIG_DFL);
-	signal(SIGTERM, SIG_DFL);
+	gaim_restore_default_signal_handlers();	
 	signal(SIGTRAP, trap_gdb_bug);
 #endif
 
--- a/libpurple/dnssrv.c	Thu Feb 15 23:25:50 2007 +0000
+++ b/libpurple/dnssrv.c	Sun Feb 18 18:16:57 2007 +0000
@@ -104,6 +104,10 @@
 	guint16 type, dlen, pref, weight, port;
 	gchar query[256];
 
+#ifdef HAVE_SIGNAL_H
+	gaim_restore_default_signal_handlers();
+#endif
+	
 	if (read(in, query, 256) <= 0)
 		_exit(0);
 
--- a/libpurple/util.c	Thu Feb 15 23:25:50 2007 +0000
+++ b/libpurple/util.c	Sun Feb 18 18:16:57 2007 +0000
@@ -4115,3 +4115,25 @@
 	return protocol;
 }
 
+void gaim_restore_default_signal_handlers(void)
+{
+#ifdef HAVE_SIGNAL_H
+	signal(SIGHUP, SIG_DFL);	/* 1: terminal line hangup */
+	signal(SIGINT, SIG_DFL);	/* 2: interrupt program */
+	signal(SIGQUIT, SIG_DFL);	/* 3: quit program */
+	signal(SIGILL,  SIG_DFL);	/* 4:  illegal instruction (not reset when caught) */
+	signal(SIGTRAP, SIG_DFL);	/* 5:  trace trap (not reset when caught) */
+	signal(SIGABRT, SIG_DFL);	/* 6:  abort program */
+	signal(SIGEMT,  SIG_DFL);	/* 7:  EMT instruction */
+	signal(SIGFPE,  SIG_DFL);	/* 8:  floating point exception */
+	signal(SIGBUS,  SIG_DFL);	/* 10: bus error */
+	signal(SIGSEGV, SIG_DFL);	/* 11: segmentation violation */
+	signal(SIGSYS,  SIG_DFL);	/* 12: bad argument to system call */
+	signal(SIGPIPE, SIG_DFL);	/* 13: write on a pipe with no reader */
+	signal(SIGALRM, SIG_DFL);	/* 14: real-time timer expired */
+	signal(SIGTERM, SIG_DFL);	/* 15: software termination signal */
+	signal(SIGCHLD, SIG_DFL);	/* 20: child status has changed */
+	signal(SIGXCPU, SIG_DFL);	/* 24: exceeded CPU time limit */
+	signal(SIGXFSZ, SIG_DFL);	/* 25: exceeded file size limit */	
+#endif
+}
--- a/libpurple/util.h	Thu Feb 15 23:25:50 2007 +0000
+++ b/libpurple/util.h	Sun Feb 18 18:16:57 2007 +0000
@@ -1071,6 +1071,13 @@
  * This should not be used by plugins.
  */
 const char *_gaim_oscar_convert(const char *act, const char *protocol);
+
+/**
+ * Restore default signal handlers for signals which might reasonably have
+ * handlers. This should be called by a fork()'d child process, since child processes
+ * inherit the handlers of the parent.
+ */
+void gaim_restore_default_signal_handlers(void);
 #ifdef __cplusplus
 }
 #endif