bin/113239: [patch] atrun(8) loses jobs due to race condition

Dieter BSD dieterbsd at gmail.com
Fri Jun 7 17:10:01 UTC 2013


The following reply was made to PR bin/113239; it has been noted by GNATS.

From: Dieter BSD <dieterbsd at gmail.com>
To: bug-followup at FreeBSD.org, guy.helmer at 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 <sys/fcntl.h>
 +#include <sys/file.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <sys/wait.h>
 @@ -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;


More information about the freebsd-bugs mailing list