]> 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>
Sat, 20 Apr 2013 12:50:07 +0000 (14:50 +0200)
bacula/src/lib/bsys.c

index 04a30d02d43adc1e0ecd25a7e2e852f128e53a25..561d0bb723a8f49ed60ec08be823a0644917f32b 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);
 }