From d454bff397c29651e20fdea105b3e8cc197d0f5e Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Wed, 20 Oct 2010 13:54:53 -0700 Subject: Check the pid to make sure it refers to the correct dnsmasq process --- nova/network/linux_net.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index c0be0e8cc..f75a079d9 100644 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -167,11 +167,9 @@ def get_dhcp_hosts(context, network_id): return '\n'.join(hosts) -# TODO(ja): if the system has restarted or pid numbers have wrapped -# then you cannot be certain that the pid refers to the -# dnsmasq. As well, sending a HUP only reloads the hostfile, -# so any configuration options (like dchp-range, vlan, ...) -# aren't reloaded +# NOTE(ja): Sending a HUP only reloads the hostfile, so any +# configuration options (like dchp-range, vlan, ...) +# aren't reloaded. def update_dhcp(context, network_id): """(Re)starts a dnsmasq server for a given network @@ -191,13 +189,15 @@ def update_dhcp(context, network_id): # if dnsmasq is already running, then tell it to reload if pid: - # TODO(ja): use "/proc/%d/cmdline" % (pid) to determine if pid refers - # correct dnsmasq process - try: - _execute('sudo kill -HUP %d' % pid) - return - except Exception as exc: # pylint: disable-msg=W0703 - logging.debug("Hupping dnsmasq threw %s", exc) + out, _err = _execute('cat /proc/%d/cmdline' % pid, check_exit_code=False) + if conffile in out: + try: + _execute('sudo kill -HUP %d' % pid) + return + except Exception as exc: # pylint: disable-msg=W0703 + logging.debug("Hupping dnsmasq threw %s", exc) + else: + logging.debug("Pid %d is stale, relaunching dnsmasq", pid) # FLAGFILE and DNSMASQ_INTERFACE in env env = {'FLAGFILE': FLAGS.dhcpbridge_flagfile, -- cgit