From ca71eb8272be3068e8cb7fe3d0ecbbbf7bf179d6 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 29 Dec 2002 20:04:17 +0000 Subject: [PATCH] Fix FreeBSD mutex problem in stored.c git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@254 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/ChangeLog | 3 +++ bacula/src/stored/stored.c | 21 ++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/bacula/ChangeLog b/bacula/ChangeLog index 03e80ce04a..7d3e623f07 100644 --- a/bacula/ChangeLog +++ b/bacula/ChangeLog @@ -16,6 +16,9 @@ Changes submitted this submission: - Added --enable-client-only to ./configure - Modified --enable-static-sd to work better and documented it. - Fixed Restore options (never,ifnewer, ...). They now work. +- Moved the stored.c Resource lock into the allocation thread so + that the same thread sets/clears it. This created a problem on + FreeBSD. 28Dec02 - Added more rescue documentation. - Did a spell check of the Bacula doc. diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index 35d50f4a8a..91b360891b 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -183,22 +183,21 @@ int main (int argc, char *argv[]) /* Make sure on Solaris we can run concurrent, watch dog + servers + misc */ set_thread_concurrency(me->max_concurrent_jobs * 2 + 4); - /* - * Here we lock the resources then fire off the device allocation - * thread. That thread will release the resources when all the - * devices are allocated. This allows use to start the server - * right away, but any jobs will wait until the resources are - * unlocked. - */ - LockRes(); + /* + * Start the device allocation thread + */ if (pthread_create(&thid, NULL, device_allocation, NULL) != 0) { Emsg1(M_ABORT, 0, _("Unable to create thread. ERR=%s\n"), strerror(errno)); } - - start_watchdog(); /* start watchdog thread */ + /* + * Sleep a bit to give device thread a chance to lock the resource + * chain before we start the server. + */ + sleep(1); + /* Single server used for Director and File daemon */ bnet_thread_server(me->SDaddr, me->SDport, me->max_concurrent_jobs * 2 + 1, &dird_workq, connection_request); @@ -283,9 +282,9 @@ static void *device_allocation(void *arg) int i; DEVRES *device; + LockRes(); pthread_detach(pthread_self()); - /* LockRes() alread done */ for (device=NULL,i=0; (device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device)); i++) { Dmsg1(90, "calling init_dev %s\n", device->device_name); device->dev = init_dev(NULL, device); -- 2.39.5