From ecd3f1bc31e9c386dbc23d1972eb01f39115d647 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 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); } -- 2.39.5