summaryrefslogtreecommitdiff
path: root/usr/src/cmd/tip/uucplock.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/tip/uucplock.c')
-rw-r--r--usr/src/cmd/tip/uucplock.c135
1 files changed, 57 insertions, 78 deletions
diff --git a/usr/src/cmd/tip/uucplock.c b/usr/src/cmd/tip/uucplock.c
index a9b5b5285c..8eaf2d16d0 100644
--- a/usr/src/cmd/tip/uucplock.c
+++ b/usr/src/cmd/tip/uucplock.c
@@ -2,12 +2,15 @@
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
-#ident "%Z%%M% %I% %E% SMI" /* from UCB 4.6 6/25/83 */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
/*
* defs that come from uucp.h
*/
@@ -17,14 +20,14 @@
#define SLCKTIME (8*60*60) /* device timeout (LCK.. files) in seconds */
#ifdef __STDC__
#define ASSERT(e, f, v) if (!(e)) {\
- fprintf(stderr, "AERROR - (%s) ", #e); \
- fprintf(stderr, f, v); \
+ (void) fprintf(stderr, "AERROR - (%s) ", #e); \
+ (void) fprintf(stderr, f, v); \
finish(FAIL); \
}
#else
#define ASSERT(e, f, v) if (!(e)) {\
- fprintf(stderr, "AERROR - (%s) ", "e"); \
- fprintf(stderr, f, v); \
+ (void) fprintf(stderr, "AERROR - (%s) ", "e"); \
+ (void) fprintf(stderr, f, v); \
finish(FAIL); \
}
#endif
@@ -45,11 +48,18 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <utime.h>
-static void stlock();
-static int onelock();
-static int checkLock();
+static void stlock(char *);
+static int onelock(char *, char *, char *);
+static int checkLock(char *);
+extern void finish(int);
/*
* ulockf(file, atime)
@@ -67,18 +77,17 @@ static int checkLock();
*
* return codes: 0 | FAIL
*/
-
-static
-ulockf(file, atime)
- char *file;
- time_t atime;
+/* ARGSUSED */
+static int
+ulockf(char *file, time_t atime)
{
static char pid[SIZEOFPID+2] = { '\0' }; /* +2 for '\n' and NULL */
static char tempfile[NAMESIZE];
if (pid[0] == '\0') {
- (void) sprintf(pid, "%*d\n", SIZEOFPID, getpid());
- (void) sprintf(tempfile, "%s/LTMP.%d", LOCKDIR, getpid());
+ (void) sprintf(pid, "%*d\n", SIZEOFPID, (int)getpid());
+ (void) snprintf(tempfile, sizeof (tempfile),
+ "%s/LTMP.%d", LOCKDIR, getpid());
}
if (onelock(pid, tempfile, file) == -1) {
/* lock file exists */
@@ -105,14 +114,12 @@ ulockf(file, atime)
* FAIL -> lock file still active
*/
static int
-checkLock(file)
-register char *file;
+checkLock(char *file)
{
- register int ret;
+ int ret;
int lpid = -1;
char alpid[SIZEOFPID+2]; /* +2 for '\n' and NULL */
int fd;
- extern int errno;
fd = open(file, 0);
if (fd == -1) {
@@ -146,11 +153,9 @@ int Nlocks = 0;
*/
static void
-stlock(name)
- char *name;
+stlock(char *name)
{
char *p;
- extern char *calloc();
int i;
for (i = 0; i < Nlocks; i++) {
@@ -162,7 +167,7 @@ stlock(name)
i = Nlocks++;
p = calloc(strlen(name) + 1, sizeof (char));
ASSERT(p != NULL, "CAN NOT ALLOCATE FOR %s", name);
- strcpy(p, name);
+ (void) strcpy(p, name);
Lockfile[i] = p;
}
@@ -173,9 +178,8 @@ stlock(name)
* return codes: none
*/
-static
-rmlock(name)
- char *name;
+static void
+rmlock(char *name)
{
int i;
@@ -183,30 +187,29 @@ rmlock(name)
if (Lockfile[i] == NULL)
continue;
if (name == NULL || strcmp(name, Lockfile[i]) == SAME) {
- unlink(Lockfile[i]);
+ (void) unlink(Lockfile[i]);
free(Lockfile[i]);
Lockfile[i] = NULL;
}
}
}
-static
-onelock(pid, tempfile, name)
- char *pid, *tempfile, *name;
+static int
+onelock(char *pid, char *tempfile, char *name)
{
int fd;
static int first = 1;
- extern int errno;
fd = creat(tempfile, 0444);
if (fd < 0) {
if (first) {
if (errno == EACCES) {
- fprintf(stderr,
+ (void) fprintf(stderr,
"tip: can't create files in lock file directory %s\n",
LOCKDIR);
} else if (access(LOCKDIR, 0) < 0) {
- fprintf(stderr, "tip: lock file directory %s: ",
+ (void) fprintf(stderr,
+ "tip: lock file directory %s: ",
LOCKDIR);
perror("");
}
@@ -218,86 +221,62 @@ onelock(pid, tempfile, name)
}
/* +1 for '\n' */
if (write(fd, pid, SIZEOFPID+1) != (SIZEOFPID+1)) {
- fprintf(stderr,
+ (void) fprintf(stderr,
"tip: can't write to files in lock file directory %s: %s\n",
LOCKDIR, strerror(errno));
(void) unlink(tempfile);
return (-1);
}
- fchmod(fd, 0444);
- close(fd);
+ (void) fchmod(fd, 0444);
+ (void) close(fd);
if (link(tempfile, name) < 0) {
- unlink(tempfile);
+ (void) unlink(tempfile);
return (-1);
}
- unlink(tempfile);
+ (void) unlink(tempfile);
return (0);
}
/*
* delock(sys) remove a lock file
* char *sys;
- *
- * return codes: 0 | FAIL
*/
-delock(sys)
- char *sys;
+void
+delock(char *sys)
{
struct stat sb;
char lname[NAMESIZE];
if (stat(sys, &sb) < 0)
- return (FAIL);
- sprintf(lname, "%s/%s.%3.3lu.%3.3lu.%3.3lu", LOCKDIR, LOCKPRE,
- (unsigned long)major(sb.st_dev),
- (unsigned long)major(sb.st_rdev),
- (unsigned long)minor(sb.st_rdev));
+ return;
+ (void) snprintf(lname, sizeof (lname), "%s/%s.%3.3lu.%3.3lu.%3.3lu",
+ LOCKDIR, LOCKPRE,
+ (unsigned long)major(sb.st_dev),
+ (unsigned long)major(sb.st_rdev),
+ (unsigned long)minor(sb.st_rdev));
rmlock(lname);
}
/*
- * mlock(sys) create system lock
+ * tip_mlock(sys) create system lock
* char *sys;
*
* return codes: 0 | FAIL
*/
-mlock(sys)
- char *sys;
+int
+tip_mlock(char *sys)
{
struct stat sb;
char lname[NAMESIZE];
if (stat(sys, &sb) < 0)
return (FAIL);
- sprintf(lname, "%s/%s.%3.3lu.%3.3lu.%3.3lu", LOCKDIR, LOCKPRE,
- (unsigned long)major(sb.st_dev),
- (unsigned long)major(sb.st_rdev),
- (unsigned long)minor(sb.st_rdev));
+ (void) snprintf(lname, sizeof (lname), "%s/%s.%3.3lu.%3.3lu.%3.3lu",
+ LOCKDIR, LOCKPRE,
+ (unsigned long)major(sb.st_dev),
+ (unsigned long)major(sb.st_rdev),
+ (unsigned long)minor(sb.st_rdev));
return (ulockf(lname, (time_t)SLCKTIME) < 0 ? FAIL : 0);
}
-
-/*
- * update access and modify times for lock files
- * return:
- * none
- */
-void
-ultouch()
-{
- register int i;
- time_t time();
-
- struct ut {
- time_t actime;
- time_t modtime;
- } ut;
-
- ut.actime = time(&ut.modtime);
- for (i = 0; i < Nlocks; i++) {
- if (Lockfile[i] == NULL)
- continue;
- utime(Lockfile[i], &ut);
- }
-}