[Midnightbsd-cvs] src [11494] trunk/usr.bin/lockf/lockf.c: add s flag
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Jul 7 13:33:07 EDT 2018
Revision: 11494
http://svnweb.midnightbsd.org/src/?rev=11494
Author: laffer1
Date: 2018-07-07 13:33:06 -0400 (Sat, 07 Jul 2018)
Log Message:
-----------
add s flag
Modified Paths:
--------------
trunk/usr.bin/lockf/Makefile
trunk/usr.bin/lockf/lockf.1
trunk/usr.bin/lockf/lockf.c
Property Changed:
----------------
trunk/usr.bin/lockf/lockf.1
Modified: trunk/usr.bin/lockf/Makefile
===================================================================
--- trunk/usr.bin/lockf/Makefile 2018-07-07 17:32:54 UTC (rev 11493)
+++ trunk/usr.bin/lockf/Makefile 2018-07-07 17:33:06 UTC (rev 11494)
@@ -1,4 +1,5 @@
# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/lockf/Makefile 90415 2002-02-08 22:31:43Z markm $
PROG= lockf
Modified: trunk/usr.bin/lockf/lockf.1
===================================================================
--- trunk/usr.bin/lockf/lockf.1 2018-07-07 17:32:54 UTC (rev 11493)
+++ trunk/usr.bin/lockf/lockf.1 2018-07-07 17:33:06 UTC (rev 11494)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\"
.\" Copyright (C) 1998 John D. Polstra. All rights reserved.
.\"
@@ -22,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/lockf/lockf.1 250462 2013-05-10 17:30:29Z eadler $
.\"
.Dd July 7, 1998
.Dt LOCKF 1
@@ -32,7 +33,7 @@
.Nd execute a command while holding a file lock
.Sh SYNOPSIS
.Nm
-.Op Fl ks
+.Op Fl kns
.Op Fl t Ar seconds
.Ar file
.Ar command
@@ -90,6 +91,18 @@
.Nm
to operate silently.
Failure to acquire the lock is indicated only in the exit status.
+.It Fl n
+Causes
+.Nm
+to fail if the specified lock
+.Ar file
+does not exist. If
+.Fl n
+is not specified,
+.Nm
+will create
+.Ar file
+if necessary.
.It Fl t Ar seconds
Specifies a timeout for waiting for the lock.
By default,
@@ -130,6 +143,10 @@
utility
was unable to create the lock file, e.g., because of insufficient access
privileges.
+.It Dv EX_UNAVAILABLE
+The
+.Fl n
+option is specified and the specified lock file does not exist.
.It Dv EX_USAGE
There was an error on the
.Nm
Property changes on: trunk/usr.bin/lockf/lockf.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/lockf/lockf.c
===================================================================
--- trunk/usr.bin/lockf/lockf.c 2018-07-07 17:32:54 UTC (rev 11493)
+++ trunk/usr.bin/lockf/lockf.c 2018-07-07 17:33:06 UTC (rev 11494)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (C) 1997 John D. Polstra. All rights reserved.
*
@@ -24,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/lockf/lockf.c 281896 2015-04-23 15:24:33Z bdrewery $");
#include <sys/types.h>
#include <sys/wait.h>
@@ -56,16 +57,20 @@
int
main(int argc, char **argv)
{
- int ch, silent, status, waitsec;
+ int ch, flags, silent, status, waitsec;
pid_t child;
silent = keep = 0;
+ flags = O_CREAT;
waitsec = -1; /* Infinite. */
- while ((ch = getopt(argc, argv, "skt:")) != -1) {
+ while ((ch = getopt(argc, argv, "sknt:")) != -1) {
switch (ch) {
case 'k':
keep = 1;
break;
+ case 'n':
+ flags &= ~O_CREAT;
+ break;
case 's':
silent = 1;
break;
@@ -118,13 +123,13 @@
* avoiding the separate step of waiting for the lock. This
* yields fairness and improved performance.
*/
- lockfd = acquire_lock(lockname, O_NONBLOCK);
+ lockfd = acquire_lock(lockname, flags | O_NONBLOCK);
while (lockfd == -1 && !timed_out && waitsec != 0) {
if (keep)
- lockfd = acquire_lock(lockname, 0);
+ lockfd = acquire_lock(lockname, flags);
else {
wait_for_lock(lockname);
- lockfd = acquire_lock(lockname, O_NONBLOCK);
+ lockfd = acquire_lock(lockname, flags | O_NONBLOCK);
}
}
if (waitsec > 0)
@@ -165,7 +170,7 @@
{
int fd;
- if ((fd = open(name, O_RDONLY|O_CREAT|O_EXLOCK|flags, 0666)) == -1) {
+ if ((fd = open(name, O_RDONLY|O_EXLOCK|flags, 0666)) == -1) {
if (errno == EAGAIN || errno == EINTR)
return (-1);
err(EX_CANTCREAT, "cannot open %s", name);
@@ -215,7 +220,7 @@
{
fprintf(stderr,
- "usage: lockf [-ks] [-t seconds] file command [arguments]\n");
+ "usage: lockf [-kns] [-t seconds] file command [arguments]\n");
exit(EX_USAGE);
}
More information about the Midnightbsd-cvs
mailing list