summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2017-11-10 13:40:22 -0500
committerJason R. Coombs <jaraco@jaraco.com>2017-11-10 13:40:22 -0500
commit7adb96d8e6f0bb01652d27ed51f9977adf106e94 (patch)
tree4eef836a7c783943c50d37c4af554f2cf89b8689
parent3b239d381cefd04fa8f2561270fc36c81ff20116 (diff)
downloadcherrypy-git-7adb96d8e6f0bb01652d27ed51f9977adf106e94.tar.gz
Consolidate error message rendering
-rw-r--r--cherrypy/process/plugins.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/cherrypy/process/plugins.py b/cherrypy/process/plugins.py
index 9b9bc1b8..c9c18724 100644
--- a/cherrypy/process/plugins.py
+++ b/cherrypy/process/plugins.py
@@ -389,6 +389,10 @@ class Daemonizer(SimplePlugin):
sys.stdout.flush()
sys.stderr.flush()
+ error_tmpl = (
+ "{sys.argv[0]}: fork #{n} failed: ({exc.errno}) {exc.strerror}\n"
+ )
+
# Do first fork.
try:
pid = os.fork()
@@ -399,11 +403,9 @@ class Daemonizer(SimplePlugin):
# This is the first parent. Exit, now that we've forked.
logger('Forking once.')
os._exit(0)
- except OSError:
+ except OSError as exc:
# Python raises OSError rather than returning negative numbers.
- exc = sys.exc_info()[1]
- sys.exit('%s: fork #1 failed: (%d) %s\n'
- % (sys.argv[0], exc.errno, exc.strerror))
+ sys.exit(error_tmpl.format(sys=sys, exc=exc, n=1))
os.setsid()
@@ -413,10 +415,8 @@ class Daemonizer(SimplePlugin):
if pid > 0:
logger('Forking twice.')
os._exit(0) # Exit second parent
- except OSError:
- exc = sys.exc_info()[1]
- sys.exit('%s: fork #2 failed: (%d) %s\n'
- % (sys.argv[0], exc.errno, exc.strerror))
+ except OSError as exc:
+ sys.exit(error_tmpl.format(sys=sys, exc=exc, n=2))
os.umask(0)