From: Ben Pfaff Date: Thu, 29 Sep 2011 06:07:11 +0000 (-0700) Subject: ovs.daemon: Fix semantics of --pidfile option. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=723a8d23f5d9ba07d67bf4d312b00f001db5bdb4;p=openvswitch ovs.daemon: Fix semantics of --pidfile option. The --pidfile option is supposed to work like this: * Without --pidfile, you don't get a pidfile. * With --pidfile, you get the default pidfile. * With --pidfile=FILE, you get FILE as your pidfile. However, it actually worked like this: * Without --pidfile, you got the default pidfile. * With --pidfile, you got no pidfile at all. * With --pidfile=FILE, you got FILE as your pidfile. This is because of the semantics of "default" in argparse. It is documented as: The default keyword argument of add_argument(), whose value defaults to None, specifies what value should be used if the command-line argument is not present. For optional arguments, the default value is used when the option string was not present at the command line. We actually want "const", which is documented under the description of nargs="?" as: If no command-line argument is present, the value from default will be produced. Note that for optional arguments, there is an additional case - the option string is present but not followed by a command-line argument. In this case the value from const will be produced. Bug #7533. --- diff --git a/python/ovs/daemon.py b/python/ovs/daemon.py index 85db050c..a919c53e 100644 --- a/python/ovs/daemon.py +++ b/python/ovs/daemon.py @@ -503,7 +503,7 @@ def add_args(parser): 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, + group.add_argument("--pidfile", nargs="?", const=pidfile, help="Create pidfile (default %s)." % pidfile) group.add_argument("--overwrite-pidfile", action="store_true", help="With --pidfile, start even if already running.")