summaryrefslogtreecommitdiffstats
path: root/usr.bin/tip
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1994-12-19 01:57:17 +0000
committerache <ache@FreeBSD.org>1994-12-19 01:57:17 +0000
commit0cd0f4861c3268b06a1faf8c000918679ce1ed0f (patch)
treea551ccbb3e0ba35d863f10a08478c826bde723fb /usr.bin/tip
parent9c0459dc63dbfe1e195946470d1a3cc4f4e07b51 (diff)
downloadFreeBSD-src-0cd0f4861c3268b06a1faf8c000918679ce1ed0f.zip
FreeBSD-src-0cd0f4861c3268b06a1faf8c000918679ce1ed0f.tar.gz
Use ASCII lock instead of BINARY one.
Diffstat (limited to 'usr.bin/tip')
-rw-r--r--usr.bin/tip/uucplock.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/usr.bin/tip/uucplock.c b/usr.bin/tip/uucplock.c
index 6761857..917d812 100644
--- a/usr.bin/tip/uucplock.c
+++ b/usr.bin/tip/uucplock.c
@@ -39,6 +39,8 @@ static char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93";
#include <sys/file.h>
#include <sys/dir.h>
#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
#include "pathnames.h"
/*
@@ -50,52 +52,43 @@ static char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93";
uu_lock(ttyname)
char *ttyname;
{
- extern int errno;
int fd, pid;
char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN];
- off_t lseek();
+ FILE *ff;
(void)sprintf(tbuf, _PATH_LOCKDIRNAME, ttyname);
- fd = open(tbuf, O_RDWR|O_CREAT|O_EXCL, 0660);
- if (fd < 0) {
+ fd = open(tbuf, O_WRONLY|O_CREAT|O_EXCL, 0644);
+ if (fd >= 0)
+ ff = fdopen(fd, "w");
+ if (fd < 0 || ff == NULL) {
/*
* file is already locked
* check to see if the process holding the lock still exists
*/
- fd = open(tbuf, O_RDWR, 0);
- if (fd < 0) {
+ ff = fopen(tbuf, "r+");
+ if (ff == NULL) {
perror("lock open");
return(-1);
}
- if (read(fd, &pid, sizeof(pid)) != sizeof(pid)) {
- (void)close(fd);
+ if (fscanf(ff, "%10d\n", &pid) != 1) {
perror("lock read");
+ (void)fclose(ff);
return(-1);
}
if (kill(pid, 0) == 0 || errno != ESRCH) {
- (void)close(fd); /* process is still running */
+ (void)fclose(ff); /* process is still running */
return(-1);
}
/*
* The process that locked the file isn't running, so
* we'll lock it ourselves
*/
- if (lseek(fd, 0L, L_SET) < 0) {
- (void)close(fd);
- perror("lock lseek");
- return(-1);
- }
+ rewind(ff);
/* fall out and finish the locking process */
}
- pid = getpid();
- if (write(fd, (char *)&pid, sizeof(pid)) != sizeof(pid)) {
- (void)close(fd);
- (void)unlink(tbuf);
- perror("lock write");
- return(-1);
- }
- (void)close(fd);
+ (void)fprintf(ff, "%10d\n", getpid());
+ (void)fclose(ff);
return(0);
}
OpenPOWER on IntegriCloud