diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2017-08-25 11:59:19 +0200 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2017-08-25 14:12:55 +0200 |
commit | 5de944420224f3b629e843f9c190132ed9ff3dca (patch) | |
tree | aa36b2c1afc283947ac199afc66202aaaa08c910 | |
parent | 043ff47b0579bffaa63cb023d8850b0e749eb9ce (diff) | |
download | lvm2-5de944420224f3b629e843f9c190132ed9ff3dca.tar.gz |
locking: avoid descriptor leak for nonblocking mode
When file-locking mode failed on locking, such description was leaked
(typically not an issue since command usually exists afterwards).
So shirt close() at the end of function and use it in all error paths.
Also make sure, when interrrupt is detected, it's really not holding
lock and returns 0.
-rw-r--r-- | WHATS_NEW | 1 | ||||
-rw-r--r-- | lib/misc/lvm-flock.c | 13 |
2 files changed, 9 insertions, 5 deletions
@@ -1,5 +1,6 @@ Version 2.02.174 - ================================= + Fix leaking of file descriptor for non-blocking filebased locking. Fix check for 2nd mda at end of disk fits if using pvcreate --restorefile. Use maximum metadataarea size that fits with pvcreate --restorefile. Always clear cached bootloaderarea when wiping label e.g. in pvcreate. diff --git a/lib/misc/lvm-flock.c b/lib/misc/lvm-flock.c index 22eb128f4..419631314 100644 --- a/lib/misc/lvm-flock.c +++ b/lib/misc/lvm-flock.c @@ -116,17 +116,16 @@ static int _do_flock(const char *file, int *fd, int operation, uint32_t nonblock old_errno = errno; if (!nonblock) { sigint_restore(); - if (sigint_caught()) + if (sigint_caught()) { log_error("Giving up waiting for lock."); + break; + } } if (r) { errno = old_errno; log_sys_error("flock", file); - if (close(*fd)) - log_sys_debug("close", file); - *fd = -1; - return 0; + break; } if (!stat(file, &buf1) && !fstat(*fd, &buf2) && @@ -134,6 +133,10 @@ static int _do_flock(const char *file, int *fd, int operation, uint32_t nonblock return 1; } while (!nonblock); + if (close(*fd)) + log_sys_debug("close", file); + *fd = -1; + return_0; } |