Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/3/84; site genrad.UUCP Path: utzoo!decvax!genrad!sources-request From: sources-request@genrad.UUCP Newsgroups: mod.sources Subject: bm bug fix Message-ID: <1005@genrad.UUCP> Date: Tue, 6-Aug-85 09:40:14 EDT Article-I.D.: genrad.1005 Posted: Tue Aug 6 09:40:14 1985 Date-Received: Tue, 6-Aug-85 23:42:15 EDT Sender: john@genrad.UUCP Lines: 113 Approved: john@genrad.UUCP 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 */