2 * This file handles locking and seaching resources
4 * Kern Sibbald, January MM
5 * Split from parse_conf.c April MMV
10 Copyright (C) 2000-2006 Kern Sibbald
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 version 2 as amended with additional clauses defined in the
15 file LICENSE in the main source directory.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 the file LICENSE for additional details.
26 extern int debug_level;
28 /* Each daemon has a slightly different set of
29 * resources, so it will define the following
34 extern RES_TABLE resources[];
35 extern RES **res_head;
37 brwlock_t res_lock; /* resource lock */
38 static int res_locked = 0; /* set when resource chains locked -- for debug */
41 /* #define TRACE_RES */
43 void b_LockRes(const char *file, int line)
47 Pmsg4(000, "LockRes locked=%d w_active=%d at %s:%d\n",
48 res_locked, res_lock.w_active, file, line);
50 Pmsg2(000, "LockRes writerid=%d myid=%d\n", res_lock.writer_id,
54 if ((errstat=rwl_writelock(&res_lock)) != 0) {
55 Emsg3(M_ABORT, 0, _("rwl_writelock failure at %s:%d: ERR=%s\n"),
56 file, line, strerror(errstat));
61 void b_UnlockRes(const char *file, int line)
64 if ((errstat=rwl_writeunlock(&res_lock)) != 0) {
65 Emsg3(M_ABORT, 0, _("rwl_writeunlock failure at %s:%d:. ERR=%s\n"),
66 file, line, strerror(errstat));
70 Pmsg4(000, "UnLockRes locked=%d wactive=%d at %s:%d\n",
71 res_locked, res_lock.w_active, file, line);
76 * Return resource of type rcode that matches name
79 GetResWithName(int rcode, char *name)
82 int rindex = rcode - r_first;
85 res = res_head[rindex];
87 if (strcmp(res->name, name) == 0) {
98 * Return next resource of type rcode. On first
99 * call second arg (res) is NULL, on subsequent
100 * calls, it is called with previous value.
103 GetNextRes(int rcode, RES *res)
106 int rindex = rcode - r_first;
109 nres = res_head[rindex];