summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbst-marge-bot <marge-bot@buildstream.build>2019-07-10 08:55:02 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-07-10 08:55:02 +0000
commit199f080fac88fac1277541baec9def1c13afd048 (patch)
tree44edea43cb6220329cd08149c7e20faca9c2e302
parentd1a9a920812ee832d4e4c34a24e8d84c3c9665ca (diff)
parenta6b0951da02188c62f6aea6b0ce3937ea5b092b7 (diff)
downloadbuildstream-199f080fac88fac1277541baec9def1c13afd048.tar.gz
Merge branch 'tristan/exit-on-nonblock-terminal' into 'master'
_frontend/cli.py: Exit with error if output streams are set to nonblocking Closes #929 See merge request BuildStream/buildstream!1411
-rw-r--r--src/buildstream/_frontend/cli.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py
index 9a753f77a..e9d67ca87 100644
--- a/src/buildstream/_frontend/cli.py
+++ b/src/buildstream/_frontend/cli.py
@@ -3,6 +3,7 @@ import sys
from contextlib import ExitStack
from functools import partial
from tempfile import TemporaryDirectory
+import fcntl
import click
from .. import _yaml
@@ -191,6 +192,17 @@ def override_main(self, args=None, prog_name=None, complete_var=None,
# Regular client return for test cases
return
+ # Check output file descriptor at earliest opportunity, to
+ # provide a reasonable error message instead of a stack trace
+ # in the case that it is blocking
+ for stream in (sys.stdout, sys.stderr):
+ fileno = stream.fileno()
+ flags = fcntl.fcntl(fileno, fcntl.F_GETFL)
+ if flags & os.O_NONBLOCK:
+ click.echo("{} is currently set to O_NONBLOCK, try opening a new shell"
+ .format(stream.name), err=True)
+ sys.exit(-1)
+
original_main(self, args=args, prog_name=prog_name, complete_var=None,
standalone_mode=standalone_mode, **extra)