2 .\" Copyright (c) 1996 Brian Somers <brian@awfulhak.demon.co.uk>
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 .\" $FreeBSD: src/lib/libutil/uucplock.3,v 1.13.2.4 2001/12/17 10:08:32 ru Exp $
35 .Nd acquire and release control of a serial device
42 .Fn uu_lock "const char *ttyname"
44 .Fn uu_lock_txfr "const char *ttyname" "pid_t pid"
46 .Fn uu_unlock "const char *ttyname"
48 .Fn uu_lockerr "int uu_lockresult"
52 function attempts to create a lock file called
53 .Pa /var/spool/lock/LCK..
54 with a suffix given by the passed
56 If the file already exists, it is expected to contain the process
57 id of the locking program.
59 If the file does not already exist, or the owning process given by
60 the process id found in the lock file is no longer running,
62 will write its own process id into the file and return success.
65 transfers lock ownership to another process.
67 must have previously been successful.
70 removes the lockfile created by
74 Care should be taken that
76 was successful before calling
80 returns an error string representing the error
86 returns 0 on success and -1 on failure.
89 may return any of the following values:
92 The lock is in use by another process.
95 The lock was successfully created.
97 .Dv UU_LOCK_OPEN_ERR :
98 The lock file could not be opened via
101 .Dv UU_LOCK_READ_ERR :
102 The lock file could not be read via
105 .Dv UU_LOCK_CREAT_ERR :
106 Can't create temporary lock file via
109 .Dv UU_LOCK_WRITE_ERR :
110 The current process id could not be written to the lock file via a call to
113 .Dv UU_LOCK_LINK_ERR :
114 Can't link temporary lock file via
117 .Dv UU_LOCK_TRY_ERR :
118 Locking attempts are failed after 5 tries.
124 an empty string is returned.
125 Otherwise, a string specifying
126 the reason for failure is returned.
128 uses the current value of
130 to determine the exact error. Care should be made not to allow
132 to be changed between calls to
138 may return any of the following values:
141 The transfer was successful. The specified process now holds the device
144 .Dv UU_LOCK_OWNER_ERR :
145 The current process does not already own a lock on the specified device.
147 .Dv UU_LOCK_WRITE_ERR :
148 The new process id could not be written to the lock file via a call to
153 returns one of the error values above, the global value
155 can be used to determine the cause. Refer to the respective manual pages
159 will set the global variable
161 to reflect the reason that the lock file could not be removed.
162 Refer to the description of
171 It is possible that a stale lock is not recognised as such if a new
172 processes is assigned the same processes id as the program that left
175 The calling process must have write permissions to the
177 directory. There is no mechanism in place to ensure that the
178 permissions of this directory are the same as those of the
179 serial devices that might be locked.