diff options
author | ed neville <ed@s5h.net> | 2023-05-06 10:05:47 +0100 |
---|---|---|
committer | Serge Hallyn <serge@hallyn.com> | 2023-05-08 08:16:11 -0500 |
commit | 0bce9c9808e6932b63a50caf537eaa528d7ed73c (patch) | |
tree | 8c897eadf8520565f6d03374e06fd7c23db67d9c | |
parent | 627631bf9a403d39663a3c33a8e4b13147996639 (diff) |
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
-rw-r--r-- | lib/commonio.c | 5 |
1 files 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); } |