| 125 | } |
| 126 | |
| 127 | int |
| 128 | uu_lock_txfr(const char *tty_name, pid_t pid) |
| 129 | { |
| 130 | int fd, err; |
| 131 | char lckname[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN]; |
| 132 | |
| 133 | snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, tty_name); |
| 134 | |
| 135 | if ((fd = open(lckname, O_RDWR | O_CLOEXEC)) < 0) |
| 136 | return UU_LOCK_OWNER_ERR; |
| 137 | if (get_pid(fd, &err) != getpid()) |
| 138 | err = UU_LOCK_OWNER_ERR; |
| 139 | else { |
| 140 | lseek(fd, (off_t)0, SEEK_SET); |
| 141 | err = put_pid(fd, pid) ? 0 : UU_LOCK_WRITE_ERR; |
| 142 | } |
| 143 | close(fd); |
| 144 | |
| 145 | return err; |
| 146 | } |
| 147 | |
| 148 | int |
| 149 | uu_unlock(const char *tty_name) |