[oe-commits] [openembedded-core] 02/03: terminal: Fix gnome-terminal to work with recent versions

git at git.openembedded.org git at git.openembedded.org
Fri Jul 8 09:50:59 UTC 2016


rpurdie pushed a commit to branch master
in repository openembedded-core.

commit 76e8ab47c936674b8bb9bf1c48de53b30f5bf74a
Author: Richard Purdie <richard.purdie at linuxfoundation.org>
AuthorDate: Wed Jul 6 17:08:57 2016 +0100

    terminal: Fix gnome-terminal to work with recent versions
    
    Currently gnome-terminal just returns straight away, opening a terminal in a new
    separate process we have no insight into. For patch resolution, this leads to
    spawning many different terminal windows, for pydevshell, it just flashes a window
    up and then closes.
    
    We need to block until the command completes but gnome-terminal gives us no way
    to do this. We therefore write the pid to a file using a "phonehome" wrapper
    script, then monitor the pid until it exits.
    
    [YOCTO #7254]
    (also fixing do_devpyshell)
    
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/lib/oe/terminal.py             | 23 ++++++++++++++++++++++-
 scripts/oe-gnome-terminal-phonehome | 10 ++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py
index 7f4458e..4a5ab1a 100644
--- a/meta/lib/oe/terminal.py
+++ b/meta/lib/oe/terminal.py
@@ -66,7 +66,28 @@ class Gnome(XTerminal):
         if vernum and LooseVersion(vernum) >= '3.10':
             logger.debug(1, 'Gnome-Terminal 3.10 or later does not support --disable-factory')
             self.command = 'gnome-terminal -t "{title}" -x {command}'
-        XTerminal.__init__(self, sh_cmd, title, env, d)
+
+        # We need to know when the command completes but gnome-terminal gives us no way 
+        # to do this. We therefore write the pid to a file using a "phonehome" wrapper
+        # script, then monitor the pid until it exits. Thanks gnome!
+
+        import tempfile
+        pidfile = tempfile.NamedTemporaryFile(delete = False).name
+        try:
+            sh_cmd = "oe-gnome-terminal-phonehome " + pidfile + " " + sh_cmd
+            XTerminal.__init__(self, sh_cmd, title, env, d)
+            while os.stat(pidfile).st_size <= 0:
+                continue
+            with open(pidfile, "r") as f:
+                pid = int(f.readline())
+        finally:
+            os.unlink(pidfile)
+
+        while True:
+            try:
+                os.kill(pid, 0)
+            except OSError:
+               return
 
 class Mate(XTerminal):
     command = 'mate-terminal -t "{title}" -x {command}'
diff --git a/scripts/oe-gnome-terminal-phonehome b/scripts/oe-gnome-terminal-phonehome
new file mode 100755
index 0000000..e023548
--- /dev/null
+++ b/scripts/oe-gnome-terminal-phonehome
@@ -0,0 +1,10 @@
+#!/bin/sh
+#
+# Gnome terminal won't tell us which PID a given command is run as 
+# or allow a single instance so we can't tell when it completes.
+# This allows us to figure out the PID of the target so we can tell 
+# when its done.
+#
+echo $$ > $1
+shift
+exec $@

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list