ia64/xen-unstable

view tools/misc/netfix @ 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Oct 06 10:13:11 2005 +0100 (2005-10-06)
parents 3b385d58d823
children 18eb059ae471
line source
1 #!/usr/bin/env python
2 # -*- mode: python; -*-
3 #============================================================================
4 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
5 #============================================================================
6 # Move the IP address from eth0 onto the Xen bridge (xen-br0).
7 # Only works if the bridge control utils (brctl) have been installed.
8 #============================================================================
10 from getopt import getopt
12 # add fallback path for non-native python path installs if needed
13 sys.path.append('/usr/lib/python')
14 sys.path.append('/usr/lib64/python')
15 from xen.util.Brctl import *
17 short_options = 'hvqni:b:c'
18 long_options = ['help', 'verbose', 'quiet',
19 'interface=', 'bridge=', 'create']
21 defaults['interface'] = 'eth0'
22 defaults['bridge'] = 'xen-br0'
24 def usage():
25 print """Usage:
26 %s [options]
28 Reconfigure routing so that <bridge> has the IP address from
29 <interface>. This lets IP carry on working when <interface>
30 is attached to <bridge> for virtual networking.
31 Uses brctl to add <interface> to <bridge>,
32 so this can be run before any domains have been created.
33 """ % sys.argv[0]
34 print """
35 -i, --interface <interface> interface, default %(interface)s.
36 -b, --bridge <bridge> bridge, default %(bridge)s.
37 -c, --create create the bridge.
38 -v, --verbose Print commands.
39 -q, --quiet Don't print commands.
40 -n, --dry-run Don't execute commands.
41 -h, --help Print this help.
42 """ % defaults
43 sys.exit(1)
46 def main():
47 lopts = set_opts(Opts(defaults))
48 lopts.dryrun = 0
49 (options, args) = getopt(sys.argv[1:], short_options, long_options)
50 if args: usage()
51 for k, v in options:
52 if k in ['-h', '--help']:
53 usage()
54 elif k in ['-c', '--create']:
55 lopts.create = 1
56 elif k in ['-i', '--interface']:
57 lopts.interface = v
58 elif k in ['-b', '--bridge']:
59 lopts.bridge = v
60 elif k in ['-q', '--quiet']:
61 lopts.verbose = 0
62 elif k in ['-v', '--verbose']:
63 lopts.verbose = 1
64 elif k in ['-n', '--dry-run']:
65 lopts.dryrun = 1
66 reconfigure(lopts.interface, lopts.bridge)
68 if __name__ == '__main__':
69 main()