2 * This file handles locking and seaching resources
4 * Kern Sibbald, January MM
5 * Split from parse_conf.c April MMV
10 Bacula® - The Network Backup Solution
12 Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
14 The main author of Bacula is Kern Sibbald, with contributions from
15 many others, a complete list can be found in the file AUTHORS.
16 This program is Free Software; you can redistribute it and/or
17 modify it under the terms of version two of the GNU General Public
18 License as published by the Free Software Foundation plus additions
19 that are listed in the file LICENSE.
21 This program is distributed in the hope that it will be useful, but
22 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 Bacula® is a registered trademark of John Walker.
32 The licensor of Bacula is the Free Software Foundation Europe
33 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
34 Switzerland, email:ftf@fsfeurope.org.
39 /* Each daemon has a slightly different set of
40 * resources, so it will define the following
45 extern RES_TABLE resources[];
46 extern RES **res_head;
48 brwlock_t res_lock; /* resource lock */
49 static int res_locked = 0; /* set when resource chains locked -- for debug */
52 /* #define TRACE_RES */
54 void b_LockRes(const char *file, int line)
58 Pmsg4(000, "LockRes locked=%d w_active=%d at %s:%d\n",
59 res_locked, res_lock.w_active, file, line);
61 Pmsg2(000, "LockRes writerid=%d myid=%d\n", res_lock.writer_id,
65 if ((errstat=rwl_writelock(&res_lock)) != 0) {
66 Emsg3(M_ABORT, 0, _("rwl_writelock failure at %s:%d: ERR=%s\n"),
67 file, line, strerror(errstat));
72 void b_UnlockRes(const char *file, int line)
75 if ((errstat=rwl_writeunlock(&res_lock)) != 0) {
76 Emsg3(M_ABORT, 0, _("rwl_writeunlock failure at %s:%d:. ERR=%s\n"),
77 file, line, strerror(errstat));
81 Pmsg4(000, "UnLockRes locked=%d wactive=%d at %s:%d\n",
82 res_locked, res_lock.w_active, file, line);
87 * Return resource of type rcode that matches name
90 GetResWithName(int rcode, char *name)
93 int rindex = rcode - r_first;
96 res = res_head[rindex];
98 if (strcmp(res->name, name) == 0) {
109 * Return next resource of type rcode. On first
110 * call second arg (res) is NULL, on subsequent
111 * calls, it is called with previous value.
114 GetNextRes(int rcode, RES *res)
117 int rindex = rcode - r_first;
120 nres = res_head[rindex];