X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=python%2Fovs%2Fdaemon.py;h=4a704c343a49e40305806999046f69a5a7794147;hb=ec988646afe6aee6a63d6894a3e9b50f715d5941;hp=5937877c3e1e52cc8fca25555fa8210e2ab12be5;hpb=e44a6fe503ad639787ec2f8d1ee0710e63dacd81;p=sliver-openvswitch.git diff --git a/python/ovs/daemon.py b/python/ovs/daemon.py index 5937877c3..4a704c343 100644 --- a/python/ovs/daemon.py +++ b/python/ovs/daemon.py @@ -1,4 +1,4 @@ -# Copyright (c) 2010, 2011 Nicira Networks +# Copyright (c) 2010, 2011, 2012 Nicira, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -78,23 +78,12 @@ def set_pidfile(name): _pidfile = make_pidfile_name(name) -def get_pidfile(): - """Returns an absolute path to the configured pidfile, or None if no - pidfile is configured.""" - return _pidfile - - def set_no_chdir(): """Sets that we do not chdir to "/".""" global _chdir _chdir = False -def is_chdir_enabled(): - """Will we chdir to "/" as part of daemonizing?""" - return _chdir - - def ignore_existing_pidfile(): """Normally, daemonize() or daemonize_start() will terminate the program with a message if a locked pidfile already exists. If this function is @@ -245,13 +234,19 @@ def _fork_and_wait_for_startup(): break if len(s) != 1: retval, status = _waitpid(pid, 0) - if (retval == pid and - os.WIFEXITED(status) and os.WEXITSTATUS(status)): - # Child exited with an error. Convey the same error to - # our parent process as a courtesy. - sys.exit(os.WEXITSTATUS(status)) + if retval == pid: + if os.WIFEXITED(status) and os.WEXITSTATUS(status): + # Child exited with an error. Convey the same error to + # our parent process as a courtesy. + sys.exit(os.WEXITSTATUS(status)) + else: + sys.stderr.write("fork child failed to signal " + "startup (%s)\n" + % ovs.process.status_msg(status)) else: - sys.stderr.write("fork child failed to signal startup\n") + assert retval < 0 + sys.stderr.write("waitpid failed (%s)\n" + % os.strerror(-retval)) sys.exit(1) os.close(rfd) @@ -356,7 +351,9 @@ def daemonize_start(): if _fork_and_wait_for_startup() > 0: # Running in parent process. sys.exit(0) + # Running in daemon or monitor process. + os.setsid() if _monitor: saved_daemonize_fd = _daemonize_fd @@ -378,7 +375,6 @@ def daemonize_complete(): _fork_notify_startup(_daemonize_fd) if _detach: - os.setsid() if _chdir: os.chdir("/") _close_standard_fds()