diff --git a/usr.bin/lockf/lockf.1 b/usr.bin/lockf/lockf.1 index 4ce28cb62028..36b50de0cc84 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 74f70d9ab553..76b4870634dd 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 @@ -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); } /*