diff options
-rw-r--r-- | lib/libutil/Makefile | 3 | ||||
-rw-r--r-- | lib/libutil/shlib_version | 2 | ||||
-rw-r--r-- | lib/libutil/util.h | 4 | ||||
-rw-r--r-- | lib/libutil/uucplock.3 | 25 | ||||
-rw-r--r-- | lib/libutil/uucplock.c | 27 |
5 files changed, 55 insertions, 6 deletions
diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile index ca526ded95f..cb39be8829f 100644 --- a/lib/libutil/Makefile +++ b/lib/libutil/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.15 1997/11/09 00:29:13 bri Exp $ +# $OpenBSD: Makefile,v 1.16 1998/06/08 20:28:23 brian Exp $ # $NetBSD: Makefile,v 1.8 1996/05/16 07:03:28 thorpej Exp $ LIB= util @@ -40,6 +40,7 @@ MLINKS+=scsi.3 scsi_debug_output.3 MLINKS+=uucplock.3 uu_lock.3 MLINKS+=uucplock.3 uu_unlock.3 MLINKS+=uucplock.3 uu_lockerr.3 +MLINKS+=uucplock.3 uu_lock_txfr.3 includes: @cd ${.CURDIR}; for i in $(HDRS); do \ diff --git a/lib/libutil/shlib_version b/lib/libutil/shlib_version index 890c57389b5..f89dbabf714 100644 --- a/lib/libutil/shlib_version +++ b/lib/libutil/shlib_version @@ -1,2 +1,2 @@ major=4 -minor=1 +minor=2 diff --git a/lib/libutil/util.h b/lib/libutil/util.h index 9fd98e23862..3f40ce91d0f 100644 --- a/lib/libutil/util.h +++ b/lib/libutil/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.7 1997/11/09 00:29:14 bri Exp $ */ +/* $OpenBSD: util.h,v 1.8 1998/06/08 20:28:28 brian Exp $ */ /* $NetBSD: util.h,v 1.2 1996/05/16 07:00:22 thorpej Exp $ */ /*- @@ -78,6 +78,7 @@ void login_fbtab __P((char *, uid_t, gid_t)); char *readlabelfs __P((char *, int)); 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)); __END_DECLS @@ -89,5 +90,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 /* !_UTIL_H_ */ diff --git a/lib/libutil/uucplock.3 b/lib/libutil/uucplock.3 index 40eeab60847..5bb1fa51e08 100644 --- a/lib/libutil/uucplock.3 +++ b/lib/libutil/uucplock.3 @@ -21,7 +21,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.1 1997/11/09 00:29:14 bri Exp $ +.\" $Id: uucplock.3,v 1.2 1998/06/08 20:28:29 brian Exp $ .\" " .Dd March 30, 1997 .Os @@ -37,6 +37,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" @@ -61,6 +63,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 @@ -128,10 +135,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 e75424f36d0..7bcbc4309d4 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.2 1997/11/09 04:05:33 bri Exp $ + * $Id: uucplock.c,v 1.3 1998/06/08 20:28:30 brian Exp $ * */ @@ -130,6 +130,28 @@ ret0: } int +uu_lock_txfr(ttyname, pid) + 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(ttyname) const char *ttyname; { @@ -169,6 +191,9 @@ uu_lockerr(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; |