+def read_pidfile(pidfile):
+ """Opens and reads a PID from 'pidfile'. Returns the positive PID if
+ successful, otherwise a negative errno value."""
+ return __read_pidfile(pidfile, False)
+
+
+def _check_already_running():
+ pid = __read_pidfile(_pidfile, True)
+ if pid > 0:
+ _fatal("%s: already running as pid %d, aborting" % (_pidfile, pid))
+ elif pid < 0:
+ _fatal("%s: pidfile check failed (%s), aborting"
+ % (_pidfile, os.strerror(pid)))
+
+
+def add_args(parser):
+ """Populates 'parser', an ArgumentParser allocated using the argparse
+ module, with the command line arguments required by the daemon module."""
+
+ pidfile = make_pidfile_name(None)
+
+ group = parser.add_argument_group(title="Daemon Options")
+ group.add_argument("--detach", action="store_true",
+ help="Run in background as a daemon.")
+ group.add_argument("--no-chdir", action="store_true",
+ help="Do not chdir to '/'.")
+ group.add_argument("--monitor", action="store_true",
+ help="Monitor %s process." % ovs.util.PROGRAM_NAME)
+ group.add_argument("--pidfile", nargs="?", default=pidfile,
+ help="Create pidfile (default %s)." % pidfile)
+ group.add_argument("--overwrite-pidfile", action="store_true",
+ help="With --pidfile, start even if already running.")
+
+
+def handle_args(args):
+ """Handles daemon module settings in 'args'. 'args' is an object
+ containing values parsed by the parse_args() method of ArgumentParser. The
+ parent ArgumentParser should have been prepared by add_args() before
+ calling parse_args()."""
+
+ if args.detach: