UUCPLOCK(3)
UUCPLOCK(3) π
okay bestie, welcome to the Library Functions Manual page for the serial-device lock girlies. this one is all about acquiring and releasing control of a serial device, and it is lowkey a whole vibe. letβs get into it. π¦
π NAME π
uu_lock, uu_lock_txfr, uu_unlock, uu_lockerr β the little squad that handles acquiring and releasing control of a serial device. periodt. β¨
π LIBRARY π
System Utilities Library (libutil, -lutil) β yes bestie, thatβs the one. link it with -lutil. π«Ά
πΈ SYNOPSIS πΈ
#include <sys/types.h>
#include <libutil.h>
int
uu_lock(const char *ttyname);
int
uu_lock_txfr(const char *ttyname, pid_t pid);
int
uu_unlock(const char *ttyname);
const char *
uu_lockerr(int uu_lockresult);
π DESCRIPTION π
the uu_lock() function tries to create a lock file called /var/spool/lock/LCK.. with a suffix given by the passed ttyname. if that file already exists, it is expected to contain the process id of the locking program. like, thatβs the whole point. π
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, uu_lock() will write its own process id into the file and return success. slay. β
uu_lock_txfr() transfers lock ownership to another process. uu_lock() must have previously been successful. no skipping steps, bestie. π
uu_unlock() removes the lockfile created by uu_lock() for the given ttyname. care should be taken that uu_lock() was successful before calling uu_unlock(). like pls check first, okay? π
uu_lockerr() returns an error string representing the error uu_lockresult, as returned from uu_lock(). itβs giving βtranslator for your lock result.β π§
π₯ RETURN VALUES π₯
uu_unlock() returns 0 on success and -1 on failure. simple. iconic. π
uu_lock() may return any of the following values:
UU_LOCK_INUSEβ the lock is in use by another process. someone else has the aux cord. πUU_LOCK_OKβ the lock was successfully created. we love a win. πUU_LOCK_OPEN_ERRβ the lock file could not be opened viaopen(2).UU_LOCK_READ_ERRβ the lock file could not be read viaread(2).UU_LOCK_CREAT_ERRβ cannot create temporary lock file viacreat(2).UU_LOCK_WRITE_ERRβ the current process id could not be written to the lock file via a call towrite(2).UU_LOCK_LINK_ERRβ cannot link temporary lock file vialink(2).UU_LOCK_TRY_ERRβ locking attempts are failed after5tries. five strikes and youβre out, bestie. π
if a value of UU_LOCK_OK is passed to uu_lockerr(), an empty string is returned. otherwise, a string specifying the reason for failure is returned. uu_lockerr() uses the current value of errno to determine the exact error.
care should be made not to allowerrnoto be changed between calls touu_lock()anduu_lockerr(). like do not let anything mess with it in between. thatβs the rule. π«Ά
uu_lock_txfr() may return any of the following values:
UU_LOCK_OKβ the transfer was successful. the specified process now holds the device lock. handing over the crown. πUU_LOCK_OWNER_ERRβ the current process does not already own a lock on the specified device. you canβt transfer what you donβt have, bestie. πUU_LOCK_WRITE_ERRβ the new process id could not be written to the lock file via a call towrite(2).
β οΈ ERRORS β οΈ
if uu_lock() returns one of the error values above, the global value errno can be used to determine the cause. refer to the respective manual pages for further details. iykyk. π
uu_unlock() will set the global variable errno to reflect the reason that the lock file could not be removed. refer to the description of unlink(2) for further details. yes, that unlink(2). π
π¦ SEE ALSO π¦
lseek(2), open(2), read(2), write(2)
π HISTORY π
the functions uu_lock(), uu_unlock() and uu_lockerr() first appeared in FreeBSD 2.0.5. vintage. iconic. ate. β¨
π BUGS π
it is possible that a stale lock is not recognised as such if a new process is assigned the same process id as the program that left the stale lock. yes, that can happen. awkward. π
the calling process must have write permissions to the /var/spool/lock directory. there is no mechanism in place to ensure that the permissions of this directory are the same as those of the serial devices that might be locked. so like, permissions check yourself before you wreck yourself. π«Ά
okay bye bestie β this page is Debian, dated May 10, 2020, and you already know the title: UUCPLOCK(3). mwah. ππ
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 1996 Brian Somers <brian@awfulhak.demon.co.uk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms