diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-12-10 10:37:11 -0700 |
---|---|---|
committer | Chris Larson <chris_larson@mentor.com> | 2010-12-16 10:39:27 -0700 |
commit | 416dfe211ff0c37d746efe113bb6064b7e57d43a (patch) | |
tree | 74d391596ca2c238e3582a2ba60dc7d3665f51ad /lib/bb/utils.py | |
parent | 588d339f2bde8ab6547bc0c1c4e7b83310b1318f (diff) | |
download | bitbake-416dfe211ff0c37d746efe113bb6064b7e57d43a.tar.gz |
server: kill stdin/stdout/stderr
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>
Diffstat (limited to 'lib/bb/utils.py')
-rw-r--r-- | lib/bb/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py index 48b120ce5..ea5af49cd 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -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()) |