summaryrefslogtreecommitdiffstats
path: root/usr.bin/lockf/lockf.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/lockf/lockf.c')
-rw-r--r--usr.bin/lockf/lockf.c21
1 files changed, 15 insertions, 6 deletions
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