Anonymous avatar Anonymous committed b0ec4c9

Patch #975056 - fixes for restartable signals on *BSD. In addition,
a few remaining calls to signal() were converted to PyOS_setsig().

Comments (0)

Files changed (5)

Modules/posixmodule.c

 	master_fd = open(DEV_PTY_FILE, O_RDWR | O_NOCTTY); /* open master */
 	if (master_fd < 0)
 		return posix_error();
-	sig_saved = signal(SIGCHLD, SIG_DFL);
+	sig_saved = PyOS_setsig(SIGCHLD, SIG_DFL);
 	/* change permission of slave */
 	if (grantpt(master_fd) < 0) {
-		signal(SIGCHLD, sig_saved);
+		PyOS_setsig(SIGCHLD, sig_saved);
 		return posix_error();
 	}
 	/* unlock slave */
 	if (unlockpt(master_fd) < 0) {
-		signal(SIGCHLD, sig_saved);
+		PyOS_setsig(SIGCHLD, sig_saved);
 		return posix_error();
 	}
-	signal(SIGCHLD, sig_saved);
+	PyOS_setsig(SIGCHLD, sig_saved);
 	slave_name = ptsname(master_fd); /* get name of slave */
 	if (slave_name == NULL)
 		return posix_error();

Modules/signalmodule.c

 		return;
 	}
 #endif
-#ifdef HAVE_SIGINTERRUPT
-	siginterrupt(sig_num, 1);
-#endif
 	PyOS_setsig(sig_num, signal_handler);
 }
 
 	}
 	else
 		func = signal_handler;
-#ifdef HAVE_SIGINTERRUPT
-	siginterrupt(sig_num, 1);
-#endif
 	if (PyOS_setsig(sig_num, func) == SIG_ERR) {
 		PyErr_SetFromErrno(PyExc_RuntimeError);
 		return NULL;

Modules/socketmodule.c

 
 /* Generic includes */
 #include <sys/types.h>
-#include <signal.h>
+//#include <signal.h>
 
 /* Generic socket object definitions and includes */
 #define PySocket_BUILDING_SOCKET

Parser/intrcheck.c

 		Py_Exit(1);
 		break;
 	}
-	signal(SIGINT, intcatcher);
+	PyOS_setsig(SIGINT, intcatcher);
 	Py_AddPendingCall(checksignals_witharg, NULL);
 }
 
 void
 PyOS_InitInterrupts(void)
 {
-	if ((old_siginthandler = signal(SIGINT, SIG_IGN)) != SIG_IGN)
-		signal(SIGINT, intcatcher);
-#ifdef HAVE_SIGINTERRUPT
-	/* This is for SunOS and other modern BSD derivatives.
-	   It means that system calls (like read()) are not restarted
-	   after an interrupt.  This is necessary so interrupting a
-	   read() or readline() call works as expected.
-	   XXX On old BSD (pure 4.2 or older) you may have to do this
-	   differently! */
-	siginterrupt(SIGINT, 1);
-#endif /* HAVE_SIGINTERRUPT */
+	if ((old_siginthandler = PyOS_setsig(SIGINT, SIG_IGN)) != SIG_IGN)
+		PyOS_setsig(SIGINT, intcatcher);
 }
 
 void
 PyOS_FiniInterrupts(void)
 {
-	signal(SIGINT, old_siginthandler);
+	PyOS_setsig(SIGINT, old_siginthandler);
 }
 
 int

Python/pythonrun.c

 initsigs(void)
 {
 #ifdef SIGPIPE
-	signal(SIGPIPE, SIG_IGN);
+	PyOS_setsig(SIGPIPE, SIG_IGN);
 #endif
 #ifdef SIGXFZ
-	signal(SIGXFZ, SIG_IGN);
+	PyOS_setsig(SIGXFZ, SIG_IGN);
 #endif
 #ifdef SIGXFSZ
-	signal(SIGXFSZ, SIG_IGN);
+	PyOS_setsig(SIGXFSZ, SIG_IGN);
 #endif
 	PyOS_InitInterrupts(); /* May imply initsignal() */
 }
 {
 #ifdef HAVE_SIGACTION
 	struct sigaction context;
-	/* Initialize context.sa_handler to SIG_ERR which makes about as
-	 * much sense as anything else.  It should get overwritten if
-	 * sigaction actually succeeds and otherwise we avoid an
-	 * uninitialized memory read.
-	 */
-	context.sa_handler = SIG_ERR;
-	sigaction(sig, NULL, &context);
+	if (sigaction(sig, NULL, &context) == -1)
+		return SIG_ERR;
 	return context.sa_handler;
 #else
 	PyOS_sighandler_t handler;
 	handler = signal(sig, SIG_IGN);
-	signal(sig, handler);
+	if (handler != SIG_ERR)
+		signal(sig, handler);
 	return handler;
 #endif
 }
 PyOS_setsig(int sig, PyOS_sighandler_t handler)
 {
 #ifdef HAVE_SIGACTION
-	struct sigaction context;
+	struct sigaction context, ocontext;
+	context.sa_handler = handler;
+	sigemptyset(&context.sa_mask);
+	context.sa_flags = 0;
+	if (sigaction(sig, &context, &ocontext) == -1)
+		return SIG_ERR;
+	return ocontext.sa_handler;
+#else
 	PyOS_sighandler_t oldhandler;
-	/* Initialize context.sa_handler to SIG_ERR which makes about as
-	 * much sense as anything else.  It should get overwritten if
-	 * sigaction actually succeeds and otherwise we avoid an
-	 * uninitialized memory read.
-	 */
-	context.sa_handler = SIG_ERR;
-	sigaction(sig, NULL, &context);
-	oldhandler = context.sa_handler;
-	context.sa_handler = handler;
-	sigaction(sig, &context, NULL);
+	oldhandler = signal(sig, handler);
+#ifdef HAVE_SIGINTERRUPT
+	siginterrupt(sig, 1);
+#endif
 	return oldhandler;
-#else
-	return signal(sig, handler);
 #endif
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.