From 8a9e93bb213fc9ff41ee6af3480c1b9ea2f3345c Mon Sep 17 00:00:00 2001 From: Mariusz Zaborski Date: Sat, 6 Apr 2019 11:24:43 +0000 Subject: [PATCH] Use funlinkat in pidfile to ensure we are removing the right file. --- lib/libutil/pidfile.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c index 05f8174bb1d..5b7d1308368 100644 --- a/lib/libutil/pidfile.c +++ b/lib/libutil/pidfile.c @@ -293,8 +293,11 @@ _pidfile_remove(struct pidfh *pfh, int freeit) return (-1); } - if (unlinkat(pfh->pf_dirfd, pfh->pf_filename, 0) == -1) + if (funlinkat(pfh->pf_dirfd, pfh->pf_filename, pfh->pf_fd, 0) == -1) { + if (errno == EDEADLK) + return (-1); error = errno; + } if (close(pfh->pf_fd) == -1 && error == 0) error = errno; if (close(pfh->pf_dirfd) == -1 && error == 0)