From owner-freebsd-bugs@FreeBSD.ORG Fri Jun 7 17:10:01 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 3668C170 for ; Fri, 7 Jun 2013 17:10:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 0D09E1B01 for ; Fri, 7 Jun 2013 17:10:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r57HA0OZ075970 for ; Fri, 7 Jun 2013 17:10:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r57HA02n075968; Fri, 7 Jun 2013 17:10:00 GMT (envelope-from gnats) Date: Fri, 7 Jun 2013 17:10:00 GMT Message-Id: <201306071710.r57HA02n075968@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Dieter BSD Subject: Re: bin/113239: [patch] atrun(8) loses jobs due to race condition X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Dieter BSD List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jun 2013 17:10:01 -0000 The following reply was made to PR bin/113239; it has been noted by GNATS. From: Dieter BSD To: bug-followup@FreeBSD.org, guy.helmer@gmail.com Cc: Subject: Re: bin/113239: [patch] atrun(8) loses jobs due to race condition Date: Fri, 7 Jun 2013 10:07:05 -0700 The flock fix seems to work (after getting it to compile). Thank you. The error message complaining about "Cannot open input file" really needs to provide the filename. (There are a few other error messages that could benefit from a similar improvement.) =================================================================== RCS file: RCS/atrun.c,v retrieving revision 1.1 diff -u -r1.1 atrun.c --- atrun.c 2013/06/06 20:41:09 1.1 +++ atrun.c 2013/06/07 16:39:59 @@ -31,6 +31,7 @@ /* System Headers */ #include +#include #include #include #include @@ -70,11 +71,11 @@ /* Macros */ #ifndef ATJOB_DIR -#define ATJOB_DIR "/usr/spool/atjobs/" +#define ATJOB_DIR "/var/at/jobs/" #endif #ifndef ATSPOOL_DIR -#define ATSPOOL_DIR "/usr/spool/atspool/" +#define ATSPOOL_DIR "/var/at/spool/" #endif #ifndef LOADAVG_MX @@ -141,6 +142,12 @@ PRIV_END +#define SLEEP_TEST 0 /* Test fix for PR bin/113239 */ +#ifdef SLEEP_TEST + syslog(LOG_DEBUG, "Sleeping to trigger race condition, file=%s\n", filename); + sleep(70); +#endif + pid = fork(); if (pid == -1) perr("cannot fork"); @@ -176,7 +183,11 @@ #endif if (stream == NULL) - perr("cannot open input file"); + { + char error_string[1024]; + sprintf(error_string, "Cannot open input file %s\n", filename); + perr(error_string); + } if ((fd_in = dup(fileno(stream))) <0) perr("error duplicating input file descriptor"); @@ -444,6 +455,16 @@ if ((spool = opendir(".")) == NULL) perr("cannot read " ATJOB_DIR); +#define WITH_FIX 1 +#ifdef WITH_FIX + if (flock(dirfd(spool), LOCK_EX) == -1) /* Fix for PR bin/113239 */ + { + char error_string[1024]; + sprintf(error_string,"cannot lock %s", ATJOB_DIR); + perr(error_string); + } +#endif + now = time(NULL); run_batch = 0; batch_uid = (uid_t) -1;