]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
open with O_CREAT when lock path does not exist
authored neville <ed@s5h.net>
Sat, 6 May 2023 09:05:47 +0000 (10:05 +0100)
committerSerge Hallyn <serge@hallyn.com>
Mon, 8 May 2023 13:16:11 +0000 (08:16 -0500)
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

index ce043f718375846478c3ef01ce3df033dc5e86ca..6857f53134c346813c345a38eb784b3451b95747 100644 (file)
@@ -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);
 }