diff options
author | Matt Wilson <msw@redhat.com> | 2001-08-14 19:07:08 +0000 |
---|---|---|
committer | Matt Wilson <msw@redhat.com> | 2001-08-14 19:07:08 +0000 |
commit | bb854a2111fec45950593e5409bd9fa6c77f4e9c (patch) | |
tree | 5181601ffc0d1ec4aa127782533c374871327dd7 /isys | |
parent | df86b28137aa6e7d88a348430edbcac8cd77e088 (diff) | |
download | anaconda-bb854a2111fec45950593e5409bd9fa6c77f4e9c.tar.gz anaconda-bb854a2111fec45950593e5409bd9fa6c77f4e9c.tar.xz anaconda-bb854a2111fec45950593e5409bd9fa6c77f4e9c.zip |
beware the leaky descriptor
Diffstat (limited to 'isys')
-rw-r--r-- | isys/isys.py | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/isys/isys.py b/isys/isys.py index 79e39b9ab..8ef0aa327 100644 --- a/isys/isys.py +++ b/isys/isys.py @@ -34,8 +34,10 @@ def raidstop(mdDevice): makeDevInode(mdDevice, "/tmp/md") fd = os.open("/tmp/md", os.O_RDONLY) os.remove("/tmp/md") - _isys.raidstop(fd) - os.close(fd) + try: + _isys.raidstop(fd) + finally: + os.close(fd) def raidstart(mdDevice, aMember): if raidCount.has_key(mdDevice) and raidCount[mdDevice]: @@ -48,15 +50,19 @@ def raidstart(mdDevice, aMember): makeDevInode(aMember, "/tmp/member") fd = os.open("/tmp/md", os.O_RDONLY) os.remove("/tmp/md") - _isys.raidstart(fd, "/tmp/member") - os.close(fd) - os.remove("/tmp/member") + try: + _isys.raidstart(fd, "/tmp/member") + finally: + os.close(fd) + os.remove("/tmp/member") def raidsb(mdDevice): makeDevInode(mdDevice, "/tmp/md") fd = os.open("/tmp/md", os.O_RDONLY) - rc = _isys.getraidsb(fd) - os.close(fd) + try: + rc = _isys.getraidsb(fd) + finally: + os.close(fd) return rc def losetup(device, file, readOnly = 0): @@ -66,21 +72,27 @@ def losetup(device, file, readOnly = 0): mode = os.O_RDWR targ = os.open(file, mode) loop = os.open(device, mode) - _isys.losetup(loop, targ, file) - os.close(loop) - os.close(targ) + try: + _isys.losetup(loop, targ, file) + finally: + os.close(loop) + os.close(targ) def lochangefd(device, file): loop = os.open(device, os.O_RDONLY) targ = os.open(file, os.O_RDONLY) - _isys.lochangefd(loop, targ) - os.close(loop) - os.close(targ) + try: + _isys.lochangefd(loop, targ) + finally: + os.close(loop) + os.close(targ) def unlosetup(device): loop = os.open(device, os.O_RDONLY) - _isys.unlosetup(loop) - os.close(loop) + try: + _isys.unlosetup(loop) + finally: + os.close(loop) def ddfile(file, megs, pw = None): fd = os.open("/dev/zero", os.O_RDONLY); |