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

Guy Helmer guy.helmer at gmail.com
Wed Jun 5 21:30:01 UTC 2013


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

From: Guy Helmer <guy.helmer at gmail.com>
To: bug-followup at FreeBSD.org,
 freebsd at sopwith.solgatos.com
Cc:  
Subject: Re: bin/113239: [patch] atrun(8) loses jobs due to race condition
Date: Wed, 5 Jun 2013 16:13:09 -0500

 I'm not comfortable with working around the race condition by =
 determining whether a file seems "too old". Would serializing access to =
 the queue work using the following patch:
 
 Index: atrun.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 --- atrun.c	(revision 251433)
 +++ atrun.c	(working copy)
 @@ -31,6 +31,7 @@
  /* System Headers */
 =20
  #include <sys/fcntl.h>
 +#include <sys/file.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  #ifdef __FreeBSD__
 @@ -521,6 +522,9 @@
      if ((spool =3D opendir(".")) =3D=3D NULL)
  	perr("cannot read %s", ATJOB_DIR);
 =20
 +    if (flock(dirfd(spool), LOCK_EX) =3D=3D -1)
 +	perr("cannot lock %s", ATJOB_DIR);
 +
      now =3D time(NULL);
      run_batch =3D 0;
      batch_uid =3D (uid_t) -1;
 


More information about the freebsd-bugs mailing list