From d72207bd88175cc8b510a49263514c2f8c594874 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 4 Mar 1996 10:35:45 +0000 Subject: Prepare to eliminate multiply uucplock.c copies --- sbin/startslip/uucplock.c | 49 +++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/sbin/startslip/uucplock.c b/sbin/startslip/uucplock.c index 20a8239..2a08bae 100644 --- a/sbin/startslip/uucplock.c +++ b/sbin/startslip/uucplock.c @@ -32,14 +32,16 @@ */ #ifndef lint -static char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93"; +static const char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #include #include #include #include +#ifndef USE_PERROR #include +#endif #include #include #include @@ -62,7 +64,7 @@ int uu_lock (char *ttyname) { int fd; pid_t pid; - char tbuf[MAXNAMLEN]; + char tbuf[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN]; (void)sprintf(tbuf, _PATH_UUCPLOCK LOCKFMT, ttyname); fd = open(tbuf, O_RDWR|O_CREAT|O_EXCL, 0660); @@ -73,11 +75,19 @@ int uu_lock (char *ttyname) */ fd = open(tbuf, O_RDWR, 0); if (fd < 0) { +#ifndef USE_PERROR syslog(LOG_ERR, "lock open: %m"); +#else + perror("lock open"); +#endif return(-1); } if ((pid = get_pid (fd)) == -1) { +#ifndef USE_PERROR syslog(LOG_ERR, "lock read: %m"); +#else + perror("lock read"); +#endif (void)close(fd); return(-1); } @@ -90,8 +100,12 @@ int uu_lock (char *ttyname) * The process that locked the file isn't running, so * we'll lock it ourselves */ - if (lseek(fd, 0L, L_SET) < 0) { + if (lseek(fd, (off_t) 0, L_SET) < 0) { +#ifndef USE_PERROR syslog(LOG_ERR, "lock lseek: %m"); +#else + perror("lock lseek"); +#endif (void)close(fd); return(-1); } @@ -99,7 +113,11 @@ int uu_lock (char *ttyname) } pid = getpid(); if (!put_pid (fd, pid)) { +#ifndef USE_PERROR syslog(LOG_ERR, "lock write: %m"); +#else + perror("lock write"); +#endif (void)close(fd); (void)unlink(tbuf); return(-1); @@ -110,7 +128,7 @@ int uu_lock (char *ttyname) int uu_unlock (char *ttyname) { - char tbuf[MAXNAMLEN]; + char tbuf[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN]; (void)sprintf(tbuf, _PATH_UUCPLOCK LOCKFMT, ttyname); return(unlink(tbuf)); @@ -118,27 +136,26 @@ int uu_unlock (char *ttyname) static int put_pid (int fd, pid_t pid) { - char buf [32]; + char buf[32]; int len; - len = sprintf (buf, "%10ld\n", pid); - return write (fd, buf, len) == len; + len = sprintf (buf, "%10ld\n", pid); + return write (fd, buf, len) == len; } static pid_t get_pid (int fd) { int bytes_read; - char buf [32]; + char buf[32]; pid_t pid; - bytes_read = read (fd, buf, sizeof (buf) - 1); - if (bytes_read > 0) { - buf [bytes_read] = '\0'; - pid = strtol (buf, (char **) NULL, 10); - } - else - pid = -1; - return pid; + bytes_read = read (fd, buf, sizeof (buf) - 1); + if (bytes_read > 0) { + buf[bytes_read] = '\0'; + pid = strtol (buf, (char **) NULL, 10); + } else + pid = -1; + return pid; } /* end of uucplock.c */ -- cgit v1.1