def kill_dhclient(device_name, family=4): for pid in pgrep('dhclient'): try: with open('/proc/%s/cmdline' % pid) as cmdline: args = cmdline.read().strip('\0').split('\0') except IOError as ioe: if ioe.errno == errno.ENOENT: # exited before we read cmdline continue if args[-1] != device_name: # dhclient of another device continue tokens = iter(args) pid_file = '/var/run/dhclient.pid' # Default client pid location running_family = 4 for token in tokens: if token == '-pf': pid_file = next(tokens) elif token == '--no-pid': pid_file = None elif token == '-6': running_family = 6 if running_family != family: continue logging.info('Stopping dhclient -%s before running our own on %s', family, device_name) kill_and_rm_pid(pid, pid_file) # In order to be able to configure the device with dhclient again. It is # necessary that dhclient does not find it configured with any IP address # (except 0.0.0.0 which is fine, or IPv6 link-local address needed for # DHCPv6). ipwrapper.addrFlush(device_name, family)
def shutdown(self): try: pid = int(open(self.pidFile).readline().strip()) except IOError as e: if e.errno == os.errno.ENOENT: pass else: raise else: kill_and_rm_pid(pid, self.pidFile)
def shutdown(self): try: pid = int(open(self.pidFile).readline().strip()) except IOError as e: if e.errno == os.errno.ENOENT: pass else: raise else: logging.info('Stopping dhclient-%s on %s', self.family, self.iface) kill_and_rm_pid(pid, self.pidFile) if linkiface.exists(self.iface): address.flush(self.iface)
def kill(device_name, family=4): if not linkiface.exists(device_name): return for pid, pid_file in _pid_lookup(device_name, family): logging.info('Stopping dhclient-%s on %s', family, device_name) kill_and_rm_pid(pid, pid_file)
def kill(device_name, family=4): for pid, pid_file in _pid_lookup(device_name, family): logging.info('Stopping dhclient -%s on %s', family, device_name) kill_and_rm_pid(pid, pid_file)