]> git.sur5r.net Git - bacula/bacula/commitdiff
Prohibit multiple Jobs from writing state file at same time
authorKern Sibbald <kern@sibbald.com>
Tue, 25 Oct 2011 14:32:16 +0000 (16:32 +0200)
committerKern Sibbald <kern@sibbald.com>
Tue, 25 Oct 2011 14:54:15 +0000 (16:54 +0200)
bacula/src/lib/bsys.c

index 3bff1c5f783091c28ce7caf1a543df43df507e3d..a1323a8cf37d5070c12984ed08c2e826f2ac7739 100644 (file)
@@ -547,12 +547,15 @@ bail_out:
 /*
  * Write the state file
  */
+static pthread_mutex_t state_mutex = PTHREAD_MUTEX_INITIALIZER;
+
 void write_state_file(char *dir, const char *progname, int port)
 {
    int sfd;
    bool ok = false;
    POOLMEM *fname = get_pool_memory(PM_FNAME);
-
+   
+   P(state_mutex);                    /* Only one job at a time can call here */
    Mmsg(&fname, "%s/%s.%d.state", dir, progname, port);
    /* Create new state file */
    unlink(fname);
@@ -590,6 +593,7 @@ bail_out:
    if (!ok) {
       unlink(fname);
    }
+   V(state_mutex);
    free_pool_memory(fname);
 }