xref: /dragonfly/usr.bin/lockf/lockf.1 (revision 0cfebe3d)
1.\"
2.\" Copyright (C) 1998 John D. Polstra.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY JOHN D. POLSTRA AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL JOHN D. POLSTRA OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD: src/usr.bin/lockf/lockf.1,v 1.7.2.4 2002/06/21 15:27:51 charnier Exp $
26.\" $DragonFly: src/usr.bin/lockf/lockf.1,v 1.2 2003/06/17 04:29:28 dillon Exp $
27.\"
28.Dd July 7, 1998
29.Os
30.Dt LOCKF 1
31.Sh NAME
32.Nm lockf
33.Nd execute a command while holding a file lock
34.Sh SYNOPSIS
35.Nm
36.Op Fl ks
37.Op Fl t Ar seconds
38.Ar file
39.Ar command
40.Op Ar arguments
41.Sh DESCRIPTION
42The
43.Nm
44utility acquires an exclusive lock on a
45.Ar file ,
46creating it if necessary.
47While holding the lock, it executes a
48.Ar command
49with optional
50.Ar arguments .
51After the
52.Ar command
53completes,
54.Nm
55releases the lock, and removes the
56.Ar file
57unless the
58.Fl k
59option is specified.
60.Bx Ns -style
61locking is used, as described in
62.Xr flock 2 ;
63the mere existence of the
64.Ar file
65is not considered to constitute a lock.
66.Pp
67The following options are supported:
68.Bl -tag -width Fl
69.It Fl k
70Causes the lock file to be kept (not removed) after the command
71completes.
72.It Fl s
73Causes
74.Nm
75to operate silently.
76Failure to acquire the lock is indicated only in the exit status.
77.It Fl t Ar seconds
78Specifies a timeout for waiting for the lock.  By default,
79.Nm
80waits indefinitely to acquire the lock.
81If a timeout is specified with this option,
82.Nm
83will wait at most the given number of
84.Ar seconds
85before giving up.  A timeout of 0 may be given, in which case
86.Nm
87will fail unless it can acquire the lock immediately.
88.El
89.Pp
90In no event will
91.Nm
92break a lock that is held by another process.
93.Sh DIAGNOSTICS
94If
95.Nm
96successfully acquires the lock, it returns the exit status produced by
97.Ar command .
98Otherwise, it returns one of the exit codes defined in
99.Xr sysexits 3 ,
100as follows:
101.Bl -tag -width F_CANTCREATX
102.It Dv EX_TEMPFAIL
103The specified lock file was already locked by another process.
104.It Dv EX_CANTCREAT
105The
106.Nm
107utility
108was unable to create the lock file, e.g., because of insufficient access
109privileges.
110.It Dv EX_USAGE
111There was an error on the
112.Nm
113command line.
114.It Dv EX_OSERR
115A system call (e.g., fork) failed unexpectedly.
116.El
117.Sh SEE ALSO
118.Xr flock 2 ,
119.Xr sysexits 3
120.Sh HISTORY
121A
122.Nm
123utility first appeared in
124.Fx 2.2 .
125.Sh AUTHORS
126.An John Polstra Aq jdp@polstra.com .
127