diff options
-rw-r--r-- | lib/libutil/Makefile | 3 | ||||
-rw-r--r-- | lib/libutil/libutil.h | 4 | ||||
-rw-r--r-- | lib/libutil/uucplock.3 | 25 | ||||
-rw-r--r-- | lib/libutil/uucplock.c | 40 |
4 files changed, 62 insertions, 10 deletions
diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile index aa8ad95..001faf0 100644 --- a/lib/libutil/Makefile +++ b/lib/libutil/Makefile @@ -26,7 +26,8 @@ MLINKS+=login_times.3 parse_lt.3 login_times.3 in_ltm.3 \ login_times.3 in_lts.3 MLINKS+=login_ok.3 auth_ttyok.3 login_ok.3 auth_hostok.3 \ login_ok.3 auth_timeok.3 -MLINKS+=uucplock.3 uu_lock.3 uucplock.3 uu_unlock.3 uucplock.3 uu_lockerr.3 +MLINKS+=uucplock.3 uu_lock.3 uucplock.3 uu_lock_txfr.3 \ + uucplock.3 uu_unlock.3 uucplock.3 uu_lockerr.3 beforeinstall: ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/libutil.h \ diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h index 8a96284..513acee 100644 --- a/lib/libutil/libutil.h +++ b/lib/libutil/libutil.h @@ -18,7 +18,7 @@ * 5. Modifications may be freely made to this file providing the above * conditions are met. * - * $Id: libutil.h,v 1.12 1997/08/31 20:09:38 brian Exp $ + * $Id: libutil.h,v 1.13 1997/09/04 22:38:58 pst Exp $ */ #ifndef _LIBUTIL_H_ @@ -43,6 +43,7 @@ int forkpty __P((int *_amaster, char *_name, struct termios *_termp, struct winsize *_winp)); const char *uu_lockerr __P((int _uu_lockresult)); int uu_lock __P((const char *_ttyname)); +int uu_lock_txfr __P((const char *_ttyname, pid_t _pid)); int uu_unlock __P((const char *_ttyname)); int _secure_path __P((const char *_path, uid_t _uid, gid_t _gid)); __END_DECLS @@ -55,5 +56,6 @@ __END_DECLS #define UU_LOCK_WRITE_ERR (-4) #define UU_LOCK_LINK_ERR (-5) #define UU_LOCK_TRY_ERR (-6) +#define UU_LOCK_OWNER_ERR (-7) #endif /* !_LIBUTIL_H_ */ diff --git a/lib/libutil/uucplock.3 b/lib/libutil/uucplock.3 index c920e4a..563323c 100644 --- a/lib/libutil/uucplock.3 +++ b/lib/libutil/uucplock.3 @@ -23,7 +23,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $Id: uucplock.3,v 1.9 1997/09/29 19:11:25 wosch Exp $ +.\" $Id: uucplock.3,v 1.10 1997/10/07 07:24:50 joerg Exp $ .\" " .Dd March 30, 1997 .Os @@ -39,6 +39,8 @@ .Ft int .Fn uu_lock "const char *ttyname" .Ft int +.Fn uu_lock_txfr "const char *ttyname" "pid_t pid" +.Ft int .Fn uu_unlock "const char *ttyname" .Ft const char * .Fn uu_lockerr "int uu_lockresult" @@ -63,6 +65,11 @@ 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 +.Fn uu_lock_txfr +transfers lock ownership to another process. +.Fn uu_lock +must have previously been successful. +.Pp .Fn uu_unlock removes the lockfile created by .Fn uu_lock @@ -130,10 +137,24 @@ to be changed between calls to .Fn uu_lock and .Fn uu_lockerr . +.Pp +.Fn uu_lock_txfr +may return any of the following values: +.Pp +.Dv UU_LOCK_OK: +The transfer was successful. The specified process now holds the device +lock. +.Pp +.Dv UU_LOCK_OWNER_ERR: +The current process does not already own a lock on the specified device. +.Pp +.Dv UU_LOCK_WRITE_ERR: +The new process id could not be written to the lock file via a call to +.Xr write 2 . .Sh ERRORS If .Fn uu_lock -returns one of the four error values above, the global value +returns one of the error values above, the global value .Va errno can be used to determine the cause. Refer to the respective manual pages for further details. diff --git a/lib/libutil/uucplock.c b/lib/libutil/uucplock.c index 8e037e4..9f33524 100644 --- a/lib/libutil/uucplock.c +++ b/lib/libutil/uucplock.c @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uucplock.c,v 1.7 1997/08/05 12:58:02 ache Exp $ + * $Id: uucplock.c,v 1.8 1997/08/10 18:42:39 ache Exp $ * */ @@ -66,7 +66,8 @@ static pid_t get_pid (int fd,int *err); * uucp style locking routines */ -int uu_lock (const char *ttyname) +int +uu_lock(const char *ttyname) { int fd, tmpfd, i; pid_t pid; @@ -127,7 +128,28 @@ ret0: return uuerr; } -int uu_unlock (const char *ttyname) +int +uu_lock_txfr(const char *ttyname, pid_t pid) +{ + int fd, err; + char lckname[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN]; + + snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, ttyname); + + if ((fd = open(lckname, O_RDWR)) < 0) + return UU_LOCK_OWNER_ERR; + if (get_pid(fd, &err) != getpid()) + return UU_LOCK_OWNER_ERR; + lseek(fd, 0, SEEK_SET); + if (put_pid(fd, pid)) + return UU_LOCK_WRITE_ERR; + close(fd); + + return UU_LOCK_OK; +} + +int +uu_unlock(const char *ttyname) { char tbuf[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN]; @@ -135,7 +157,8 @@ int uu_unlock (const char *ttyname) return unlink(tbuf); } -const char *uu_lockerr (int uu_lockresult) +const char * +uu_lockerr(int uu_lockresult) { static char errbuf[128]; char *fmt; @@ -163,6 +186,9 @@ const char *uu_lockerr (int uu_lockresult) case UU_LOCK_TRY_ERR: fmt = "too many tries: %s"; break; + case UU_LOCK_OWNER_ERR: + fmt = "not locking process: %s"; + break; default: fmt = "undefined error: %s"; break; @@ -172,7 +198,8 @@ const char *uu_lockerr (int uu_lockresult) return errbuf; } -static int put_pid (int fd, pid_t pid) +static int +put_pid(int fd, pid_t pid) { char buf[32]; int len; @@ -181,7 +208,8 @@ static int put_pid (int fd, pid_t pid) return write (fd, buf, len) == len; } -static pid_t get_pid (int fd, int *err) +static pid_t +get_pid(int fd, int *err) { int bytes_read; char buf[32]; |