Skip to contentSkip to conversation

prserv/serv: Tweak stdout manipulation to be stream safe

PATCH Superseded Richard Purdie 1 participant 1 message Jan 4, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 prserv/serv: Tweak stdout manipulation to be stream safe

We've been seeing oe-selftest failures under puzzling circumstances. It turns out if you run oe-selftest on a machine with xmlrunner installed and have the recent tinfoil2 changes, the launching of PR server crashes leading to selftest hanging if using an autoloaded PR server.

The reason is that xmlrunner uses an io.StringIO object as stdout/stderr instead of the usual io.TextIOWrapper and StringIO lacks a fileno() method.

This code was copied from build.py from what I remember and in that case we need to retain copies of the old file descriptors, hence the use of os.dup2. As far as I can tell, here, we can just overwrite the handles directly and hence avoid this rather puzzling crash.

[YOCTO #10866]

---
 lib/prserv/serv.py | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
lib/prserv/serv.py +3 -6
index 350b085..965793d 100644
@@ -242,12 +242,9 @@ class PRServer(SimpleXMLRPCServer):
 
         sys.stdout.flush()
         sys.stderr.flush()
-        si = open('/dev/null', 'r')
-        so = open(self.logfile, 'a+')
-        se = so
-        os.dup2(si.fileno(),sys.stdin.fileno())
-        os.dup2(so.fileno(),sys.stdout.fileno())
-        os.dup2(se.fileno(),sys.stderr.fileno())
+        sys.stdin = open('/dev/null', 'r')
+        sys.stdout = open(self.logfile, 'a+')
+        sys.stderr = sys.stdout
 
         # Clear out all log handlers prior to the fork() to avoid calling
         # event handlers not part of the PRserver
Signature · 1 line
2.7.4