Skip to content

Commit

Permalink
config: LockRes und UnlockRes now with pointer to ConfigurationParser…
Browse files Browse the repository at this point in the history
… as parameter
  • Loading branch information
franku committed Sep 10, 2018
1 parent a1edf9a commit 4a3e09a
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 160 deletions.
28 changes: 14 additions & 14 deletions core/src/console/console.cc
Expand Up @@ -886,24 +886,24 @@ static bool SelectDirector(const char *director, DirectorResource **ret_dir, Con
*ret_cons = NULL;
*ret_dir = NULL;

LockRes();
LockRes(my_config);
numdir = 0;
foreach_res(director_resource, R_DIRECTOR) { numdir++; }
numcon = 0;
foreach_res(console_resource, R_CONSOLE) { numcon++; }
UnlockRes();
UnlockRes(my_config);

if (numdir == 1) { /* No choose */
director_resource = (DirectorResource *)my_config->GetNextRes(R_DIRECTOR, NULL);
}

if (director) { /* Command line choice overwrite the no choose option */
LockRes();
LockRes(my_config);
foreach_res(director_resource, R_DIRECTOR)
{
if (bstrcmp(director_resource->name(), director)) { break; }
}
UnlockRes();
UnlockRes(my_config);
if (!director_resource) { /* Can't find Director used as argument */
senditf(_("Can't find %s in Director list\n"), director);
return 0;
Expand All @@ -914,14 +914,14 @@ static bool SelectDirector(const char *director, DirectorResource **ret_dir, Con
UA_sock = New(BareosSocketTCP);
try_again:
sendit(_("Available Directors:\n"));
LockRes();
LockRes(my_config);
numdir = 0;
foreach_res(director_resource, R_DIRECTOR)
{
senditf(_("%2d: %s at %s:%d\n"), 1 + numdir++, director_resource->name(), director_resource->address,
director_resource->DIRport);
}
UnlockRes();
UnlockRes(my_config);
if (GetCmd(stdin, _("Select Director by entering a number: "), UA_sock, 600) < 0) {
WSACleanup(); /* Cleanup Windows sockets */
return 0;
Expand All @@ -938,18 +938,18 @@ static bool SelectDirector(const char *director, DirectorResource **ret_dir, Con
goto try_again;
}
delete UA_sock;
LockRes();
LockRes(my_config);
for (i = 0; i < item; i++) {
director_resource =
(DirectorResource *)my_config->GetNextRes(R_DIRECTOR, (CommonResourceHeader *)director_resource);
}
UnlockRes();
UnlockRes(my_config);
}

/*
* Look for a console linked to this director
*/
LockRes();
LockRes(my_config);
for (i = 0; i < numcon; i++) {
console_resource =
(ConsoleResource *)my_config->GetNextRes(R_CONSOLE, (CommonResourceHeader *)console_resource);
Expand Down Expand Up @@ -977,7 +977,7 @@ static bool SelectDirector(const char *director, DirectorResource **ret_dir, Con
if (!console_resource) {
console_resource = (ConsoleResource *)my_config->GetNextRes(R_CONSOLE, (CommonResourceHeader *)NULL);
}
UnlockRes();
UnlockRes(my_config);

*ret_dir = director_resource;
*ret_cons = console_resource;
Expand Down Expand Up @@ -1173,9 +1173,9 @@ int main(int argc, char *argv[])
if (!no_conio) { ConInit(stdin); }

if (list_directors) {
LockRes();
LockRes(my_config);
foreach_res(director_resource, R_DIRECTOR) { senditf("%s\n", director_resource->name()); }
UnlockRes();
UnlockRes(my_config);
}

if (test_config) {
Expand Down Expand Up @@ -1296,7 +1296,7 @@ static int CheckResources()
bool OK = true;
DirectorResource *director;

LockRes();
LockRes(my_config);

numdir = 0;
foreach_res(director, R_DIRECTOR) { numdir++; }
Expand All @@ -1312,7 +1312,7 @@ static int CheckResources()

me = (ConsoleResource *)my_config->GetNextRes(R_CONSOLE, NULL);

UnlockRes();
UnlockRes(my_config);

return OK;
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/dird/dbcheck.cc
Expand Up @@ -1238,7 +1238,7 @@ int main (int argc, char *argv[])
}
my_config = InitDirConfig(configfile, M_ERROR_TERM);
my_config->ParseConfig();
LockRes();
LockRes(my_config);
foreach_res(catalog, R_CATALOG) {
if (catalogname && bstrcmp(catalog->hdr.name, catalogname)) {
++found;
Expand All @@ -1248,7 +1248,7 @@ int main (int argc, char *argv[])
break;
}
}
UnlockRes();
UnlockRes(my_config);
if (!found) {
if (catalogname) {
Pmsg2(0, _("Error can not find the Catalog name[%s] in the given config file [%s]\n"), catalogname, configfile);
Expand All @@ -1257,9 +1257,9 @@ int main (int argc, char *argv[])
}
exit(1);
} else {
LockRes();
LockRes(my_config);
me = (DirectorResource *)my_config->GetNextRes(R_DIRECTOR, NULL);
UnlockRes();
UnlockRes(my_config);
if (!me) {
Pmsg0(0, _("Error no Director resource defined.\n"));
exit(1);
Expand Down
12 changes: 6 additions & 6 deletions core/src/dird/dird.cc
Expand Up @@ -130,7 +130,7 @@ static void ReloadJobEndCb(JobControlRecord *jcr, void *ctx)
resource_table_reference *table;

LockJobs();
LockRes();
LockRes(my_config);

foreach_alist_index(i, table, reload_table) {
if (table == (resource_table_reference *)ctx) {
Expand All @@ -147,7 +147,7 @@ static void ReloadJobEndCb(JobControlRecord *jcr, void *ctx)
}
}

UnlockRes();
UnlockRes(my_config);
UnlockJobs();
}

Expand Down Expand Up @@ -585,7 +585,7 @@ bool DoReloadConfig()
StopStatisticsThread();

LockJobs();
LockRes();
LockRes(my_config);

DbSqlPoolFlush();

Expand Down Expand Up @@ -653,7 +653,7 @@ bool DoReloadConfig()
}

bail_out:
UnlockRes();
UnlockRes(my_config);
UnlockJobs();
is_reloading = false;
return reloaded;
Expand Down Expand Up @@ -689,7 +689,7 @@ static bool CheckResources()
bool need_tls;
const std::string &configfile = my_config->get_base_config_path();

LockRes();
LockRes(my_config);

job = (JobResource *)my_config->GetNextRes(R_JOB, NULL);
me = (DirectorResource *)my_config->GetNextRes(R_DIRECTOR, NULL);
Expand Down Expand Up @@ -952,7 +952,7 @@ static bool CheckResources()
}

bail_out:
UnlockRes();
UnlockRes(my_config);
return OK;
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/dird/expand.cc
Expand Up @@ -230,7 +230,7 @@ static var_rc_t lookup_counter_var(var_t *ctx,
PmMemcpy(buf, var_ptr, var_len);
(buf.c_str())[var_len] = 0;

LockRes();
LockRes(my_config);
for (counter = NULL; (counter = (CounterResource *)my_config->GetNextRes(R_COUNTER, (CommonResourceHeader *)counter)); ) {
if (bstrcmp(counter->name(), buf.c_str())) {
Dmsg2(100, "Counter=%s val=%d\n", buf.c_str(), counter->CurrentValue);
Expand Down Expand Up @@ -279,7 +279,7 @@ static var_rc_t lookup_counter_var(var_t *ctx,
break;
}
}
UnlockRes();
UnlockRes(my_config);

return status;
}
Expand Down Expand Up @@ -437,14 +437,14 @@ static var_rc_t operate_var(var_t *var,
(buf.c_str())[val_len] = 0;
Dmsg1(100, "Val=%s\n", buf.c_str());

LockRes();
LockRes(my_config);
for (counter = NULL; (counter = (CounterResource *)my_config->GetNextRes(R_COUNTER, (CommonResourceHeader *)counter)); ) {
if (bstrcmp(counter->name(), buf.c_str())) {
Dmsg2(100, "counter=%s val=%s\n", counter->name(), buf.c_str());
break;
}
}
UnlockRes();
UnlockRes(my_config);
return status;
}
*out_size = 0;
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/msgchan.cc
Expand Up @@ -537,15 +537,15 @@ extern "C" void *device_thread(void *arg)
Dmsg0(900, "Failed connecting to SD.\n");
continue;
}
LockRes();
LockRes(this);
foreach_res(dev, R_DEVICE) {
if (!UpdateDeviceRes(jcr, dev)) {
Dmsg1(900, "Error updating device=%s\n", dev->name());
} else {
Dmsg1(900, "Updated Device=%s\n", dev->name());
}
}
UnlockRes();
UnlockRes(this);
jcr->store_bsock->close();
delete jcr->store_bsock;
jcr->store_bsock = NULL;
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/scheduler.cc
Expand Up @@ -371,7 +371,7 @@ static void find_runs()
/*
* Loop through all jobs
*/
LockRes();
LockRes(my_config);
foreach_res(job, R_JOB) {
sched = job->schedule;
if (sched == NULL ||
Expand Down Expand Up @@ -446,7 +446,7 @@ static void find_runs()
}
}
}
UnlockRes();
UnlockRes(my_config);
Dmsg0(debuglevel, "Leave find_runs()\n");
}

Expand Down
12 changes: 6 additions & 6 deletions core/src/dird/stats.cc
Expand Up @@ -166,7 +166,7 @@ void *statistics_thread(void *arg)
StorageResource *store;
int64_t StorageId;

LockRes();
LockRes(my_config);
if ((current_store.c_str())[0]) {
store = (StorageResource *)my_config->GetResWithName(R_STORAGE, current_store.c_str());
} else {
Expand All @@ -176,34 +176,34 @@ void *statistics_thread(void *arg)
store = (StorageResource *)my_config->GetNextRes(R_STORAGE, (CommonResourceHeader *)store);
if (!store) {
PmStrcpy(current_store, "");
UnlockRes();
UnlockRes(my_config);
break;
}

PmStrcpy(current_store, store->name());
if (!store->collectstats) {
UnlockRes();
UnlockRes(my_config);
continue;
}

switch (store->Protocol) {
case APT_NATIVE:
break;
default:
UnlockRes();
UnlockRes(my_config);
continue;
}

jcr->res.rstore = store;
if (!ConnectToStorageDaemon(jcr, 2, 1, false)) {
UnlockRes();
UnlockRes(my_config);
continue;
}

StorageId = store->StorageId;
sd = jcr->store_bsock;

UnlockRes();
UnlockRes(my_config);

/*
* Do our work retrieving the statistics from the remote SD.
Expand Down
8 changes: 4 additions & 4 deletions core/src/dird/ua_cmds.cc
Expand Up @@ -1227,7 +1227,7 @@ static void do_all_setdebug(UaContext *ua, int level, int trace_flag,
/*
* Count Storage items
*/
LockRes();
LockRes(my_config);
store = NULL;
i = 0;
foreach_res(store, R_STORAGE) {
Expand Down Expand Up @@ -1255,7 +1255,7 @@ static void do_all_setdebug(UaContext *ua, int level, int trace_flag,
Dmsg2(140, "Stuffing: %s:%d\n", store->address, store->SDport);
}
}
UnlockRes();
UnlockRes(my_config);

/*
* Call each unique Storage daemon
Expand All @@ -1268,7 +1268,7 @@ static void do_all_setdebug(UaContext *ua, int level, int trace_flag,
/*
* Count Client items
*/
LockRes();
LockRes(my_config);
client = NULL;
i = 0;
foreach_res(client, R_CLIENT) {
Expand Down Expand Up @@ -1296,7 +1296,7 @@ static void do_all_setdebug(UaContext *ua, int level, int trace_flag,
Dmsg2(140, "Stuffing: %s:%d\n", client->address, client->FDport);
}
}
UnlockRes();
UnlockRes(my_config);

/*
* Call each unique File daemon
Expand Down

0 comments on commit 4a3e09a

Please sign in to comment.