From 2f9a114be45ff3e3edad000105a76b6b5ca01051 Mon Sep 17 00:00:00 2001 From: avos Date: Wed, 27 Mar 2019 08:55:59 +0000 Subject: [PATCH] MFC r345318: lockf(1): return EX_UNAVAILABLE if -n is used and the lock file does not exist Apply EX_UNAVAILABLE patch part from PR 170775 to match the documentation. Was checked with a command from PR 210770: lockf -n /tmp/doesnotexist echo; echo $? PR: 210770 --- usr.bin/lockf/lockf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/usr.bin/lockf/lockf.c b/usr.bin/lockf/lockf.c index 471bedf9ed7..b0265531689 100644 --- a/usr.bin/lockf/lockf.c +++ b/usr.bin/lockf/lockf.c @@ -174,6 +174,8 @@ acquire_lock(const char *name, int flags) if ((fd = open(name, O_RDONLY|O_EXLOCK|flags, 0666)) == -1) { if (errno == EAGAIN || errno == EINTR) return (-1); + else if (errno == ENOENT && (flags & O_CREAT) == 0) + err(EX_UNAVAILABLE, "%s", name); err(EX_CANTCREAT, "cannot open %s", name); } return (fd); -- 2.45.0