Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Use gdbm_fd_open so we can move the fd to >9
- X-seq: zsh-workers 54994
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: Use gdbm_fd_open so we can move the fd to >9
- Date: Sun, 19 Jul 2026 19:31:03 +0200
- Archived-at: <https://zsh.org/workers/54994>
- List-id: <zsh-workers.zsh.org>
This function is available since gdbm 1.13 and even debian old old
stable has 1.17, so this should be fine.
---
It feels a bit weird that we have to duplicate the open flags, but that's what the
gdbm docs seem to say.
Also clear the fdtable entry in the one path where it wasn't.
Src/Modules/db_gdbm.c | 16 +++++++++++++---
configure.ac | 2 +-
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c
index 09f8224f01..4df86089e8 100644
--- a/Src/Modules/db_gdbm.c
+++ b/Src/Modules/db_gdbm.c
@@ -100,6 +100,7 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
char *resource_name, *pmname;
GDBM_FILE dbf = NULL;
int read_write = GDBM_SYNC, pmflags = PM_REMOVABLE|PM_SINGLE;
+ int fdflags = 0;
Param tied_param;
if(!OPT_ISSET(ops,'d')) {
@@ -112,9 +113,11 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
}
if (OPT_ISSET(ops,'r')) {
read_write |= GDBM_READER;
+ fdflags |= O_RDONLY;
pmflags |= PM_READONLY;
} else {
read_write |= GDBM_WRCREAT;
+ fdflags |= O_RDWR|O_CREAT;
}
/* Here should be a lookup of the backend type against
@@ -147,14 +150,21 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
}
gdbm_errno=0;
- dbf = gdbm_open(resource_name, 0, read_write, 0666, 0);
- if(dbf == NULL) {
- zwarnnam(nam, "error opening database file %s (%s)", resource_name, gdbm_strerror(gdbm_errno));
+ int fd = movefd(open(resource_name, fdflags, 0666));
+ if (fd < 0) {
+ zwarnnam(nam, "error opening database file %s: %e", resource_name, errno);
+ return 1;
+ }
+ dbf = gdbm_fd_open(fd, resource_name, 0, read_write, 0);
+ if (dbf == NULL) {
+ zwarnnam(nam, "error opening database file %s: %s", resource_name, gdbm_strerror(gdbm_errno));
+ zclose(fd);
return 1;
}
if (!(tied_param = creategdbmhash(pmname, pmflags))) {
zwarnnam(nam, "cannot create the requested parameter %s", pmname);
+ fdtable[gdbm_fdesc(dbf)] = FDT_UNUSED;
gdbm_close(dbf);
return 1;
}
diff --git a/configure.ac b/configure.ac
index b541efbef3..d02abe7ce1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -952,7 +952,7 @@ if test x$enable_gdbm = xyes; then
AC_CHECK_HEADERS(gdbm.h, [], [AC_MSG_FAILURE([gdbm.h not found])])
save_LIBS=$LIBS
LIBS=
- AC_CHECK_LIB(gdbm, gdbm_open, [], [AC_MSG_FAILURE([gdbm_open not found in libgdbm])])
+ AC_CHECK_LIB(gdbm, gdbm_fd_open, [], [AC_MSG_FAILURE([gdbm_fd_open not found in libgdbm])])
GDBM_LIBS=$LIBS
LIBS=$save_LIBS
if test x$enable_link_all_libs = xyes; then
--
2.38.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author