summaryrefslogtreecommitdiffstats
path: root/lib/libutil/uucplock.c
diff options
context:
space:
mode:
authorbrian <brian@openbsd.org>1998-06-08 20:28:23 +0000
committerbrian <brian@openbsd.org>1998-06-08 20:28:23 +0000
commit709dd3e49f8b667c62f9522c65e9392b50567962 (patch)
tree2949a410f068cd45aa3e8a6a75e9352e69be717b /lib/libutil/uucplock.c
parentuse endptr in a strtl() (diff)
downloadwireguard-openbsd-709dd3e49f8b667c62f9522c65e9392b50567962.tar.xz
wireguard-openbsd-709dd3e49f8b667c62f9522c65e9392b50567962.zip
Add uu_lock_txfr() for donating locks to another process.
Reviewed by: Theo
Diffstat (limited to 'lib/libutil/uucplock.c')
-rw-r--r--lib/libutil/uucplock.c27
1 files changed, 26 insertions, 1 deletions
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;