summaryrefslogtreecommitdiffstats
path: root/usr.bin/lockf
diff options
context:
space:
mode:
authorjdp <jdp@FreeBSD.org>1998-07-08 05:29:05 +0000
committerjdp <jdp@FreeBSD.org>1998-07-08 05:29:05 +0000
commit2756040b8bf0afb2cb87ce31b2b0dfafc62d20c9 (patch)
treec50aab11f319c9823911201baa9007001bacb793 /usr.bin/lockf
parent397a367a3ecff8cf99508842bcd945095408dd52 (diff)
downloadFreeBSD-src-2756040b8bf0afb2cb87ce31b2b0dfafc62d20c9.zip
FreeBSD-src-2756040b8bf0afb2cb87ce31b2b0dfafc62d20c9.tar.gz
Add a "-k" option, to specify that the lock file should be kept
rather than removed. Submitted by: Nick Barnes <Nick.Barnes@pobox.com>
Diffstat (limited to 'usr.bin/lockf')
-rw-r--r--usr.bin/lockf/lockf.119
-rw-r--r--usr.bin/lockf/lockf.c21
2 files changed, 27 insertions, 13 deletions
diff --git a/usr.bin/lockf/lockf.1 b/usr.bin/lockf/lockf.1
index 4ce28cb..36b50de 100644
--- a/usr.bin/lockf/lockf.1
+++ b/usr.bin/lockf/lockf.1
@@ -1,5 +1,5 @@
.\"
-.\" Copyright (C) 1997 John D. Polstra. All rights reserved.
+.\" Copyright (C) 1998 John D. Polstra. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -22,9 +22,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $Id: lockf.1,v 1.4 1997/02/22 19:55:53 peter Exp $
+.\" $Id: lockf.1,v 1.5 1998/03/23 07:44:28 charnier Exp $
.\"
-.Dd January 8, 1997
+.Dd July 7, 1998
.Os FreeBSD
.Dt LOCKF 1
.Sh NAME
@@ -32,7 +32,7 @@
.Nd execute a command while holding a file lock
.Sh SYNOPSIS
.Nm
-.Op Fl s
+.Op Fl ks
.Op Fl t Ar seconds
.Ar file
.Ar command
@@ -51,9 +51,11 @@ After the
.Ar command
completes,
.Nm
-releases the lock and removes the
-.Ar file .
-BSD-style locking is used, as described in
+releases the lock, and removes the
+.Ar file
+unless the
+.Fl k
+option is specified. BSD-style locking is used, as described in
.Xr flock 2 ;
the mere existence of the
.Ar file
@@ -61,6 +63,9 @@ is not considered to constitute a lock.
.Pp
The following options are supported:
.Bl -tag -width Fl
+.It Fl k
+Causes the lock file to be kept (not removed) after the command
+completes.
.It Fl s
Causes
.Nm
diff --git a/usr.bin/lockf/lockf.c b/usr.bin/lockf/lockf.c
index 74f70d9..76b4870 100644
--- a/usr.bin/lockf/lockf.c
+++ b/usr.bin/lockf/lockf.c
@@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: lockf.c,v 1.5 1997/03/29 04:30:37 imp Exp $
+ * $Id: lockf.c,v 1.6 1997/07/22 07:32:23 charnier Exp $
*/
#include <sys/types.h>
@@ -45,6 +45,8 @@ static void usage(void);
static void wait_for_lock(const char *name);
static const char *lockname;
+static int lockfd;
+static int keep;
static volatile sig_atomic_t timed_out;
/*
@@ -54,17 +56,21 @@ int
main(int argc, char **argv)
{
int ch;
- int lockfd;
int silent;
int status;
int waitsec;
pid_t child;
silent = 0;
+ keep = 0;
waitsec = -1; /* Infinite. */
- while ((ch = getopt(argc, argv, "st:")) != -1) {
+ while ((ch = getopt(argc, argv, "skt:")) != -1) {
switch (ch) {
+ case 'k':
+ keep = 1;
+ break;
+
case 's':
silent = 1;
break;
@@ -164,7 +170,10 @@ acquire_lock(const char *name)
static void
cleanup(void)
{
- unlink(lockname);
+ if (keep)
+ flock(lockfd, LOCK_UN);
+ else
+ unlink(lockname);
}
/*
@@ -193,8 +202,8 @@ static void
usage(void)
{
fprintf(stderr,
- "usage: lockf [-s] [-t seconds] file command [arguments]\n");
- exit(EX_USAGE);
+ "usage: lockf [-ks] [-t seconds] file command [arguments]\n");
+ exit(EX_USAGE);
}
/*
OpenPOWER on IntegriCloud