[bitbake-devel] [PATCH v2] prserv/serv: Tweak stdout manipulation to be stream safe
Richard Purdie
richard.purdie at linuxfoundation.org
Thu Jan 5 14:54:07 UTC 2017
On Thu, 2017-01-05 at 14:46 +0000, Joshua Lock wrote:
> On Thu, 2017-01-05 at 13:52 +0000, Richard Purdie wrote:
> > + # to physically close the fds to prevent the program
> > launching us from
> > + # potentially hanging on a pipe. Handle both cases.
> > si = open('/dev/null', 'r')
> > + try:
> > + os.dup2(si.fileno(),sys.stdin.fileno())
> > + except (AttributeError, io.UnsupportedOperation):
> > + sys.stdin = si
> > 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())
> > + try:
> > + os.dup2(so.fileno(),sys.stdout.fileno())
> > + except (AttributeError, io.UnsupportedOperation):
> > + sys.stdout = so
> > + try:
> > + os.dup2(so.fileno(),sys.stderr.fileno())
> > + except (AttributeError, io.UnsupportedOperation):
> > + sys.stderr = so
> I think there's a copy/paste error here — shouldn't the second
> try/except be duplicating/assigning se not so?
so == se in the original code and I dropped that just using so
everywhere here so I believe the code is ok.
Cheers,
Richard
More information about the bitbake-devel
mailing list