]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
server: kill stdin/stdout/stderr
authorChris Larson <chris_larson@mentor.com>
Fri, 10 Dec 2010 17:37:11 +0000 (10:37 -0700)
committerChris Larson <chris_larson@mentor.com>
Thu, 16 Dec 2010 17:39:27 +0000 (10:39 -0700)
This ensures that nothing run from the server can touch the console, in
particular event handlers and python tasks, both of which can use bb.msg or
the bitbake loggers to send output to the UI in a correct fashion instead.

Signed-off-by: Chris Larson <chris_larson@mentor.com>
lib/bb/server/process.py
lib/bb/utils.py

index f3ad5da60798f41b893d36f025d21b4ac9feb618..12e099a9546401018b5f9733d7c47d73f6fa679f 100644 (file)
@@ -22,6 +22,7 @@
 
 import logging
 import signal
+import sys
 import time
 import bb
 import bb.event
@@ -29,6 +30,7 @@ from multiprocessing import Process, Event
 from bb.cooker import BBCooker
 
 logger = logging.getLogger('BitBake')
+NULL = open('/dev/null', 'a')
 
 class ServerCommunicator():
     def __init__(self, connection):
@@ -86,6 +88,13 @@ class ProcessServer(Process):
         self._idlefunctions[function] = data
 
     def run(self):
+        """Run the server, killing off stdin/stdout/stderr"""
+        with bb.utils.redirected_fds([sys.stdin, sys.stdout, sys.stderr],
+                                     [NULL, NULL, NULL]):
+            return self.main()
+
+    def main(self):
+        """Server main loop"""
         # Ensure logging messages get sent to the UI as events
         logger.addHandler(bb.event.LogHandler())
 
@@ -105,7 +114,6 @@ class ProcessServer(Process):
         self.event_queue.cancel_join_thread()
         bb.event.unregister_UIHhandler(self.event_handle)
         self.command_channel.close()
-        return
 
     def idle_commands(self, delay):
         nextsleep = delay
index 48b120ce5383811a6f7cb4b4817b3da63da614ce..ea5af49cdf21050c6e1e2c640996b8bda085c4ce 100644 (file)
@@ -774,3 +774,18 @@ def init_logger(logger, verbose, debug, debug_domains):
 
     if debug_domains:
         bb.msg.set_debug_domains(debug_domains)
+
+@contextmanager
+def redirected_fds(from_files, to_files):
+    assert len(from_files) == len(to_files), 'from_files / to_files length mismatch'
+
+    old_fds = []
+    for position, fobj in enumerate(from_files):
+        fd = fobj.fileno()
+        old_fds.append(os.dup(fd))
+        os.dup2(to_files[position].fileno(), fd)
+
+    yield
+
+    for position, fd in enumerate(old_fds):
+        os.dup2(fd, from_files[position].fileno())