Commit 225e2544 authored by Iustin Pop's avatar Iustin Pop
Browse files

Handle EPIPE errors while writing to the terminal



This handles EPIPE errors in two places: ToStream (to catch logging
done in GenericMain itself) and in GenericMain (to cover also plain
print statements).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 20d317d4
......@@ -27,6 +27,7 @@ import textwrap
import os.path
import time
import logging
import errno
from cStringIO import StringIO
from ganeti import utils
......@@ -1939,6 +1940,12 @@ def GenericMain(commands, override=None, aliases=None):
ToStderr("Aborted. Note that if the operation created any jobs, they"
" might have been submitted and"
" will continue to run in the background.")
except IOError, err:
if err.errno == errno.EPIPE:
# our terminal went away, we'll exit
sys.exit(constants.EXIT_FAILURE)
else:
raise
return result
......@@ -2795,6 +2802,7 @@ def _ToStream(stream, txt, *args):
@param txt: the message
"""
try:
if args:
args = tuple(args)
stream.write(txt % args)
......@@ -2802,6 +2810,12 @@ def _ToStream(stream, txt, *args):
stream.write(txt)
stream.write('\n')
stream.flush()
except IOError, err:
if err.errno == errno.EPIPE:
# our terminal went away, we'll exit
sys.exit(constants.EXIT_FAILURE)
else:
raise
def ToStdout(txt, *args):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment