[gnome-chess/gnome-3-8] Do not unconditionally call prctl in distributed C



commit 57f1931b4f7f1b73b1a0ee99ede0b9a22b507800
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Thu Mar 20 22:41:17 2014 -0500

    Do not unconditionally call prctl in distributed C
    
    The existing check for linux/prctl.h works great if you are compiling
    the Vala code, but it's expected that users and distributions may start
    with the distributed C files instead. If the tarball is generated on
    Linux, then the call to prctl() will unconditionally appear in the
    distributed C, and if the tarball isn't generated on Linux, then it will
    be unconditionally absent.
    
    There are only two ways to fix this: (a) not distribute any C code, or
    (b) move the conditional compilation out of the Vala code. Though it
    looks like the Autotools Vala world may be starting to lean towards (a),
    let's be conservative and pick (b) for now.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=726614

 src/Makefile.am       |    8 +++-----
 src/chess-engine.vala |    6 +-----
 src/portability.c     |   30 ++++++++++++++++++++++++++++++
 src/portability.h     |   17 +++++++++++++++++
 src/portability.vapi  |    5 +++++
 src/prctl.vapi        |    9 ---------
 6 files changed, 56 insertions(+), 19 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 8bb47ee..70f0527 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,7 +9,9 @@ gnome_chess_SOURCES = \
        gl.vapi \
        glu.vapi \
        glx.vapi \
-       prctl.vapi \
+       portability.vapi \
+       portability.c \
+       portability.h \
        3ds.vala \
        gnome-chess.vala \
        ai-profile.vala \
@@ -67,10 +69,6 @@ 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 aad4ff2..3b5de30 100644
--- a/src/chess-engine.vala
+++ b/src/chess-engine.vala
@@ -40,11 +40,7 @@ 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
+                                            () => Portability.maybe_kill_orphan_engine (),
                                             out pid, out stdin_fd, out stdout_fd, out stderr_fd);
         }
         catch (SpawnError e)
diff --git a/src/portability.c b/src/portability.c
new file mode 100644
index 0000000..00c098f
--- /dev/null
+++ b/src/portability.c
@@ -0,0 +1,30 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright © 2014 Michael Catanzaro
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 2 of the License, or (at your option) any later
+ * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
+ * license.
+ */
+
+#include "portability.h"
+
+#if HAVE_LINUX_PRCTL_H
+#include <signal.h>
+
+#include <linux/prctl.h>
+#include <sys/prctl.h>
+#endif
+
+/*
+ * When called in the engine process before exec, this ensures
+ * the engine is terminated in the event that we crash.
+ */
+void maybe_kill_orphan_engine ()
+{
+#if HAVE_LINUX_PRCTL_H
+    prctl (PR_SET_PDEATHSIG, SIGTERM);
+#endif
+}
diff --git a/src/portability.h b/src/portability.h
new file mode 100644
index 0000000..634a066
--- /dev/null
+++ b/src/portability.h
@@ -0,0 +1,17 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright © 2014 Michael Catanzaro
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 2 of the License, or (at your option) any later
+ * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
+ * license.
+ */
+
+#ifndef GNOME_CHESS_PORTABILITY_H
+#define GNOME_CHESS_PORTABILITY_H
+
+void maybe_kill_orphan_engine ();
+
+#endif GNOME_CHESS_PORTABILITY_H
diff --git a/src/portability.vapi b/src/portability.vapi
new file mode 100644
index 0000000..a620c3c
--- /dev/null
+++ b/src/portability.vapi
@@ -0,0 +1,5 @@
+[CCode (cheader_filename = "portability.h", lower_case_cprefix = "")]
+namespace Portability
+{
+    public void maybe_kill_orphan_engine ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]