From 20c22cb5bb905d526c7d8067d3cc1afd03c725a4 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 25 Oct 2011 16:32:16 +0200 Subject: [PATCH] Prohibit multiple Jobs from writing state file at same time --- bacula/src/lib/bsys.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index 3bff1c5f78..a1323a8cf3 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); } -- 2.39.5