summaryrefslogtreecommitdiff
path: root/lib/misc
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2017-08-25 11:59:19 +0200
committerZdenek Kabelac <zkabelac@redhat.com>2017-08-25 14:12:55 +0200
commit5de944420224f3b629e843f9c190132ed9ff3dca (patch)
treeaa36b2c1afc283947ac199afc66202aaaa08c910 /lib/misc
parent043ff47b0579bffaa63cb023d8850b0e749eb9ce (diff)
downloadlvm2-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.
Diffstat (limited to 'lib/misc')
-rw-r--r--lib/misc/lvm-flock.c13
1 files changed, 8 insertions, 5 deletions
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;
}