Index: stable/9/usr.bin/at =================================================================== --- stable/9/usr.bin/at (revision 252030) +++ stable/9/usr.bin/at (working copy) Property changes on: stable/9/usr.bin/at ___________________________________________________________________ Added: svn:mergeinfo Merged /head/usr.bin/at:r226702,227006,228761,228857,229067,229538,229997,230127,230555,231544,232274,232322,232994,233121,234206,234449,234772,234782,235915,236338,236346,236365,238514,240605,240954,248112,249406 Merged /vendor/resolver/dist/usr.bin/at:r1540-186085 Merged /projects/largeSMP/usr.bin/at:r221273-222812,222815-223757 Merged /projects/quota64/usr.bin/at:r184125-207707 Index: stable/9/usr.bin/at/at.c =================================================================== --- stable/9/usr.bin/at/at.c (revision 252030) +++ stable/9/usr.bin/at/at.c (working copy) @@ -533,6 +533,10 @@ /* Delete every argument (job - ID) given */ int i; + int rc; + int nofJobs; + int nofDone; + int statErrno; struct stat buf; DIR *spool; struct dirent *dirent; @@ -540,6 +544,9 @@ char queue; long jobno; + nofJobs = argc - optind; + nofDone = 0; + PRIV_START if (chdir(ATJOB_DIR) != 0) @@ -555,9 +562,20 @@ while((dirent = readdir(spool)) != NULL) { PRIV_START - if (stat(dirent->d_name, &buf) != 0) - perr("cannot stat in " ATJOB_DIR); + rc = stat(dirent->d_name, &buf); + statErrno = errno; PRIV_END + /* There's a race condition between readdir above and stat here: + * another atrm process could have removed the file from the spool + * directory under our nose. If this happens, stat will set errno to + * ENOENT, which we shouldn't treat as fatal. + */ + if (rc != 0) { + if (statErrno == ENOENT) + continue; + else + perr("cannot stat in " ATJOB_DIR); + } if(sscanf(dirent->d_name, "%c%5lx%8lx", &queue, &jobno, &ctm)!=3) continue; @@ -603,9 +621,15 @@ errx(EXIT_FAILURE, "internal error, process_jobs = %d", what); } + + /* All arguments have been processed + */ + if (++nofDone == nofJobs) + goto end; } } } +end: closedir(spool); } /* delete_jobs */