Browse Source

Add uu_lock_txfr() for donating locks to another process.

Reviewed by: Theo
OPENBSD_2_4
brian 26 years ago
parent
commit
6c131f03f8
5 changed files with 55 additions and 6 deletions
  1. +2
    -1
      src/lib/libutil/Makefile
  2. +1
    -1
      src/lib/libutil/shlib_version
  3. +3
    -1
      src/lib/libutil/util.h
  4. +23
    -2
      src/lib/libutil/uucplock.3
  5. +26
    -1
      src/lib/libutil/uucplock.c

+ 2
- 1
src/lib/libutil/Makefile View File

@ -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 \


+ 1
- 1
src/lib/libutil/shlib_version View File

@ -1,2 +1,2 @@
major=4
minor=1
minor=2

+ 3
- 1
src/lib/libutil/util.h View File

@ -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_ */

+ 23
- 2
src/lib/libutil/uucplock.3 View File

@ -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.


+ 26
- 1
src/lib/libutil/uucplock.c View File

@ -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 $
*
*/
@ -129,6 +129,28 @@ ret0:
return uuerr;
}
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;


Loading…
Cancel
Save