From e52068f0b8eea73b66ff6b2f7fd520291fb8b0be 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 git-svn-id: svn://svn.freebsd.org/base/stable/10@345569 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- 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 5555c488c..906f2d030 100644 --- a/usr.bin/lockf/lockf.c +++ b/usr.bin/lockf/lockf.c @@ -172,6 +172,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