summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1996-03-04 10:35:45 +0000
committerache <ache@FreeBSD.org>1996-03-04 10:35:45 +0000
commitd72207bd88175cc8b510a49263514c2f8c594874 (patch)
treed458b44d71b69d030afd9ea5461dd1d5f4e5ac64
parent4efa53288e20f5990c002cc7766e3bfc774c2569 (diff)
downloadFreeBSD-src-d72207bd88175cc8b510a49263514c2f8c594874.zip
FreeBSD-src-d72207bd88175cc8b510a49263514c2f8c594874.tar.gz
Prepare to eliminate multiply uucplock.c copies
-rw-r--r--sbin/startslip/uucplock.c49
1 files 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 <sys/types.h>
#include <sys/file.h>
#include <sys/dir.h>
#include <errno.h>
+#ifndef USE_PERROR
#include <syslog.h>
+#endif
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
@@ -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 */
OpenPOWER on IntegriCloud