mirror of
https://github.com/Interlisp/maiko.git
synced 2026-05-01 06:09:21 +00:00
Improves performance of some file operations, fixes some memory leaks, and increases clarity.
* Avoids unnecessary alarm(0) when it is about to be set again, only cleans up after it’s all done. * Renames DIRCHAR to LISPDIRCHAR to be more descriptive, adds LISPDIRSTR for contexts where a string is required rather than a character. * Avoids leaks of directory structures by ensuring that any opendir() has a matching closedir(), with a timeout check, on the return path * Ensures that closedir() calls that could smash errno happen after errno is saved for Lisp’s consumption * Simplifies code to take advantage of strlcpy()/strlcat() guarantee that destination string is NUL terminated * Reduces number of unnecessary copies into scratch buffer for file name processing * Removes some commented out code left over from copy/paste of functions
This commit is contained in:
@@ -38,9 +38,8 @@ extern unsigned int TIMEOUT_TIME;
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define S_TOUT(exp) \
|
#define S_TOUT(exp) \
|
||||||
alarm(TIMEOUT_TIME), \
|
alarm(TIMEOUT_TIME), \
|
||||||
(exp), \
|
(exp)
|
||||||
alarm(0)
|
|
||||||
|
|
||||||
#define ERRSETJMP(rval) \
|
#define ERRSETJMP(rval) \
|
||||||
do { \
|
do { \
|
||||||
|
|||||||
221
src/dir.c
221
src/dir.c
@@ -38,7 +38,8 @@
|
|||||||
extern int *Lisp_errno;
|
extern int *Lisp_errno;
|
||||||
extern int Dummy_errno;
|
extern int Dummy_errno;
|
||||||
|
|
||||||
#define DIRCHAR '>'
|
#define LISPDIRCHAR '>'
|
||||||
|
#define LISPDIRSTR ">"
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
SUBROUTINES
|
SUBROUTINES
|
||||||
@@ -193,7 +194,7 @@ static int match_pattern(char *tp, char *pp)
|
|||||||
int make_old_version(char *old, size_t oldsize, char *file)
|
int make_old_version(char *old, size_t oldsize, char *file)
|
||||||
{
|
{
|
||||||
int len = (int)strlen(file) - 1;
|
int len = (int)strlen(file) - 1;
|
||||||
if (file[len] == DIRCHAR) return 0;
|
if (file[len] == LISPDIRCHAR) return 0;
|
||||||
/* look up old versions of files for version # 0's */
|
/* look up old versions of files for version # 0's */
|
||||||
strlcpy(old, file, oldsize);
|
strlcpy(old, file, oldsize);
|
||||||
|
|
||||||
@@ -661,6 +662,7 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
if (nextp == (FINFO *)NULL) {
|
if (nextp == (FINFO *)NULL) {
|
||||||
FreeFinfo(prevp);
|
FreeFinfo(prevp);
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
|
TIMEOUT(closedir(dirp));
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
nextp->next = prevp;
|
nextp->next = prevp;
|
||||||
@@ -688,25 +690,19 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
nextp->dirp = 1;
|
nextp->dirp = 1;
|
||||||
quote_dname(namebuf, sizeof(namebuf));
|
quote_dname(namebuf, sizeof(namebuf));
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
strlcat(nextp->lname, LISPDIRSTR, sizeof(nextp->lname));
|
||||||
*(nextp->lname + len) = DIRCHAR;
|
nextp->lname_len = strlen(nextp->lname);
|
||||||
*(nextp->lname + len + 1) = '\0';
|
|
||||||
nextp->lname_len = len + 1;
|
|
||||||
} else {
|
} else {
|
||||||
/* All other types than directory. */
|
/* All other types than directory. */
|
||||||
nextp->dirp = 0;
|
nextp->dirp = 0;
|
||||||
strlcat(namebuf, ".~1~", sizeof(namebuf));
|
strlcat(namebuf, ".~1~", sizeof(namebuf));
|
||||||
quote_fname(namebuf, sizeof(namebuf));
|
quote_fname(namebuf, sizeof(namebuf));
|
||||||
len = strlen(namebuf);
|
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
||||||
*(nextp->lname + len) = '\0';
|
nextp->lname_len = strlen(nextp->lname);
|
||||||
nextp->lname_len = len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(namebuf, dirp.name, sizeof(namebuf));
|
strlcpy(nextp->no_ver_name, dirp.name, sizeof(nextp->no_ver_name));
|
||||||
len = strlen(namebuf);
|
DOWNCASE(nextp->no_ver_name);
|
||||||
DOWNCASE(namebuf);
|
|
||||||
strlcpy(nextp->no_ver_name, namebuf, sizeof(nextp->no_ver_name));
|
|
||||||
nextp->version = 1;
|
nextp->version = 1;
|
||||||
nextp->ino = sbuf.st_ino;
|
nextp->ino = sbuf.st_ino;
|
||||||
nextp->prop->length = (unsigned)sbuf.st_size;
|
nextp->prop->length = (unsigned)sbuf.st_size;
|
||||||
@@ -717,14 +713,13 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
if (pwd == (struct passwd *)NULL) {
|
if (pwd == (struct passwd *)NULL) {
|
||||||
nextp->prop->au_len = 0;
|
nextp->prop->au_len = 0;
|
||||||
} else {
|
} else {
|
||||||
len = strlen(pwd->pw_name);
|
|
||||||
strlcpy(nextp->prop->author, pwd->pw_name, sizeof(nextp->prop->author));
|
strlcpy(nextp->prop->author, pwd->pw_name, sizeof(nextp->prop->author));
|
||||||
*(nextp->prop->author + len) = '\0';
|
nextp->prop->au_len = strlen(nextp->prop->author);
|
||||||
nextp->prop->au_len = len;
|
|
||||||
} */
|
} */
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
alarm(0); // cancel alarm from S_TOUT
|
||||||
|
|
||||||
/***********************/
|
/***********************/
|
||||||
/* Now go looking for version-0 entries */
|
/* Now go looking for version-0 entries */
|
||||||
/***********************/
|
/***********************/
|
||||||
@@ -751,9 +746,8 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
newp->dirp = 0;
|
newp->dirp = 0;
|
||||||
snprintf(namebuf, sizeof(namebuf), "%s.~00~", nextp->no_ver_name);
|
snprintf(namebuf, sizeof(namebuf), "%s.~00~", nextp->no_ver_name);
|
||||||
quote_fname(namebuf, sizeof(namebuf));
|
quote_fname(namebuf, sizeof(namebuf));
|
||||||
len = strlen(namebuf);
|
|
||||||
strlcpy(newp->lname, namebuf, sizeof(newp->lname));
|
strlcpy(newp->lname, namebuf, sizeof(newp->lname));
|
||||||
newp->lname_len = len;
|
newp->lname_len = strlen(newp->lname);
|
||||||
|
|
||||||
strlcpy(newp->no_ver_name, old, sizeof(newp->no_ver_name));
|
strlcpy(newp->no_ver_name, old, sizeof(newp->no_ver_name));
|
||||||
newp->version = 0;
|
newp->version = 0;
|
||||||
@@ -801,8 +795,8 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
AllocFinfo(nextp);
|
AllocFinfo(nextp);
|
||||||
if (nextp == (FINFO *)NULL) {
|
if (nextp == (FINFO *)NULL) {
|
||||||
FreeFinfo(prevp);
|
FreeFinfo(prevp);
|
||||||
closedir(dirp);
|
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
nextp->next = prevp;
|
nextp->next = prevp;
|
||||||
@@ -814,35 +808,26 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
* link. We should ignore such error here.
|
* link. We should ignore such error here.
|
||||||
*/
|
*/
|
||||||
FreeFinfo(nextp);
|
FreeFinfo(nextp);
|
||||||
closedir(dirp);
|
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(namebuf, dp->d_name, sizeof(namebuf));
|
strlcpy(nextp->lname, dp->d_name, sizeof(nextp->lname));
|
||||||
if (S_ISDIR(sbuf.st_mode)) {
|
if (S_ISDIR(sbuf.st_mode)) {
|
||||||
nextp->dirp = 1;
|
nextp->dirp = 1;
|
||||||
quote_dname(namebuf, sizeof(namebuf));
|
quote_dname(nextp->lname, sizeof(nextp->lname));
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
strlcat(nextp->lname, LISPDIRSTR, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
|
||||||
*(nextp->lname + len) = DIRCHAR;
|
|
||||||
*(nextp->lname + len + 1) = '\0';
|
|
||||||
nextp->lname_len = len + 1;
|
|
||||||
} else {
|
} else {
|
||||||
/* All other types than directory. */
|
/* All other types than directory. */
|
||||||
nextp->dirp = 0;
|
nextp->dirp = 0;
|
||||||
quote_fname(namebuf, sizeof(namebuf));
|
quote_fname(nextp->lname, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
|
||||||
*(nextp->lname + len) = '\0';
|
|
||||||
nextp->lname_len = len;
|
|
||||||
}
|
}
|
||||||
|
nextp->lname_len = strlen(nextp->lname);
|
||||||
|
|
||||||
strlcpy(namebuf, dp->d_name, sizeof(namebuf));
|
strlcpy(nextp->no_ver_name, dp->d_name, sizeof(nextp->no_ver_name));
|
||||||
len = strlen(namebuf);
|
separate_version(nextp->no_ver_name, sizeof(nextp->no_ver_name), fver, sizeof(fver), 1);
|
||||||
separate_version(namebuf, sizeof(namebuf), fver, sizeof(fver), 1);
|
DOWNCASE(nextp->no_ver_name);
|
||||||
DOWNCASE(namebuf);
|
|
||||||
strlcpy(nextp->no_ver_name, namebuf, sizeof(nextp->no_ver_name));
|
|
||||||
if (*fver == '\0')
|
if (*fver == '\0')
|
||||||
nextp->version = 0;
|
nextp->version = 0;
|
||||||
else
|
else
|
||||||
@@ -856,14 +841,12 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
if (pwd == (struct passwd *)NULL) {
|
if (pwd == (struct passwd *)NULL) {
|
||||||
nextp->prop->au_len = 0;
|
nextp->prop->au_len = 0;
|
||||||
} else {
|
} else {
|
||||||
len = strlen(pwd->pw_name);
|
|
||||||
strlcpy(nextp->prop->author, pwd->pw_name, sizeof(nextp->prop->author));
|
strlcpy(nextp->prop->author, pwd->pw_name, sizeof(nextp->prop->author));
|
||||||
*(nextp->prop->author + len) = '\0';
|
nextp->prop->au_len = strlen(nextp->prop->author);
|
||||||
nextp->prop->au_len = len;
|
|
||||||
}
|
}
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
if (n > 0) *finfo_buf = prevp;
|
if (n > 0) *finfo_buf = prevp;
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
@@ -939,6 +922,7 @@ static int enum_dsk(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
if (nextp == (FINFO *)NULL) {
|
if (nextp == (FINFO *)NULL) {
|
||||||
FreeFinfo(prevp);
|
FreeFinfo(prevp);
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
|
alarm(0); // cancel alarm from S_TOUT
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
nextp->next = prevp;
|
nextp->next = prevp;
|
||||||
@@ -949,7 +933,7 @@ static int enum_dsk(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
snprintf(namebuf, sizeof(namebuf), "\\%s", dirp.name);
|
snprintf(namebuf, sizeof(namebuf), "\\%s", dirp.name);
|
||||||
} else
|
} else
|
||||||
snprintf(namebuf, sizeof(namebuf), "%s\\%s", dir, dirp.name);
|
snprintf(namebuf, sizeof(namebuf), "%s\\%s", dir, dirp.name);
|
||||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
TIMEOUT(rval = stat(namebuf, &sbuf)); // will cancel S_TOUT alarm
|
||||||
if (rval == -1 && errno != ENOENT) {
|
if (rval == -1 && errno != ENOENT) {
|
||||||
/*
|
/*
|
||||||
* ENOENT error might be caused by missing symbolic
|
* ENOENT error might be caused by missing symbolic
|
||||||
@@ -960,35 +944,32 @@ static int enum_dsk(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
strlcpy(namebuf, dirp.name, sizeof(namebuf)); /* moved from below 2/26/93 */
|
strlcpy(namebuf, dirp.name, sizeof(namebuf)); /* moved from below 2/26/93 */
|
||||||
if (S_ISDIR(sbuf.st_mode)) {
|
if (S_ISDIR(sbuf.st_mode)) {
|
||||||
nextp->dirp = 1;
|
nextp->dirp = 1;
|
||||||
quote_dname(namebuf, sizeof(namebuf));
|
quote_dname(namebuf, sizeof(namebuf));
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
strlcat(nextp->lname, LISPDIRCHAR, sizeof(nextp->lname));
|
||||||
*(nextp->lname + len) = DIRCHAR;
|
nextp->lname_len = strlen(nextp->lname);
|
||||||
*(nextp->lname + len + 1) = '\0';
|
|
||||||
nextp->lname_len = len + 1;
|
|
||||||
} else {
|
} else {
|
||||||
/* All other types than directory. */
|
/* All other types than directory. */
|
||||||
nextp->dirp = 0;
|
nextp->dirp = 0;
|
||||||
strlcat(namebuf, ".~1~", sizeof(namebuf));
|
strlcat(namebuf, ".~1~", sizeof(namebuf));
|
||||||
quote_fname(namebuf, sizeof(namebuf));
|
quote_fname(namebuf, sizeof(namebuf));
|
||||||
len = strlen(namebuf);
|
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
||||||
*(nextp->lname + len) = '\0';
|
nextp->lname_len = strlen(nextp->lname);
|
||||||
nextp->lname_len = len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(namebuf, dirp.name, sizeof(namebuf)); /* to get real versionless name */
|
strlcpy(namebuf, dirp.name, sizeof(namebuf)); /* to get real versionless name */
|
||||||
len = strlen(namebuf);
|
|
||||||
DOWNCASE(namebuf);
|
DOWNCASE(namebuf);
|
||||||
strlcpy(nextp->no_ver_name, namebuf, sizeof(nextp->no_ver_name));
|
strlcpy(nextp->no_ver_name, namebuf, sizeof(nextp->no_ver_name));
|
||||||
nextp->version = 1;
|
nextp->version = 1;
|
||||||
nextp->ino = sbuf.st_ino;
|
nextp->ino = sbuf.st_ino;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
alarm(0); // ensure alarm from S_TOUT is cancelled
|
||||||
|
|
||||||
/***********************/
|
/***********************/
|
||||||
/* Now go looking for version-0 entries */
|
/* Now go looking for version-0 entries */
|
||||||
/***********************/
|
/***********************/
|
||||||
@@ -1064,8 +1045,8 @@ static int enum_dsk(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
AllocFinfo(nextp);
|
AllocFinfo(nextp);
|
||||||
if (nextp == (FINFO *)NULL) {
|
if (nextp == (FINFO *)NULL) {
|
||||||
FreeFinfo(prevp);
|
FreeFinfo(prevp);
|
||||||
closedir(dirp);
|
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
nextp->next = prevp;
|
nextp->next = prevp;
|
||||||
@@ -1077,35 +1058,26 @@ static int enum_dsk(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
* link. We should ignore such error here.
|
* link. We should ignore such error here.
|
||||||
*/
|
*/
|
||||||
FreeFinfo(nextp);
|
FreeFinfo(nextp);
|
||||||
closedir(dirp);
|
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
|
TIMEOUT(closedir(dirp));
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(namebuf, dp->d_name, sizeof(namebuf));
|
strlcpy(nextp->lname, dp->d_name, sizeof(nextp->lname));
|
||||||
if (S_ISDIR(sbuf.st_mode)) {
|
if (S_ISDIR(sbuf.st_mode)) {
|
||||||
nextp->dirp = 1;
|
nextp->dirp = 1;
|
||||||
quote_dname(namebuf, sizeof(namebuf));
|
quote_dname(nextp->lname, sizeof(nextp->lname));
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
strlcat(nextp->lname, LISPDIRSTR, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
|
||||||
*(nextp->lname + len) = DIRCHAR;
|
|
||||||
*(nextp->lname + len + 1) = '\0';
|
|
||||||
nextp->lname_len = len + 1;
|
|
||||||
} else {
|
} else {
|
||||||
/* All other types than directory. */
|
/* All other types than directory. */
|
||||||
nextp->dirp = 0;
|
nextp->dirp = 0;
|
||||||
quote_fname(namebuf, sizeof(namebuf));
|
quote_fname(nextp->lname, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
|
||||||
*(nextp->lname + len) = '\0';
|
|
||||||
nextp->lname_len = len;
|
|
||||||
}
|
}
|
||||||
|
nextp->lname_len = strlen(nextp->lname);
|
||||||
|
|
||||||
strlcpy(namebuf, dp->d_name, sizeof(namebuf));
|
strlcpy(nextp->no_ver_name, dp->d_name, sizeof(nextp->no_ver_name));
|
||||||
len = strlen(namebuf);
|
separate_version(nextp->no_ver_name, sizeof(nextp->no_ver_name), fver, sizeof(fver), 1);
|
||||||
separate_version(namebuf, sizeof(namebuf), fver, sizeof(fver), 1);
|
DOWNCASE(nextp->no_ver_name);
|
||||||
DOWNCASE(namebuf);
|
|
||||||
strlcpy(nextp->no_ver_name, namebuf, sizeof(nextp->no_ver_name));
|
|
||||||
if (*fver == '\0')
|
if (*fver == '\0')
|
||||||
nextp->version = 0;
|
nextp->version = 0;
|
||||||
else
|
else
|
||||||
@@ -1113,7 +1085,7 @@ static int enum_dsk(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
nextp->ino = sbuf.st_ino;
|
nextp->ino = sbuf.st_ino;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
if (n > 0) *finfo_buf = prevp;
|
if (n > 0) *finfo_buf = prevp;
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
@@ -1170,11 +1142,12 @@ static int enum_ufs_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
if (nextp == (FINFO *)NULL) {
|
if (nextp == (FINFO *)NULL) {
|
||||||
FreeFinfo(prevp);
|
FreeFinfo(prevp);
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
|
alarm(0); // cancel alarm from S_TOUT
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
nextp->next = prevp;
|
nextp->next = prevp;
|
||||||
snprintf(namebuf, sizeof(namebuf), "%s\\%s", dir, dirp.name);
|
snprintf(namebuf, sizeof(namebuf), "%s\\%s", dir, dirp.name);
|
||||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
TIMEOUT(rval = stat(namebuf, &sbuf)); // cancels alarm set by S_TOUT
|
||||||
if (rval == -1 && errno != ENOENT) {
|
if (rval == -1 && errno != ENOENT) {
|
||||||
/*
|
/*
|
||||||
* ENOENT error might be caused by missing symbolic
|
* ENOENT error might be caused by missing symbolic
|
||||||
@@ -1185,45 +1158,26 @@ static int enum_ufs_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(namebuf, dirp.name, sizeof(namebuf));
|
strlcpy(nextp->lname, dp->d_name, sizeof(nextp->lname));
|
||||||
if (S_ISDIR(sbuf.st_mode)) {
|
if (S_ISDIR(sbuf.st_mode)) {
|
||||||
nextp->dirp = 1;
|
nextp->dirp = 1;
|
||||||
quote_dname(namebuf, sizeof(namebuf));
|
quote_dname(nextp->lname, sizeof(nextp->lname));
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
strlcat(nextp->lname, LISPDIRSTR, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
|
||||||
*(nextp->lname + len) = DIRCHAR;
|
|
||||||
*(nextp->lname + len + 1) = '\0';
|
|
||||||
nextp->lname_len = len + 1;
|
|
||||||
} else {
|
} else {
|
||||||
/* All other types than directory. */
|
/* All other types than directory. */
|
||||||
nextp->dirp = 0;
|
nextp->dirp = 0;
|
||||||
quote_fname_ufs(namebuf, sizeof(namebuf));
|
quote_fname(nextp->lname, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
|
||||||
*(nextp->lname + len) = '\0';
|
|
||||||
nextp->lname_len = len;
|
|
||||||
}
|
}
|
||||||
|
nextp->lname_len = strlen(nextp->lname);
|
||||||
|
|
||||||
strlcpy(namebuf, dirp.name, sizeof(namebuf));
|
|
||||||
len = strlen(namebuf);
|
|
||||||
nextp->ino = sbuf.st_ino;
|
nextp->ino = sbuf.st_ino;
|
||||||
nextp->prop->length = (unsigned)sbuf.st_size;
|
nextp->prop->length = (unsigned)sbuf.st_size;
|
||||||
nextp->prop->wdate = (unsigned)ToLispTime(sbuf.st_mtime);
|
nextp->prop->wdate = (unsigned)ToLispTime(sbuf.st_mtime);
|
||||||
nextp->prop->rdate = (unsigned)ToLispTime(sbuf.st_atime);
|
nextp->prop->rdate = (unsigned)ToLispTime(sbuf.st_atime);
|
||||||
nextp->prop->protect = (unsigned)sbuf.st_mode;
|
nextp->prop->protect = (unsigned)sbuf.st_mode;
|
||||||
/*
|
|
||||||
TIMEOUT(pwd = getpwuid(sbuf.st_uid));
|
|
||||||
if (pwd == (struct passwd *)NULL) {
|
|
||||||
nextp->prop->au_len = 0;
|
|
||||||
} else {
|
|
||||||
len = strlen(pwd->pw_name);
|
|
||||||
strlcpy(nextp->prop->author, pwd->pw_name, sizeof(nextp->prop->author));
|
|
||||||
*(nextp->prop->author + len) = '\0';
|
|
||||||
nextp->prop->au_len = len;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
alarm(0); // ensure alarm set by S_TOUT is cancelled
|
||||||
if (n > 0) *finfo_buf = prevp;
|
if (n > 0) *finfo_buf = prevp;
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
@@ -1259,64 +1213,43 @@ static int enum_ufs_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
AllocFinfo(nextp);
|
AllocFinfo(nextp);
|
||||||
if (nextp == (FINFO *)NULL) {
|
if (nextp == (FINFO *)NULL) {
|
||||||
FreeFinfo(prevp);
|
FreeFinfo(prevp);
|
||||||
closedir(dirp);
|
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
nextp->next = prevp;
|
nextp->next = prevp;
|
||||||
snprintf(namebuf, sizeof(namebuf), "%s/%s", dir, dp->d_name);
|
snprintf(namebuf, sizeof(namebuf), "%s/%s", dir, dp->d_name);
|
||||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
TIMEOUT(rval = stat(namebuf, &sbuf)); // cancels alarm set by S_TOUT
|
||||||
if (rval == -1 && errno != ENOENT) {
|
if (rval == -1 && errno != ENOENT) {
|
||||||
/*
|
/*
|
||||||
* ENOENT error might be caused by missing symbolic
|
* ENOENT error might be caused by missing symbolic
|
||||||
* link. We should ignore such error here.
|
* link. We should ignore such error here.
|
||||||
*/
|
*/
|
||||||
FreeFinfo(nextp);
|
FreeFinfo(nextp);
|
||||||
closedir(dirp);
|
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
|
TIMEOUT(closedir(dirp));
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(namebuf, dp->d_name, sizeof(namebuf));
|
strlcpy(nextp->lname, dp->d_name, sizeof(nextp->lname));
|
||||||
if (S_ISDIR(sbuf.st_mode)) {
|
if (S_ISDIR(sbuf.st_mode)) {
|
||||||
nextp->dirp = 1;
|
nextp->dirp = 1;
|
||||||
quote_dname(namebuf, sizeof(namebuf));
|
quote_dname(nextp->lname, sizeof(nextp->lname));
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
strlcat(nextp->lname, LISPDIRSTR, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
|
||||||
*(nextp->lname + len) = DIRCHAR;
|
|
||||||
*(nextp->lname + len + 1) = '\0';
|
|
||||||
nextp->lname_len = len + 1;
|
|
||||||
} else {
|
} else {
|
||||||
/* All other types than directory. */
|
|
||||||
nextp->dirp = 0;
|
nextp->dirp = 0;
|
||||||
quote_fname_ufs(namebuf, sizeof(namebuf));
|
quote_fname(nextp->lname, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
|
||||||
*(nextp->lname + len) = '\0';
|
|
||||||
nextp->lname_len = len;
|
|
||||||
}
|
}
|
||||||
|
nextp->lname_len = strlen(nextp->lname);
|
||||||
|
|
||||||
strlcpy(namebuf, dp->d_name, sizeof(namebuf));
|
|
||||||
len = strlen(namebuf);
|
|
||||||
nextp->ino = sbuf.st_ino;
|
nextp->ino = sbuf.st_ino;
|
||||||
nextp->prop->length = (unsigned)sbuf.st_size;
|
nextp->prop->length = (unsigned)sbuf.st_size;
|
||||||
nextp->prop->wdate = (unsigned)ToLispTime(sbuf.st_mtime);
|
nextp->prop->wdate = (unsigned)ToLispTime(sbuf.st_mtime);
|
||||||
nextp->prop->rdate = (unsigned)ToLispTime(sbuf.st_atime);
|
nextp->prop->rdate = (unsigned)ToLispTime(sbuf.st_atime);
|
||||||
nextp->prop->protect = (unsigned)sbuf.st_mode;
|
nextp->prop->protect = (unsigned)sbuf.st_mode;
|
||||||
/*
|
|
||||||
TIMEOUT(pwd = getpwuid(sbuf.st_uid));
|
|
||||||
if (pwd == (struct passwd *)NULL) {
|
|
||||||
nextp->prop->au_len = 0;
|
|
||||||
} else {
|
|
||||||
len = strlen(pwd->pw_name);
|
|
||||||
strlcpy(nextp->prop->author, pwd->pw_name, sizeof(nextp->prop->author));
|
|
||||||
*(nextp->prop->author + len) = '\0';
|
|
||||||
nextp->prop->au_len = len;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
if (n > 0) *finfo_buf = prevp;
|
if (n > 0) *finfo_buf = prevp;
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
@@ -1369,6 +1302,7 @@ static int enum_ufs(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
if (nextp == (FINFO *)NULL) {
|
if (nextp == (FINFO *)NULL) {
|
||||||
FreeFinfo(prevp);
|
FreeFinfo(prevp);
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
|
alarm(0); // cancel alarm from S_TOUT
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
nextp->next = prevp;
|
nextp->next = prevp;
|
||||||
@@ -1390,7 +1324,7 @@ static int enum_ufs(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
quote_dname(namebuf, sizeof(namebuf));
|
quote_dname(namebuf, sizeof(namebuf));
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
len = strlen(namebuf);
|
||||||
*(nextp->lname + len) = DIRCHAR;
|
*(nextp->lname + len) = LISPDIRCHAR;
|
||||||
*(nextp->lname + len + 1) = '\0';
|
*(nextp->lname + len + 1) = '\0';
|
||||||
nextp->lname_len = len + 1;
|
nextp->lname_len = len + 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -1442,49 +1376,38 @@ static int enum_ufs(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
|||||||
AllocFinfo(nextp);
|
AllocFinfo(nextp);
|
||||||
if (nextp == (FINFO *)NULL) {
|
if (nextp == (FINFO *)NULL) {
|
||||||
FreeFinfo(prevp);
|
FreeFinfo(prevp);
|
||||||
closedir(dirp);
|
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
nextp->next = prevp;
|
nextp->next = prevp;
|
||||||
snprintf(namebuf, sizeof(namebuf), "%s/%s", dir, dp->d_name);
|
snprintf(namebuf, sizeof(namebuf), "%s/%s", dir, dp->d_name);
|
||||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
TIMEOUT(rval = stat(namebuf, &sbuf)); // cancels alarm from S_TOUT
|
||||||
if (rval == -1 && errno != ENOENT) {
|
if (rval == -1 && errno != ENOENT) {
|
||||||
/*
|
/*
|
||||||
* ENOENT error might be caused by missing symbolic
|
* ENOENT error might be caused by missing symbolic
|
||||||
* link. We should ignore such error here.
|
* link. We should ignore such error here.
|
||||||
*/
|
*/
|
||||||
FreeFinfo(nextp);
|
FreeFinfo(nextp);
|
||||||
closedir(dirp);
|
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
|
TIMEOUT(closedir(dirp));
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(namebuf, dp->d_name, sizeof(namebuf));
|
strlcpy(nextp->lname, dp->d_name, sizeof(nextp->lname));
|
||||||
if (S_ISDIR(sbuf.st_mode)) {
|
if (S_ISDIR(sbuf.st_mode)) {
|
||||||
nextp->dirp = 1;
|
nextp->dirp = 1;
|
||||||
quote_dname(namebuf, sizeof(namebuf));
|
quote_dname(nextp->lname, sizeof(nextp->lname));
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
strlcat(nextp->lname, LISPDIRSTR, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
|
||||||
*(nextp->lname + len) = DIRCHAR;
|
|
||||||
*(nextp->lname + len + 1) = '\0';
|
|
||||||
nextp->lname_len = len + 1;
|
|
||||||
} else {
|
} else {
|
||||||
/* All other types than directory. */
|
|
||||||
nextp->dirp = 0;
|
nextp->dirp = 0;
|
||||||
quote_fname_ufs(namebuf, sizeof(namebuf));
|
quote_fname(nextp->lname, sizeof(nextp->lname));
|
||||||
len = strlen(namebuf);
|
|
||||||
strlcpy(nextp->lname, namebuf, sizeof(nextp->lname));
|
|
||||||
*(nextp->lname + len) = '\0';
|
|
||||||
nextp->lname_len = len;
|
|
||||||
}
|
}
|
||||||
|
nextp->lname_len = strlen(nextp->lname);
|
||||||
strlcpy(namebuf, dp->d_name, sizeof(namebuf));
|
|
||||||
len = strlen(namebuf);
|
|
||||||
nextp->ino = sbuf.st_ino;
|
nextp->ino = sbuf.st_ino;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
if (n > 0) *finfo_buf = prevp;
|
if (n > 0) *finfo_buf = prevp;
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/dsk.c
14
src/dsk.c
@@ -671,7 +671,7 @@ LispPTR COM_closefile(LispPTR *args)
|
|||||||
time[1].tv_sec = (long)ToUnixTime(cdate);
|
time[1].tv_sec = (long)ToUnixTime(cdate);
|
||||||
time[1].tv_usec = 0L;
|
time[1].tv_usec = 0L;
|
||||||
#endif /* DOS */
|
#endif /* DOS */
|
||||||
TIMEOUT(rval = close(fd));
|
TIMEOUT(rval = close(fd)); // cancels alarm from S_TOUT
|
||||||
if (rval == -1) {
|
if (rval == -1) {
|
||||||
*Lisp_errno = errno;
|
*Lisp_errno = errno;
|
||||||
return (NIL);
|
return (NIL);
|
||||||
@@ -1486,7 +1486,6 @@ LispPTR DSK_directorynamep(LispPTR *args)
|
|||||||
if (len > MAXPATHLEN - 2) FileNameTooLong(NIL);
|
if (len > MAXPATHLEN - 2) FileNameTooLong(NIL);
|
||||||
|
|
||||||
LispStringToCString(args[0], dirname, MAXPATHLEN);
|
LispStringToCString(args[0], dirname, MAXPATHLEN);
|
||||||
|
|
||||||
/* Convert Xerox Lisp file naming convention to Unix one. */
|
/* Convert Xerox Lisp file naming convention to Unix one. */
|
||||||
#ifdef DOS
|
#ifdef DOS
|
||||||
separate_drive(dirname, drive);
|
separate_drive(dirname, drive);
|
||||||
@@ -2708,13 +2707,13 @@ static int locate_file(char *dir, size_t dirsize, char *name)
|
|||||||
DIR_OR_FILE_P(path, type);
|
DIR_OR_FILE_P(path, type);
|
||||||
if (type != 0) {
|
if (type != 0) {
|
||||||
strlcpy(dir, path, dirsize);
|
strlcpy(dir, path, dirsize);
|
||||||
TIMEOUT(closedir(dirp));
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
return (type);
|
return (type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TIMEOUT(closedir(dirp));
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
return (0);
|
return (0);
|
||||||
#endif /* DOS */
|
#endif /* DOS */
|
||||||
}
|
}
|
||||||
@@ -3081,6 +3080,7 @@ static int get_version_array(char *dir, char *file)
|
|||||||
varray_index++;
|
varray_index++;
|
||||||
if (varray_index >= VERSIONARRAYMAXLENGTH) {
|
if (varray_index >= VERSIONARRAYMAXLENGTH) {
|
||||||
*Lisp_errno = EIO;
|
*Lisp_errno = EIO;
|
||||||
|
alarm(0); // cancel alarm from S_TOUT
|
||||||
return (0);
|
return (0);
|
||||||
} else if (varray_index >= VA.allocated) {
|
} else if (varray_index >= VA.allocated) {
|
||||||
VA.allocated += VERSIONARRAYCHUNKLENGTH;
|
VA.allocated += VERSIONARRAYCHUNKLENGTH;
|
||||||
@@ -3088,7 +3088,7 @@ static int get_version_array(char *dir, char *file)
|
|||||||
sizeof(*VA.files) * VA.allocated);
|
sizeof(*VA.files) * VA.allocated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
alarm(0); // cancel alarm from S_TOUT
|
||||||
/*
|
/*
|
||||||
* The last entry of VA.files is indicated by setting LASTVERSIONARRAY into
|
* The last entry of VA.files is indicated by setting LASTVERSIONARRAY into
|
||||||
* version_no field.
|
* version_no field.
|
||||||
@@ -3192,6 +3192,7 @@ static int get_version_array(char *dir, char *file)
|
|||||||
varray_index++;
|
varray_index++;
|
||||||
if (varray_index >= VERSIONARRAYMAXLENGTH) {
|
if (varray_index >= VERSIONARRAYMAXLENGTH) {
|
||||||
*Lisp_errno = EIO;
|
*Lisp_errno = EIO;
|
||||||
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
return (0);
|
return (0);
|
||||||
} else if (varray_index >= VA.allocated) {
|
} else if (varray_index >= VA.allocated) {
|
||||||
VA.allocated += VERSIONARRAYCHUNKLENGTH;
|
VA.allocated += VERSIONARRAYCHUNKLENGTH;
|
||||||
@@ -3200,6 +3201,8 @@ static int get_version_array(char *dir, char *file)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TIMEOUT(closedir(dirp)); // cancels alarm from S_TOUT
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The last entry of varray is indicated by setting LASTVERSIONARRAY into
|
* The last entry of varray is indicated by setting LASTVERSIONARRAY into
|
||||||
* version_no field.
|
* version_no field.
|
||||||
@@ -3223,7 +3226,6 @@ static int get_version_array(char *dir, char *file)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TIMEOUT(closedir(dirp));
|
|
||||||
return (1);
|
return (1);
|
||||||
#endif /* DOS */
|
#endif /* DOS */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user