[gnome-chess/gnome-3-8] Don't leave an orphaned engine if we crash
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess/gnome-3-8] Don't leave an orphaned engine if we crash
- Date: Sun, 12 Jan 2014 17:24:20 +0000 (UTC)
commit 06ec6a97d60896d333277b5abdae26e6d58e6d71
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Jan 12 10:41:50 2014 -0600
Don't leave an orphaned engine if we crash
If we crash or receive a signal that kills us, the chess engine might
live on forever. Linux (and only Linux) provides a nice way to avoid
this by tying the life of a child process to its parent. Use it.
(To get equivalent behavior on other systems, we would need to fork a
third process to function as a monitor, which is not worth the bother.
Non-Linux users should simply not crash the game.)
configure.ac | 3 +++
src/Makefile.am | 5 +++++
src/chess-engine.vala | 4 ++++
src/prctl.vapi | 9 +++++++++
4 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index eee1287..cde6e04 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,6 +32,9 @@ PKG_CHECK_MODULES(TEST, [
gio-2.0
])
+AC_CHECK_HEADERS([linux/prctl.h])
+AM_CONDITIONAL([WITH_PRCTL], [test x$ac_cv_header_linux_prctl_h = xyes])
+
dnl ###########################################################################
dnl Internationalization
dnl ###########################################################################
diff --git a/src/Makefile.am b/src/Makefile.am
index 4343a2f..8bb47ee 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,7 @@ gnome_chess_SOURCES = \
gl.vapi \
glu.vapi \
glx.vapi \
+ prctl.vapi \
3ds.vala \
gnome-chess.vala \
ai-profile.vala \
@@ -66,6 +67,10 @@ gnome_chess_VALAFLAGS = \
--pkg posix \
--pkg sqlite3
+if WITH_PRCTL
+ gnome_chess_VALAFLAGS += -D HAVE_LINUX_PRCTL_H
+endif
+
CLEANFILES = \
$(patsubst %.vala,%.c,$(filter %.vala, $(SOURCES))) \
*_vala.stamp
diff --git a/src/chess-engine.vala b/src/chess-engine.vala
index 4b63df3..aad4ff2 100644
--- a/src/chess-engine.vala
+++ b/src/chess-engine.vala
@@ -40,7 +40,11 @@ public class ChessEngine : Object
{
Process.spawn_async_with_pipes (null, argv, null,
SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD,
+#if HAVE_LINUX_PRCTL_H
+ () => Prctl.prctl (Prctl.SET_PDEATHSIG, Posix.SIGTERM),
+#else
null,
+#endif
out pid, out stdin_fd, out stdout_fd, out stderr_fd);
}
catch (SpawnError e)
diff --git a/src/prctl.vapi b/src/prctl.vapi
new file mode 100644
index 0000000..c7c2513
--- /dev/null
+++ b/src/prctl.vapi
@@ -0,0 +1,9 @@
+[CCode (cprefix = "", lower_case_cprefix = "")]
+namespace Prctl
+{
+ [CCode (cheader_filename = "linux/prctl.h", cname = "PR_SET_PDEATHSIG")]
+ public const int SET_PDEATHSIG;
+
+ [CCode (cheader_filename = "sys/prctl.h", sentinel = "")]
+ public int prctl (int option, ...);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]