From: Ben Pfaff Date: Wed, 5 Aug 2009 21:53:48 +0000 (-0700) Subject: xenserver: Add new helper function to interface-reconfigure. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=449776d81d7b03d9b5f552b402c8a619323e8aa2;p=openvswitch xenserver: Add new helper function to interface-reconfigure. This will be useful in the followin commit. --- diff --git a/xenserver/opt_xensource_libexec_interface-reconfigure b/xenserver/opt_xensource_libexec_interface-reconfigure index 8f33e102..6de62b38 100755 --- a/xenserver/opt_xensource_libexec_interface-reconfigure +++ b/xenserver/opt_xensource_libexec_interface-reconfigure @@ -543,6 +543,15 @@ def run_command(command): return False return True +def read_first_line_of_file(name): + file = None + try: + file = open(name, 'r') + return file.readline().rstrip('\n') + finally: + if file != None: + file.close() + def down_netdev(interface, deconfigure=True): if not interface_exists(interface): log("down_netdev: interface %s does not exist, ignoring" % interface) @@ -550,14 +559,10 @@ def down_netdev(interface, deconfigure=True): if deconfigure: # Kill dhclient. pidfile_name = '/var/run/dhclient-%s.pid' % interface - pidfile = None try: - pidfile = open(pidfile_name, 'r') - os.kill(int(pidfile.readline()), signal.SIGTERM) + os.kill(int(read_first_line_of_file(pidfile_name)), signal.SIGTERM) except: pass - if pidfile != None: - pidfile.close() # Remove dhclient pidfile. try: