From 0bce9c9808e6932b63a50caf537eaa528d7ed73c Mon Sep 17 00:00:00 2001 From: ed neville Date: Sat, 6 May 2023 10:05:47 +0100 Subject: [PATCH] open with O_CREAT when lock path does not exist Reported in #686, by wyj611 when trying to lock a file that is not present Lock method should be F_SETLKW rather than open file descriptor --- lib/commonio.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/commonio.c b/lib/commonio.c index ce043f71..6857f531 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -215,7 +215,7 @@ int do_fcntl_lock (const char *file, bool log, short type) .l_len = 0, }; - fd = open (file, O_WRONLY, 0600); + fd = open (file, O_WRONLY | O_CREAT, 0600); if (-1 == fd) { if (log) { (void) fprintf (shadow_logfd, "%s: %s: %s\n", @@ -224,8 +224,7 @@ int do_fcntl_lock (const char *file, bool log, short type) return 0; } - fcntl (fd, F_OFD_SETLKW, &lck); - close(fd); + fcntl (fd, F_SETLKW, &lck); return(1); }