2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * This file handles locking and seaching resources
22 * Kern Sibbald, January MM
23 * Split from parse_conf.c April MMV
29 /* Each daemon has a slightly different set of
30 * resources, so it will define the following
33 extern int32_t r_first;
34 extern int32_t r_last;
35 extern RES_TABLE resources[];
36 extern RES **res_head;
38 brwlock_t res_lock; /* resource lock */
39 static int res_locked = 0; /* resource chain lock count -- for debug */
42 /* #define TRACE_RES */
44 void b_LockRes(const char *file, int line)
48 Pmsg4(000, "LockRes locked=%d w_active=%d at %s:%d\n",
49 res_locked, res_lock.w_active, file, line);
51 Pmsg2(000, "LockRes writerid=%d myid=%d\n", res_lock.writer_id,
55 if ((errstat=rwl_writelock(&res_lock)) != 0) {
56 Emsg3(M_ABORT, 0, _("rwl_writelock failure at %s:%d: ERR=%s\n"),
57 file, line, strerror(errstat));
62 void b_UnlockRes(const char *file, int line)
65 if ((errstat=rwl_writeunlock(&res_lock)) != 0) {
66 Emsg3(M_ABORT, 0, _("rwl_writeunlock failure at %s:%d:. ERR=%s\n"),
67 file, line, strerror(errstat));
71 Pmsg4(000, "UnLockRes locked=%d wactive=%d at %s:%d\n",
72 res_locked, res_lock.w_active, file, line);
77 * Return resource of type rcode that matches name
80 GetResWithName(int rcode, const char *name)
83 int rindex = rcode - r_first;
86 res = res_head[rindex];
88 if (strcmp(res->name, name) == 0) {
99 * Return next resource of type rcode. On first
100 * call second arg (res) is NULL, on subsequent
101 * calls, it is called with previous value.
104 GetNextRes(int rcode, RES *res)
107 int rindex = rcode - r_first;
110 nres = res_head[rindex];