1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-08 09:41:14 +02:00

42188: Close flock descriptor in failure cases

This commit is contained in:
Sebastian Gniazdowski 2017-12-30 16:32:34 +01:00 committed by Peter Stephenson
parent 21a09a1418
commit 1e46f73b8e
2 changed files with 16 additions and 3 deletions

View file

@ -1,3 +1,8 @@
2018-01-04 Peter Stephenson <p.stephenson@samsung.com>
* Sebastian: 42188: Src/Modules/system.c: It is necessary to
close the lock descriptor in some failure cases.
2018-01-04 Oliver Kiddle <okiddle@yahoo.co.uk>
* dana: 42214: Completion/BSD/Type/_file_flags,

View file

@ -649,22 +649,30 @@ bin_zsystem_flock(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
if (timeout > 0) {
time_t end = time(NULL) + (time_t)timeout;
while (fcntl(flock_fd, F_SETLK, &lck) < 0) {
if (errflag)
if (errflag) {
zclose(flock_fd);
return 1;
}
if (errno != EINTR && errno != EACCES && errno != EAGAIN) {
zclose(flock_fd);
zwarnnam(nam, "failed to lock file %s: %e", args[0], errno);
return 1;
}
if (time(NULL) >= end)
if (time(NULL) >= end) {
zclose(flock_fd);
return 2;
}
sleep(1);
}
} else {
while (fcntl(flock_fd, timeout == 0 ? F_SETLK : F_SETLKW, &lck) < 0) {
if (errflag)
if (errflag) {
zclose(flock_fd);
return 1;
}
if (errno == EINTR)
continue;
zclose(flock_fd);
zwarnnam(nam, "failed to lock file %s: %e", args[0], errno);
return 1;
}