2001-07-15 07:53:42 +00:00
|
|
|
.\"
|
1997-03-30 12:12:20 +00:00
|
|
|
.\" Copyright (c) 1996 Brian Somers <brian@awfulhak.demon.co.uk>
|
2001-07-15 07:53:42 +00:00
|
|
|
.\"
|
1997-03-30 12:12:20 +00:00
|
|
|
.\" All rights reserved.
|
2001-07-15 07:53:42 +00:00
|
|
|
.\"
|
1997-03-30 12:12:20 +00:00
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2001-07-15 07:53:42 +00:00
|
|
|
.\"
|
1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1997-03-30 12:12:20 +00:00
|
|
|
.\" "
|
2020-06-14 05:35:02 +00:00
|
|
|
.Dd May 10, 2020
|
1999-08-15 09:51:25 +00:00
|
|
|
.Dt UUCPLOCK 3
|
2010-04-14 19:08:06 +00:00
|
|
|
.Os
|
1997-03-30 12:12:20 +00:00
|
|
|
.Sh NAME
|
2001-07-15 07:53:42 +00:00
|
|
|
.Nm uu_lock ,
|
1997-04-01 17:44:31 +00:00
|
|
|
.Nm uu_unlock ,
|
|
|
|
.Nm uu_lockerr
|
1997-03-30 12:12:20 +00:00
|
|
|
.Nd acquire and release control of a serial device
|
2000-04-22 16:17:00 +00:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libutil
|
1997-03-30 12:12:20 +00:00
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In sys/types.h
|
|
|
|
.In libutil.h
|
1997-03-30 12:12:20 +00:00
|
|
|
.Ft int
|
1997-05-12 10:36:14 +00:00
|
|
|
.Fn uu_lock "const char *ttyname"
|
1997-03-30 12:12:20 +00:00
|
|
|
.Ft int
|
1998-05-28 23:17:09 +00:00
|
|
|
.Fn uu_lock_txfr "const char *ttyname" "pid_t pid"
|
|
|
|
.Ft int
|
1997-05-12 10:36:14 +00:00
|
|
|
.Fn uu_unlock "const char *ttyname"
|
|
|
|
.Ft const char *
|
1997-03-31 22:51:00 +00:00
|
|
|
.Fn uu_lockerr "int uu_lockresult"
|
1997-03-30 12:12:20 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn uu_lock
|
|
|
|
function attempts to create a lock file called
|
1997-04-01 17:44:31 +00:00
|
|
|
.Pa /var/spool/lock/LCK..
|
1997-03-30 12:12:20 +00:00
|
|
|
with a suffix given by the passed
|
|
|
|
.Fa ttyname .
|
|
|
|
If the file already exists, it is expected to contain the process
|
|
|
|
id of the locking program.
|
|
|
|
.Pp
|
|
|
|
If the file does not already exist, or the owning process given by
|
|
|
|
the process id found in the lock file is no longer running,
|
|
|
|
.Fn uu_lock
|
|
|
|
will write its own process id into the file and return success.
|
|
|
|
.Pp
|
1998-05-28 23:17:09 +00:00
|
|
|
.Fn uu_lock_txfr
|
|
|
|
transfers lock ownership to another process.
|
|
|
|
.Fn uu_lock
|
|
|
|
must have previously been successful.
|
|
|
|
.Pp
|
1997-03-30 12:12:20 +00:00
|
|
|
.Fn uu_unlock
|
|
|
|
removes the lockfile created by
|
|
|
|
.Fn uu_lock
|
|
|
|
for the given
|
|
|
|
.Fa ttyname .
|
|
|
|
Care should be taken that
|
|
|
|
.Fn uu_lock
|
|
|
|
was successful before calling
|
|
|
|
.Fn uu_unlock .
|
1997-03-31 22:51:00 +00:00
|
|
|
.Pp
|
|
|
|
.Fn uu_lockerr
|
|
|
|
returns an error string representing the error
|
|
|
|
.Fa uu_lockresult ,
|
|
|
|
as returned from
|
|
|
|
.Fn uu_lock .
|
1997-03-30 12:12:20 +00:00
|
|
|
.Sh RETURN VALUES
|
1997-03-31 22:51:00 +00:00
|
|
|
.Fn uu_unlock
|
|
|
|
returns 0 on success and -1 on failure.
|
|
|
|
.Pp
|
|
|
|
.Fn uu_lock
|
|
|
|
may return any of the following values:
|
|
|
|
.Pp
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv UU_LOCK_INUSE :
|
1997-03-31 22:51:00 +00:00
|
|
|
The lock is in use by another process.
|
|
|
|
.Pp
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv UU_LOCK_OK :
|
1997-03-31 22:51:00 +00:00
|
|
|
The lock was successfully created.
|
|
|
|
.Pp
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv UU_LOCK_OPEN_ERR :
|
1997-03-31 22:51:00 +00:00
|
|
|
The lock file could not be opened via
|
|
|
|
.Xr open 2 .
|
|
|
|
.Pp
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv UU_LOCK_READ_ERR :
|
1997-03-31 22:51:00 +00:00
|
|
|
The lock file could not be read via
|
|
|
|
.Xr read 2 .
|
|
|
|
.Pp
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv UU_LOCK_CREAT_ERR :
|
2005-02-13 22:25:33 +00:00
|
|
|
Cannot create temporary lock file via
|
1997-08-10 18:42:39 +00:00
|
|
|
.Xr creat 2 .
|
1997-03-31 22:51:00 +00:00
|
|
|
.Pp
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv UU_LOCK_WRITE_ERR :
|
1997-03-31 22:51:00 +00:00
|
|
|
The current process id could not be written to the lock file via a call to
|
|
|
|
.Xr write 2 .
|
|
|
|
.Pp
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv UU_LOCK_LINK_ERR :
|
2005-02-13 22:25:33 +00:00
|
|
|
Cannot link temporary lock file via
|
1997-08-10 18:42:39 +00:00
|
|
|
.Xr link 2 .
|
|
|
|
.Pp
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv UU_LOCK_TRY_ERR :
|
1997-08-10 18:42:39 +00:00
|
|
|
Locking attempts are failed after 5 tries.
|
|
|
|
.Pp
|
1997-03-31 22:51:00 +00:00
|
|
|
If a value of
|
|
|
|
.Dv UU_LOCK_OK
|
|
|
|
is passed to
|
|
|
|
.Fn uu_lockerr ,
|
1997-04-02 05:52:22 +00:00
|
|
|
an empty string is returned.
|
1997-04-02 03:38:29 +00:00
|
|
|
Otherwise, a string specifying
|
1997-03-31 22:51:00 +00:00
|
|
|
the reason for failure is returned.
|
|
|
|
.Fn uu_lockerr
|
|
|
|
uses the current value of
|
1997-04-01 17:44:31 +00:00
|
|
|
.Va errno
|
2004-07-02 23:52:20 +00:00
|
|
|
to determine the exact error.
|
|
|
|
Care should be made not to allow
|
1997-04-01 17:44:31 +00:00
|
|
|
.Va errno
|
1997-03-31 22:51:00 +00:00
|
|
|
to be changed between calls to
|
1997-03-30 12:12:20 +00:00
|
|
|
.Fn uu_lock
|
|
|
|
and
|
1997-03-31 22:51:00 +00:00
|
|
|
.Fn uu_lockerr .
|
1998-05-28 23:17:09 +00:00
|
|
|
.Pp
|
|
|
|
.Fn uu_lock_txfr
|
|
|
|
may return any of the following values:
|
|
|
|
.Pp
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv UU_LOCK_OK :
|
2004-07-02 23:52:20 +00:00
|
|
|
The transfer was successful.
|
|
|
|
The specified process now holds the device
|
1998-05-28 23:17:09 +00:00
|
|
|
lock.
|
|
|
|
.Pp
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv UU_LOCK_OWNER_ERR :
|
1998-05-28 23:17:09 +00:00
|
|
|
The current process does not already own a lock on the specified device.
|
|
|
|
.Pp
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv UU_LOCK_WRITE_ERR :
|
1998-05-28 23:17:09 +00:00
|
|
|
The new process id could not be written to the lock file via a call to
|
|
|
|
.Xr write 2 .
|
1997-03-30 12:12:20 +00:00
|
|
|
.Sh ERRORS
|
1997-03-31 22:51:00 +00:00
|
|
|
If
|
1997-03-30 12:12:20 +00:00
|
|
|
.Fn uu_lock
|
1998-05-28 23:17:09 +00:00
|
|
|
returns one of the error values above, the global value
|
1997-04-01 17:44:31 +00:00
|
|
|
.Va errno
|
2004-07-02 23:52:20 +00:00
|
|
|
can be used to determine the cause.
|
|
|
|
Refer to the respective manual pages
|
1997-03-31 22:51:00 +00:00
|
|
|
for further details.
|
1997-03-30 12:12:20 +00:00
|
|
|
.Pp
|
|
|
|
.Fn uu_unlock
|
|
|
|
will set the global variable
|
1997-04-01 17:44:31 +00:00
|
|
|
.Va errno
|
1997-03-30 12:12:20 +00:00
|
|
|
to reflect the reason that the lock file could not be removed.
|
|
|
|
Refer to the description of
|
|
|
|
.Xr unlink 2
|
|
|
|
for further details.
|
1997-03-31 22:51:00 +00:00
|
|
|
.Sh SEE ALSO
|
1997-09-29 19:11:55 +00:00
|
|
|
.Xr lseek 2 ,
|
1997-03-31 22:51:00 +00:00
|
|
|
.Xr open 2 ,
|
|
|
|
.Xr read 2 ,
|
|
|
|
.Xr write 2
|
2020-06-14 05:35:02 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
The functions
|
|
|
|
.Fn uu_lock ,
|
|
|
|
.Fn uu_unlock
|
|
|
|
and
|
|
|
|
.Fn uu_lockerr
|
|
|
|
first appeared in
|
|
|
|
.Fx 2.0.5 .
|
1997-03-30 12:12:20 +00:00
|
|
|
.Sh BUGS
|
|
|
|
It is possible that a stale lock is not recognised as such if a new
|
|
|
|
processes is assigned the same processes id as the program that left
|
|
|
|
the stale lock.
|
|
|
|
.Pp
|
|
|
|
The calling process must have write permissions to the
|
1997-04-01 17:44:31 +00:00
|
|
|
.Pa /var/spool/lock
|
2004-07-02 23:52:20 +00:00
|
|
|
directory.
|
|
|
|
There is no mechanism in place to ensure that the
|
1997-03-30 12:12:20 +00:00
|
|
|
permissions of this directory are the same as those of the
|
|
|
|
serial devices that might be locked.
|