From d43312387d7f7841101e7a600c2072dd076643aa Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Tue, 12 Apr 2011 09:34:05 +0200 Subject: [PATCH] python: Ignore EPIPE in hredir and serve-ssi. --- python/htredir | 11 +++++++---- python/serve-ssi | 30 ++++++++++++++++++------------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/python/htredir b/python/htredir index f0e9070..1e03499 100755 --- a/python/htredir +++ b/python/htredir @@ -53,7 +53,10 @@ else: # Illegal, but the only option (the premises are illegal anyway) pass -sys.stdout.write("HTTP/1.1 %s\n" % status) -sys.stdout.write("Location: %s\n" % target) -sys.stdout.write("Content-Length: 0\n") -sys.stdout.write("\n") +try: + sys.stdout.write("HTTP/1.1 %s\n" % status) + sys.stdout.write("Location: %s\n" % target) + sys.stdout.write("Content-Length: 0\n") + sys.stdout.write("\n") +except IOError: + sys.exit(1) diff --git a/python/serve-ssi b/python/serve-ssi index bbf7188..abdb701 100755 --- a/python/serve-ssi +++ b/python/serve-ssi @@ -151,16 +151,22 @@ if rest != "": sys.exit(0) try: - f = ssifile(open(path), url, path) -except Exception: - simpleerror(sys.stdout, 500, "Server Error", "The server could not access its data.") + try: + f = ssifile(open(path), url, path) + except Exception: + simpleerror(sys.stdout, 500, "Server Error", "The server could not access its data.") + sys.exit(1) + try: + sys.stdout.write("HTTP/1.1 200 OK\n") + sys.stdout.write("Content-Type: text/html\n") + sys.stdout.write("\n") + f.initvars(ssivars) + f.process() + finally: + f.close() +except IOError: + # This is for catching EPIPE, when the client has closed the + # connection. This shouldn't *really* be necessary since the + # process should terminate with SIGPIPE, but apparently Python + # ignores that. sys.exit(1) -try: - sys.stdout.write("HTTP/1.1 200 OK\n") - sys.stdout.write("Content-Type: text/html\n") - sys.stdout.write("\n") - f.initvars(ssivars) - f.process() -finally: - f.close() - -- 2.11.0