Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] zsystem flock: zclose descriptor after unsuccessful lock
Hello
I have background scripts using zsystem flock. After a few hours OS X is out of descriptors. Turns out system.c doesn't close descriptor initially opened and passed to movefd(), when lock doesn't succeed. The patch adds preceding zclose(flock_fd) to all return 1 and return 2 code paths.
Just to mention, I might still resolve the script issues by changing code to use subshell closed on unsuccessful lock, unsure yet.
--
Sebastian Gniazdowski
psprint /at/ zdharma.org
diff --git a/Src/Modules/system.c b/Src/Modules/system.c
index 3eecd7e..9fd4d25 100644
--- a/Src/Modules/system.c
+++ b/Src/Modules/system.c
@@ -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;
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author