summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbst-marge-bot <marge-bot@buildstream.build>2019-07-12 08:01:28 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-07-12 08:01:28 +0000
commit6ed6317ef0f91012d9924db63841f94ed5343085 (patch)
tree2b5cd80625cba32989a84af0336e1949c7ca42fb
parentd6bc33fe23e169221130083e5ef3ccdc6e29aef6 (diff)
parentacf4962f0c010a0344e252ffacce741118a844a1 (diff)
downloadbuildstream-6ed6317ef0f91012d9924db63841f94ed5343085.tar.gz
Merge branch 'tristan/exit-on-nonblock-terminal-1.2' into 'bst-1.2'bst-1.2-branchpoint
_frontend/cli.py: Exit with error if output streams are set to nonblocking See merge request BuildStream/buildstream!1389
-rw-r--r--buildstream/_frontend/cli.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 20624e2ac..cf143f1c8 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -1,5 +1,6 @@
import os
import sys
+import fcntl
import click
from .. import _yaml
@@ -158,6 +159,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)