1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

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.
This commit is contained in:
Zdenek Kabelac 2017-08-25 11:59:19 +02:00
parent 043ff47b05
commit 5de9444202
2 changed files with 9 additions and 5 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.174 - 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. Fix check for 2nd mda at end of disk fits if using pvcreate --restorefile.
Use maximum metadataarea size that fits with pvcreate --restorefile. Use maximum metadataarea size that fits with pvcreate --restorefile.
Always clear cached bootloaderarea when wiping label e.g. in pvcreate. Always clear cached bootloaderarea when wiping label e.g. in pvcreate.

View File

@ -116,17 +116,16 @@ static int _do_flock(const char *file, int *fd, int operation, uint32_t nonblock
old_errno = errno; old_errno = errno;
if (!nonblock) { if (!nonblock) {
sigint_restore(); sigint_restore();
if (sigint_caught()) if (sigint_caught()) {
log_error("Giving up waiting for lock."); log_error("Giving up waiting for lock.");
break;
}
} }
if (r) { if (r) {
errno = old_errno; errno = old_errno;
log_sys_error("flock", file); log_sys_error("flock", file);
if (close(*fd)) break;
log_sys_debug("close", file);
*fd = -1;
return 0;
} }
if (!stat(file, &buf1) && !fstat(*fd, &buf2) && 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; return 1;
} while (!nonblock); } while (!nonblock);
if (close(*fd))
log_sys_debug("close", file);
*fd = -1;
return_0; return_0;
} }