diff options
author | Benjamin Marzinski <bmarzins@sourceware.org> | 2011-04-09 10:03:22 +0200 |
---|---|---|
committer | Christophe Varoqui <christophe.varoqui@opensvc.com> | 2011-04-09 10:03:22 +0200 |
commit | 50b26122b914acaafc3d4fbddd3f95903dc1387d (patch) | |
tree | 0ad32e6831318744a8c0b39ca2e5254d5ec2e6dc | |
parent | 8092493275bf6733e1e9db7922ce208026a70e33 (diff) | |
download | multipath-tools-50b26122b914acaafc3d4fbddd3f95903dc1387d.tar.gz |
Remove tmp loopdev created by 'kpartx -l' if no partitions were found
-rw-r--r-- | kpartx/kpartx.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c index f518aa0..2052b1a 100644 --- a/kpartx/kpartx.c +++ b/kpartx/kpartx.c @@ -186,7 +186,8 @@ get_hotplug_device(void) int main(int argc, char **argv){ - int fd, i, j, m, n, op, off, arg, c, d, ro=0; + int i, j, m, n, op, off, arg, c, d, ro=0; + int fd = -1; struct slice all; struct pt *ptp; enum action what = LIST; @@ -354,8 +355,10 @@ main(int argc, char **argv){ printf("%s: %d slices\n", ptp->type, n); #endif - if (n > 0) + if (n > 0) { close(fd); + fd = -1; + } else continue; @@ -403,15 +406,6 @@ main(int argc, char **argv){ break; } - if (loopcreated && S_ISREG (buf.st_mode)) { - if (del_loop(device)) { - if (verbose) - printf("can't del loop : %s\n", - device); - exit(1); - } - printf("loop deleted : %s\n", device); - } break; case DELETE: @@ -572,6 +566,17 @@ main(int argc, char **argv){ if (n > 0) break; } + if (what == LIST && loopcreated && S_ISREG (buf.st_mode)) { + if (fd != -1) + close(fd); + if (del_loop(device)) { + if (verbose) + printf("can't del loop : %s\n", + device); + exit(1); + } + printf("loop deleted : %s\n", device); + } dm_udev_wait(cookie); dm_lib_release(); dm_lib_exit(); |