sources-request@genrad.UUCP (08/06/85)
Mod.sources: Volume 2, Issue 36 Submitted by: seismo!mcvax!ken (Ken Yap) Problem: Bm quits when encountering an unreadable file (no permission, file does not exist) with an exit status of 2. The grep family prints an error message and continues searching. Repeat-by: # in some directory with a C main program echo main > xxx chmod 200 xxx bm main xxx *.c # compare with grep main xxx *.c Fix: Apply the patch below. *** bm.c.old Tue Aug 6 10:34:57 1985 --- bm.c Tue Aug 6 10:41:22 1985 *************** *** 17,22 * machines which would complain) */ int ret = 1, /* return code from Execute */ NFiles, NPats; /* number of patterns to search for */ char i, --- 17,23 ----- * machines which would complain) */ int ret = 1, /* return code from Execute */ + NotFound = 0, /* non-zero if file not readable */ NFiles, NPats; /* number of patterns to search for */ char i, *************** *** 76,82 if ((NFiles > 1) || lFlag) FileName = *OptPtr; if ((TextFile = open(*OptPtr,O_RDONLY,0)) < 0) { fprintf(stderr,"bm: can't open %s\n",*OptPtr); ! exit(2); } /* if */ ret &= Execute(DescVec,NPats,TextFile,BigBuff+1); if (sFlag && !ret) --- 77,89 ----- if ((NFiles > 1) || lFlag) FileName = *OptPtr; if ((TextFile = open(*OptPtr,O_RDONLY,0)) < 0) { fprintf(stderr,"bm: can't open %s\n",*OptPtr); ! NotFound++; ! } ! else { ! ret &= Execute(DescVec,NPats,TextFile,BigBuff+1); ! if (sFlag && !ret) ! exit(0); ! close(TextFile); } /* if */ ++OptPtr; } /* while */ *************** *** 78,86 fprintf(stderr,"bm: can't open %s\n",*OptPtr); exit(2); } /* if */ - ret &= Execute(DescVec,NPats,TextFile,BigBuff+1); - if (sFlag && !ret) - exit(0); ++OptPtr; close(TextFile); } /* while */ --- 85,90 ----- exit(0); close(TextFile); } /* if */ ++OptPtr; } /* while */ if (cFlag) printf("%d\n",MatchCount); *************** *** 82,88 if (sFlag && !ret) exit(0); ++OptPtr; - close(TextFile); } /* while */ if (cFlag) printf("%d\n",MatchCount); exit(ret); --- 86,91 ----- close(TextFile); } /* if */ ++OptPtr; } /* while */ if (cFlag) printf("%d\n",MatchCount); exit(NotFound ? 2 : ret); *************** *** 85,89 close(TextFile); } /* while */ if (cFlag) printf("%d\n",MatchCount); ! exit(ret); } /* main */ --- 88,92 ----- ++OptPtr; } /* while */ if (cFlag) printf("%d\n",MatchCount); ! exit(NotFound ? 2 : ret); } /* main */