Skip to content

fix(db-functions): fix locking issue that overwrote the same fd

Levente Polyak requested to merge fix-locking-fd-table into master

Calling acquire_fd in a subshell doesn't populate the global lockfd associate array properly. This resulted in the reuse of the same fd multiple times, effectively only holding a single latest lock and releasing any previous.

Fix the issue by avoiding a global variable that causes issues in subshell calls by using the file descriptor table directly. Instead of storing file descriptors, the lookup call iterates through all fds and checks their handle. In case a file is not yet opened, allocate the next free fd between 4 and 1023.

Operating directly on the file descriptor table has the nice side effect that we avoid reusing descriptors by accident in case they have been opened for none locking purpose within the statically defined range.

Reported-by: Felix Yan felixonmars@archlinux.org

Co-authored-by: Felix Yan felixonmars@archlinux.org

Signed-off-by: Levente Polyak anthraxx@archlinux.org

Edited by Levente Polyak

Merge request reports

Loading