[Flatpak] Let flatpak process handle SIGINT
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jul 2018 08:24:27 +0000 (08:24 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jul 2018 08:24:27 +0000 (08:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187521

Patch by Thibault Saunier <tsaunier@igalia.com> on 2018-07-19
Reviewed by Philippe Normand.

Ensuring that flatpak process ends properly and that the sandbox is teard down.
It also avoids showing usless backtrace to the end user and makes gdb
much more usable.

Also make flatpakutils not verbose by default

* flatpak/flatpakutils.py:
(disable_signals):
(WebkitFlatpak.run_in_sandbox):
(WebkitFlatpak.run_gdb):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233979 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/flatpak/flatpakutils.py

index 93531f2..9dcf871 100644 (file)
@@ -1,3 +1,21 @@
+2018-07-19  Thibault Saunier  <tsaunier@igalia.com>
+
+        [Flatpak] Let flatpak process handle SIGINT
+        https://bugs.webkit.org/show_bug.cgi?id=187521
+
+        Reviewed by Philippe Normand.
+
+        Ensuring that flatpak process ends properly and that the sandbox is teard down.
+        It also avoids showing usless backtrace to the end user and makes gdb
+        much more usable.
+
+        Also make flatpakutils not verbose by default
+
+        * flatpak/flatpakutils.py:
+        (disable_signals):
+        (WebkitFlatpak.run_in_sandbox):
+        (WebkitFlatpak.run_gdb):
+
 2018-07-18  Stephan Szabo  <stephan.szabo@sony.com>
 
         Unreviewed. Fix contributors entry.
index d7f45b5..973b2b1 100644 (file)
@@ -20,11 +20,13 @@ try:
     import configparser
 except ImportError:
     import ConfigParser as configparser
+from contextlib import contextmanager
 import errno
 import json
 import os
 import shlex
 import shutil
+import signal
 import subprocess
 import sys
 import tempfile
@@ -444,6 +446,20 @@ class FlatpakPackage(FlatpakObject):
                     *extra_args, comment=comment)
 
 
+@contextmanager
+def disable_signals(signals=[signal.SIGINT]):
+    old_signal_handlers = []
+
+    for disabled_signal in signals:
+        old_signal_handlers.append((disabled_signal, signal.getsignal(disabled_signal)))
+        signal.signal(disabled_signal, signal.SIG_IGN)
+
+    yield
+
+    for disabled_signal, previous_handler in old_signal_handlers:
+        signal.signal(disabled_signal, previous_handler)
+
+
 class WebkitFlatpak:
 
     @staticmethod
@@ -517,7 +533,7 @@ class WebkitFlatpak:
         self.sdk_debug = None
         self.app = None
 
-        self.verbose = True
+        self.verbose = False
         self.quiet = False
         self.packs = []
         self.update = False
@@ -704,11 +720,12 @@ class WebkitFlatpak:
             _log.debug('Running in sandbox: "%s" %s\n' % ('" "'.join(flatpak_command), shell_string))
             flatpak_command.extend(['sh', "/run/host/" + tmpscript.name])
 
-            try:
-                subprocess.check_call(flatpak_command, stdout=stdout)
-            except subprocess.CalledProcessError as e:
-                sys.stderr.write(str(e) + "\n")
-                return e.returncode
+            with disable_signals():
+                try:
+                    subprocess.check_call(flatpak_command, stdout=stdout)
+                except subprocess.CalledProcessError as e:
+                    sys.stderr.write(str(e) + "\n")
+                    return e.returncode
 
         return 0
 
@@ -794,11 +811,12 @@ class WebkitFlatpak:
                 package.install()
 
     def run_gdb(self):
-        try:
-            subprocess.check_output(['which', 'coredumpctl'])
-        except subprocess.CalledProcessError as e:
-            sys.stderr.write("'coredumpctl' not present on the system, can't run. (%s)\n" % e)
-            return e.returncode
+        with disable_signals():
+            try:
+                subprocess.check_output(['which', 'coredumpctl'])
+            except subprocess.CalledProcessError as e:
+                sys.stderr.write("'coredumpctl' not present on the system, can't run. (%s)\n" % e)
+                return e.returncode
 
         # We need access to the host from the sandbox to run.
         with tempfile.NamedTemporaryFile() as coredump: