mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-11-11 09:40:59 +01:00
42188: Close flock descriptor in failure cases
This commit is contained in:
parent
21a09a1418
commit
1e46f73b8e
2 changed files with 16 additions and 3 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue