From: Kern Sibbald Date: Tue, 25 Oct 2011 14:32:16 +0000 (+0200) Subject: Prohibit multiple Jobs from writing state file at same time X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ecd3f1bc31e9c386dbc23d1972eb01f39115d647;p=bacula%2Fbacula Prohibit multiple Jobs from writing state file at same time --- diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index 04a30d02d4..561d0bb723 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -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); }