projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
BSD 4_4 release
[unix-history]
/
usr
/
src
/
usr.bin
/
uucp
/
libuu
/
gename.c
diff --git
a/usr/src/usr.bin/uucp/libuu/gename.c
b/usr/src/usr.bin/uucp/libuu/gename.c
index
f05f825
..
a370e6b
100644
(file)
--- a/
usr/src/usr.bin/uucp/libuu/gename.c
+++ b/
usr/src/usr.bin/uucp/libuu/gename.c
@@
-1,77
+1,68
@@
+/*-
+ * Copyright (c) 1985, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This module is believed to contain source code proprietary to AT&T.
+ * Use and redistribution is subject to the Berkeley Software License
+ * Agreement and your Software Agreement with AT&T (Western Electric).
+ */
+
#ifndef lint
#ifndef lint
-static char sccsid[] = "@(#)gename.c
5.1 (Berkeley) %G%
";
-#endif
+static char sccsid[] = "@(#)gename.c
8.1 (Berkeley) 6/6/93
";
+#endif
/* not lint */
#include "uucp.h"
#define SEQLEN 4
#include "uucp.h"
#define SEQLEN 4
-
-/*******
- * gename(pre, sys, grade, file) generate file name
- * char grade, *sys, pre, *file;
- *
- * return codes: none
+#define SLOCKTIME 10L
+#define SLOCKTRIES 5
+/*
+ * the alphabet can be anything, but if it's not in ascii order,
+ * sequence ordering is not preserved
*/
*/
+static char alphabet[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-gename(pre, sys, grade, file)
-char pre, *sys, grade, *file;
-{
- static char sqnum[5];
-
- getseq(sqnum);
- sprintf(file, "%c.%.7s%c%.*s", pre, sys, grade, SEQLEN, sqnum);
- DEBUG(4, "file - %s\n", file);
- return;
-}
+#ifdef BSD4_2
+#include <sys/file.h>
+#endif BSD4_2
+/*LINTLIBRARY*/
-#define SLOCKTIME 10L
-#define SLOCKTRIES 5
-
-/*******
- * getseq(snum) get next sequence number
- * char *snum;
- *
- * return codes: none
+/*
+ * generate file name
*/
*/
-
-static
-getseq(snum)
-register char *snum;
+gename(pre, sys, grade, file)
+char pre, *sys, grade, *file;
{
{
- /*
- * the alphabet can be anything, but if it's not in ascii order,
- * sequence ordering is not preserved
- */
- char *alphabet =
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
register int i, fd;
register int i, fd;
- static char *lastchar;
+ static char snum[5];
+ static char *lastchar = NULL;
if (lastchar == NULL || (snum[SEQLEN-1] = *(lastchar++)) == '\0') {
if (lastchar == NULL || (snum[SEQLEN-1] = *(lastchar++)) == '\0') {
+#ifndef BSD4_2
for (i = 0; i < SLOCKTRIES; i++) {
if (!ulockf(SEQLOCK, SLOCKTIME))
break;
sleep(5);
}
for (i = 0; i < SLOCKTRIES; i++) {
if (!ulockf(SEQLOCK, SLOCKTIME))
break;
sleep(5);
}
- ASSERT(i < SLOCKTRIES, "CAN NOT GET %s", "", SEQLOCK);
+ if (i >= SLOCKTRIES) {
+ logent(SEQLOCK, "CAN NOT LOCK");
+ goto getrandseq;
+ }
+#endif !BSD4_2
if ((fd = open(SEQFILE, 2)) >= 0) {
if ((fd = open(SEQFILE, 2)) >= 0) {
- int alphalen;
- register char *p;
- char *index();
-
- alphalen = strlen(alphabet);
+ register char *p;
+#ifdef BSD4_2
+ flock(fd, LOCK_EX);
+#endif !BSD4_2
read(fd, snum, SEQLEN);
/* increment the penultimate character */
for (i = SEQLEN - 2; i >= 0; --i) {
read(fd, snum, SEQLEN);
/* increment the penultimate character */
for (i = SEQLEN - 2; i >= 0; --i) {
- if ((p = index(alphabet, snum[i])) == NULL) {
- /* drastic but effective */
- snum[i] = alphabet[alphalen - 1];
- DEBUG(6, "bad seqf: %s\n", snum);
- }
- if (++p < &alphabet[alphalen]) {
+ if ((p = index(alphabet, snum[i])) == NULL)
+ goto getrandseq;
+ if (++p < &alphabet[sizeof alphabet - 1]) {
snum[i] = *p;
break;
} else /* carry */
snum[i] = *p;
break;
} else /* carry */
@@
-79,17
+70,24
@@
register char *snum;
}
snum[SEQLEN-1] = alphabet[0];
} else {
}
snum[SEQLEN-1] = alphabet[0];
} else {
- if ((fd = creat(SEQFILE, 0666)) < 0)
- return(FAIL);
+ syslog(LOG_WARNING, "open(%s) failed: %m", SEQFILE);
+ fd = creat(SEQFILE, 0666);
+getrandseq: srand((int)time((time_t *)0));
for (i = 0; i < SEQLEN; i++)
for (i = 0; i < SEQLEN; i++)
- snum[i] = alphabet[0];
+ snum[i] = alphabet[rand() % (sizeof alphabet - 1)];
+ snum[SEQLEN-1] = alphabet[0];
}
}
- lseek(fd, 0, 0);
- write(fd, snum, SEQLEN);
- close(fd);
+ if (fd >= 0) {
+ lseek(fd, 0L, 0);
+ write(fd, snum, SEQLEN);
+ close(fd);
+ }
+#ifndef BSD4_2
rmlock(SEQLOCK);
rmlock(SEQLOCK);
+#endif !BSD4_2
lastchar = alphabet + 1;
}
lastchar = alphabet + 1;
}
- return(0);
+ sprintf(file,"%c.%.*s%c%.*s", pre, SYSNSIZE, sys, grade, SEQLEN, snum);
+ DEBUG(4, "file - %s\n", file);
}
}