[9158] in Athena Bugs
7.3P VAX/RT: find -depth
daemon@ATHENA.MIT.EDU (Richard Basch)
Thu Apr 2 13:32:58 1992
Date: Thu, 2 Apr 92 13:32:44 -0500
To: bugs@MIT.EDU
From: "Richard Basch" <basch@MIT.EDU>
find -depth is broken. It doesn't seem to traverse all the directories
it is supposed to. The reason is that the stat structure is being
clobbered.
The following patch fixes that problem (and it also allows compilation
under AIX, not that we do so). One other inconsistency of not enclosing
something in #ifndef NO_PW_STAYOPEN has been fixed (it was used
elsewhere in the code, but was overlooked in one place).
It has been tested on the various BSD platforms (and AIX, which was
where I started my debugging).
The problem was discovered while trying to write the NFS-AFS migration
script. The depth traversal for acl settings was breaking...
Patch:
*** /source/bsd-4.3/common/usr.bin/find/find.c Wed Jul 11 13:50:37 1990
--- /afs/athena.mit.edu/user/p/r/probe/src//find.c Thu Apr 2 13:23:52 1992
***************
*** 684,689 ****
--- 684,690 ----
register char *c1;
int rv = 0;
char *endofname;
+ struct stat *Stat2;
if (lstat(fname, &Statb)<0) {
fprintf(stderr, "find: bad status < %s > (%s)\n",
***************
*** 696,701 ****
--- 697,711 ----
!Xdev && Devstat.st_dev != Statb.st_dev) {
return(1);
}
+ if (Depth) {
+ Stat2 = (struct stat *)malloc(sizeof(struct stat));
+ if (Stat2)
+ bcopy((char *)&Statb, (char *)Stat2, sizeof(struct stat));
+ else {
+ fprintf(stderr, "find: Out of memory\n");
+ exit(1);
+ }
+ }
for (c1 = name; *c1; ++c1);
if (*(c1-1) == '/')
***************
*** 735,740 ****
--- 745,752 ----
fprintf(stderr, "find: bad directory <%s>\n", name);
rv = 0;
} else if (Depth) {
+ bcopy((char *)Stat2, (char *)&Statb, sizeof(struct stat));
+ free(Stat2);
(*exlist->F)(exlist);
}
return(rv);
***************
*** 1020,1028 ****
--- 1032,1042 ----
register struct passwd *pw;
struct passwd *getpwent();
register int cp;
+ #ifndef NO_PW_STAYOPEN
extern int _pw_stayopen;
_pw_stayopen = 1;
+ #endif
#if (((NUID) & ((NUID) - 1)) != 0)
cp = uid % (NUID);
***************
*** 1245,1251 ****
printf("%6lu %4ld %s %2d %s%s%s %s %s%s%s\n",
stp->st_ino, /* inode # */
! #ifdef S_IFSOCK
(long) kbytes(dbtob(stp->st_blocks)), /* kbytes */
#else
(long) kbytes(stp->st_size), /* kbytes */
--- 1259,1265 ----
printf("%6lu %4ld %s %2d %s%s%s %s %s%s%s\n",
stp->st_ino, /* inode # */
! #if defined(S_IFSOCK) && !defined(_AIX)
(long) kbytes(dbtob(stp->st_blocks)), /* kbytes */
#else
(long) kbytes(stp->st_size), /* kbytes */