From: ed neville Date: Sat, 6 May 2023 09:05:47 +0000 (+0100) Subject: open with O_CREAT when lock path does not exist X-Git-Tag: 4.14.0-rc1~87 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0bce9c9808e6932b63a50caf537eaa528d7ed73c;p=thirdparty%2Fshadow.git 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 --- diff --git a/lib/commonio.c b/lib/commonio.c index ce043f718..6857f5313 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); }