summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0778029)
raw | patch | inline | side by side (parent: 0778029)
author | Sven Velt <sven@velt.de> | |
Thu, 17 Jun 2010 12:51:31 +0000 (14:51 +0200) | ||
committer | Sven Velt <sven@velt.de> | |
Thu, 17 Jun 2010 12:51:31 +0000 (14:51 +0200) |
If the pipe is NOT writeable you should see an error message instead of
just a not running daemon.
Signed-off-by: Sven Velt <sven@velt.de>
just a not running daemon.
Signed-off-by: Sven Velt <sven@velt.de>
nagixsc/__init__.py | patch | blob | history |
diff --git a/nagixsc/__init__.py b/nagixsc/__init__.py
index 8f11a42dbf37d65b153759e4daf51be852514a50..825d41d25196eebff8ab1cb3240bda92f2a70526 100644 (file)
--- a/nagixsc/__init__.py
+++ b/nagixsc/__init__.py
@@ -437,7 +437,7 @@ def daemonize(pidfile=None, stdin='/dev/null', stdout='/dev/null', stderr='/dev/
if pid > 0:
sys.exit(0)
except OSError, e:
- sys.stderr.write("1st fork failed: (%d) %sn" % (e.errno, e.strerror))
+ sys.stderr.write("1st fork failed: (%d) %s\n" % (e.errno, e.strerror))
sys.exit(1)
# Prepare 2nd fork
os.chdir("/")
@@ -449,8 +449,18 @@ def daemonize(pidfile=None, stdin='/dev/null', stdout='/dev/null', stderr='/dev/
if pid > 0:
sys.exit(0)
except OSError, e:
- sys.stderr.write("2nd fork failed: (%d) %sn" % (e.errno, e.strerror))
+ sys.stderr.write("2nd fork failed: (%d) %s\n" % (e.errno, e.strerror))
sys.exit(1)
+
+ # Try to write PID file
+ if pidfile:
+ pid = str(os.getpid())
+ try:
+ file(pidfile, 'w+').write('%s\n' % pid)
+ except IOError:
+ sys.stderr.write("Could not write PID file, exiting...\n")
+ sys.exit(1)
+
# Redirect stdin, stdout, stderr
sys.stdout.flush()
sys.stderr.flush()
@@ -461,10 +471,6 @@ def daemonize(pidfile=None, stdin='/dev/null', stdout='/dev/null', stderr='/dev/
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
- if pidfile:
- pid = str(os.getpid())
- file(pidfile, 'w+').write('%s\n' % pid)
-
return
##############################################################################