xref: /f-stack/tools/libutil/uucplock.3 (revision 22ce4aff)
11eaf0ac3Slogwang.\"
21eaf0ac3Slogwang.\" Copyright (c) 1996 Brian Somers <[email protected]>
31eaf0ac3Slogwang.\"
41eaf0ac3Slogwang.\" All rights reserved.
51eaf0ac3Slogwang.\"
61eaf0ac3Slogwang.\" Redistribution and use in source and binary forms, with or without
71eaf0ac3Slogwang.\" modification, are permitted provided that the following conditions
81eaf0ac3Slogwang.\" are met:
91eaf0ac3Slogwang.\" 1. Redistributions of source code must retain the above copyright
101eaf0ac3Slogwang.\"    notice, this list of conditions and the following disclaimer.
111eaf0ac3Slogwang.\" 2. Redistributions in binary form must reproduce the above copyright
121eaf0ac3Slogwang.\"    notice, this list of conditions and the following disclaimer in the
131eaf0ac3Slogwang.\"    documentation and/or other materials provided with the distribution.
141eaf0ac3Slogwang.\"
151eaf0ac3Slogwang.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
161eaf0ac3Slogwang.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171eaf0ac3Slogwang.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
181eaf0ac3Slogwang.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
191eaf0ac3Slogwang.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201eaf0ac3Slogwang.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
211eaf0ac3Slogwang.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
221eaf0ac3Slogwang.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231eaf0ac3Slogwang.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
241eaf0ac3Slogwang.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
251eaf0ac3Slogwang.\"
261eaf0ac3Slogwang.\" $FreeBSD$
271eaf0ac3Slogwang.\" "
28*22ce4affSfengbojiang.Dd May 10, 2020
291eaf0ac3Slogwang.Dt UUCPLOCK 3
301eaf0ac3Slogwang.Os
311eaf0ac3Slogwang.Sh NAME
321eaf0ac3Slogwang.Nm uu_lock ,
331eaf0ac3Slogwang.Nm uu_unlock ,
341eaf0ac3Slogwang.Nm uu_lockerr
351eaf0ac3Slogwang.Nd acquire and release control of a serial device
361eaf0ac3Slogwang.Sh LIBRARY
371eaf0ac3Slogwang.Lb libutil
381eaf0ac3Slogwang.Sh SYNOPSIS
391eaf0ac3Slogwang.In sys/types.h
401eaf0ac3Slogwang.In libutil.h
411eaf0ac3Slogwang.Ft int
421eaf0ac3Slogwang.Fn uu_lock "const char *ttyname"
431eaf0ac3Slogwang.Ft int
441eaf0ac3Slogwang.Fn uu_lock_txfr "const char *ttyname" "pid_t pid"
451eaf0ac3Slogwang.Ft int
461eaf0ac3Slogwang.Fn uu_unlock "const char *ttyname"
471eaf0ac3Slogwang.Ft const char *
481eaf0ac3Slogwang.Fn uu_lockerr "int uu_lockresult"
491eaf0ac3Slogwang.Sh DESCRIPTION
501eaf0ac3SlogwangThe
511eaf0ac3Slogwang.Fn uu_lock
521eaf0ac3Slogwangfunction attempts to create a lock file called
531eaf0ac3Slogwang.Pa /var/spool/lock/LCK..
541eaf0ac3Slogwangwith a suffix given by the passed
551eaf0ac3Slogwang.Fa ttyname .
561eaf0ac3SlogwangIf the file already exists, it is expected to contain the process
571eaf0ac3Slogwangid of the locking program.
581eaf0ac3Slogwang.Pp
591eaf0ac3SlogwangIf the file does not already exist, or the owning process given by
601eaf0ac3Slogwangthe process id found in the lock file is no longer running,
611eaf0ac3Slogwang.Fn uu_lock
621eaf0ac3Slogwangwill write its own process id into the file and return success.
631eaf0ac3Slogwang.Pp
641eaf0ac3Slogwang.Fn uu_lock_txfr
651eaf0ac3Slogwangtransfers lock ownership to another process.
661eaf0ac3Slogwang.Fn uu_lock
671eaf0ac3Slogwangmust have previously been successful.
681eaf0ac3Slogwang.Pp
691eaf0ac3Slogwang.Fn uu_unlock
701eaf0ac3Slogwangremoves the lockfile created by
711eaf0ac3Slogwang.Fn uu_lock
721eaf0ac3Slogwangfor the given
731eaf0ac3Slogwang.Fa ttyname .
741eaf0ac3SlogwangCare should be taken that
751eaf0ac3Slogwang.Fn uu_lock
761eaf0ac3Slogwangwas successful before calling
771eaf0ac3Slogwang.Fn uu_unlock .
781eaf0ac3Slogwang.Pp
791eaf0ac3Slogwang.Fn uu_lockerr
801eaf0ac3Slogwangreturns an error string representing the error
811eaf0ac3Slogwang.Fa uu_lockresult ,
821eaf0ac3Slogwangas returned from
831eaf0ac3Slogwang.Fn uu_lock .
841eaf0ac3Slogwang.Sh RETURN VALUES
851eaf0ac3Slogwang.Fn uu_unlock
861eaf0ac3Slogwangreturns 0 on success and -1 on failure.
871eaf0ac3Slogwang.Pp
881eaf0ac3Slogwang.Fn uu_lock
891eaf0ac3Slogwangmay return any of the following values:
901eaf0ac3Slogwang.Pp
911eaf0ac3Slogwang.Dv UU_LOCK_INUSE :
921eaf0ac3SlogwangThe lock is in use by another process.
931eaf0ac3Slogwang.Pp
941eaf0ac3Slogwang.Dv UU_LOCK_OK :
951eaf0ac3SlogwangThe lock was successfully created.
961eaf0ac3Slogwang.Pp
971eaf0ac3Slogwang.Dv UU_LOCK_OPEN_ERR :
981eaf0ac3SlogwangThe lock file could not be opened via
991eaf0ac3Slogwang.Xr open 2 .
1001eaf0ac3Slogwang.Pp
1011eaf0ac3Slogwang.Dv UU_LOCK_READ_ERR :
1021eaf0ac3SlogwangThe lock file could not be read via
1031eaf0ac3Slogwang.Xr read 2 .
1041eaf0ac3Slogwang.Pp
1051eaf0ac3Slogwang.Dv UU_LOCK_CREAT_ERR :
1061eaf0ac3SlogwangCannot create temporary lock file via
1071eaf0ac3Slogwang.Xr creat 2 .
1081eaf0ac3Slogwang.Pp
1091eaf0ac3Slogwang.Dv UU_LOCK_WRITE_ERR :
1101eaf0ac3SlogwangThe current process id could not be written to the lock file via a call to
1111eaf0ac3Slogwang.Xr write 2 .
1121eaf0ac3Slogwang.Pp
1131eaf0ac3Slogwang.Dv UU_LOCK_LINK_ERR :
1141eaf0ac3SlogwangCannot link temporary lock file via
1151eaf0ac3Slogwang.Xr link 2 .
1161eaf0ac3Slogwang.Pp
1171eaf0ac3Slogwang.Dv UU_LOCK_TRY_ERR :
1181eaf0ac3SlogwangLocking attempts are failed after 5 tries.
1191eaf0ac3Slogwang.Pp
1201eaf0ac3SlogwangIf a value of
1211eaf0ac3Slogwang.Dv UU_LOCK_OK
1221eaf0ac3Slogwangis passed to
1231eaf0ac3Slogwang.Fn uu_lockerr ,
1241eaf0ac3Slogwangan empty string is returned.
1251eaf0ac3SlogwangOtherwise, a string specifying
1261eaf0ac3Slogwangthe reason for failure is returned.
1271eaf0ac3Slogwang.Fn uu_lockerr
1281eaf0ac3Slogwanguses the current value of
1291eaf0ac3Slogwang.Va errno
1301eaf0ac3Slogwangto determine the exact error.
1311eaf0ac3SlogwangCare should be made not to allow
1321eaf0ac3Slogwang.Va errno
1331eaf0ac3Slogwangto be changed between calls to
1341eaf0ac3Slogwang.Fn uu_lock
1351eaf0ac3Slogwangand
1361eaf0ac3Slogwang.Fn uu_lockerr .
1371eaf0ac3Slogwang.Pp
1381eaf0ac3Slogwang.Fn uu_lock_txfr
1391eaf0ac3Slogwangmay return any of the following values:
1401eaf0ac3Slogwang.Pp
1411eaf0ac3Slogwang.Dv UU_LOCK_OK :
1421eaf0ac3SlogwangThe transfer was successful.
1431eaf0ac3SlogwangThe specified process now holds the device
1441eaf0ac3Slogwanglock.
1451eaf0ac3Slogwang.Pp
1461eaf0ac3Slogwang.Dv UU_LOCK_OWNER_ERR :
1471eaf0ac3SlogwangThe current process does not already own a lock on the specified device.
1481eaf0ac3Slogwang.Pp
1491eaf0ac3Slogwang.Dv UU_LOCK_WRITE_ERR :
1501eaf0ac3SlogwangThe new process id could not be written to the lock file via a call to
1511eaf0ac3Slogwang.Xr write 2 .
1521eaf0ac3Slogwang.Sh ERRORS
1531eaf0ac3SlogwangIf
1541eaf0ac3Slogwang.Fn uu_lock
1551eaf0ac3Slogwangreturns one of the error values above, the global value
1561eaf0ac3Slogwang.Va errno
1571eaf0ac3Slogwangcan be used to determine the cause.
1581eaf0ac3SlogwangRefer to the respective manual pages
1591eaf0ac3Slogwangfor further details.
1601eaf0ac3Slogwang.Pp
1611eaf0ac3Slogwang.Fn uu_unlock
1621eaf0ac3Slogwangwill set the global variable
1631eaf0ac3Slogwang.Va errno
1641eaf0ac3Slogwangto reflect the reason that the lock file could not be removed.
1651eaf0ac3SlogwangRefer to the description of
1661eaf0ac3Slogwang.Xr unlink 2
1671eaf0ac3Slogwangfor further details.
1681eaf0ac3Slogwang.Sh SEE ALSO
1691eaf0ac3Slogwang.Xr lseek 2 ,
1701eaf0ac3Slogwang.Xr open 2 ,
1711eaf0ac3Slogwang.Xr read 2 ,
1721eaf0ac3Slogwang.Xr write 2
173*22ce4affSfengbojiang.Sh HISTORY
174*22ce4affSfengbojiangThe functions
175*22ce4affSfengbojiang.Fn uu_lock ,
176*22ce4affSfengbojiang.Fn uu_unlock
177*22ce4affSfengbojiangand
178*22ce4affSfengbojiang.Fn uu_lockerr
179*22ce4affSfengbojiangfirst appeared in
180*22ce4affSfengbojiang.Fx 2.0.5 .
1811eaf0ac3Slogwang.Sh BUGS
1821eaf0ac3SlogwangIt is possible that a stale lock is not recognised as such if a new
1831eaf0ac3Slogwangprocesses is assigned the same processes id as the program that left
1841eaf0ac3Slogwangthe stale lock.
1851eaf0ac3Slogwang.Pp
1861eaf0ac3SlogwangThe calling process must have write permissions to the
1871eaf0ac3Slogwang.Pa /var/spool/lock
1881eaf0ac3Slogwangdirectory.
1891eaf0ac3SlogwangThere is no mechanism in place to ensure that the
1901eaf0ac3Slogwangpermissions of this directory are the same as those of the
1911eaf0ac3Slogwangserial devices that might be locked.
192