From owner-svn-src-head@FreeBSD.ORG Fri Apr 12 14:32:17 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 534714D8; Fri, 12 Apr 2013 14:32:17 +0000 (UTC) (envelope-from gahr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 2B619AD8; Fri, 12 Apr 2013 14:32:17 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r3CEWHsc034436; Fri, 12 Apr 2013 14:32:17 GMT (envelope-from gahr@svn.freebsd.org) Received: (from gahr@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r3CEWHBc034435; Fri, 12 Apr 2013 14:32:17 GMT (envelope-from gahr@svn.freebsd.org) Message-Id: <201304121432.r3CEWHBc034435@svn.freebsd.org> From: Pietro Cerutti Date: Fri, 12 Apr 2013 14:32:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r249406 - head/usr.bin/at X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Apr 2013 14:32:17 -0000 Author: gahr (ports committer) Date: Fri Apr 12 14:32:16 2013 New Revision: 249406 URL: http://svnweb.freebsd.org/changeset/base/249406 Log: - Do not bail out if stat(2) fails with ENOENT in the spool directory. This happens if another atrm process removes a job while we're scanning through the directory. - While at it, optimize a bit the directory scanning, so that we quit looping as soon as all jobs specified in argv have been dealt with. Approved by: cognet Modified: head/usr.bin/at/at.c Modified: head/usr.bin/at/at.c ============================================================================== --- head/usr.bin/at/at.c Fri Apr 12 14:23:21 2013 (r249405) +++ head/usr.bin/at/at.c Fri Apr 12 14:32:16 2013 (r249406) @@ -531,6 +531,10 @@ process_jobs(int argc, char **argv, int /* Delete every argument (job - ID) given */ int i; + int rc; + int nofJobs; + int nofDone; + int statErrno; struct stat buf; DIR *spool; struct dirent *dirent; @@ -538,6 +542,9 @@ process_jobs(int argc, char **argv, int char queue; long jobno; + nofJobs = argc - optind; + nofDone = 0; + PRIV_START if (chdir(ATJOB_DIR) != 0) @@ -553,9 +560,20 @@ process_jobs(int argc, char **argv, int 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; @@ -601,9 +619,15 @@ process_jobs(int argc, char **argv, int errx(EXIT_FAILURE, "internal error, process_jobs = %d", what); } + + /* All arguments have been processed + */ + if (++nofDone == nofJobs) + goto end; } } } +end: closedir(spool); } /* delete_jobs */