Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bareos/bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rogge <andreas.rogge@bareos.com>2022-10-14 17:20:00 +0300
committerPhilipp Storz <philipp.storz@bareos.com>2022-11-03 19:26:50 +0300
commitd61468a333041d72ce086ff18d2791966b2186f2 (patch)
treeb50303520221854d33ef64276fef516b853f63d7
parentcf2d6b1ac3cf0e2185aa7a14ac3769f81c36009a (diff)
lib: improve foreach_res()
This patch extends the foreach_res() macro so that the loop will survive a configuration reload.
-rw-r--r--core/src/lib/parse_conf.h24
1 files changed, 15 insertions, 9 deletions
diff --git a/core/src/lib/parse_conf.h b/core/src/lib/parse_conf.h
index 317098f52..288083837 100644
--- a/core/src/lib/parse_conf.h
+++ b/core/src/lib/parse_conf.h
@@ -475,16 +475,22 @@ void IndentConfigItem(PoolMem& cfg_str,
const char* config_item,
bool inherited = false);
+/* this function is used as an initializer in foreach_res, so we can null
+ * the pointer passed into and also get a reference to the configuration that
+ * we then keep for the lifetime of the loop.
+ */
+inline std::shared_ptr<ConfigResourcesContainer> _init_foreach_res_(
+ ConfigurationParser* my_config,
+ void* var)
+{
+ memset(var, 0, sizeof(void*));
+ return my_config->GetResourcesContainer();
+}
// Loop through each resource of type, returning in var
-#ifdef HAVE_TYPEOF
-# define foreach_res(var, type) \
- for ((var) = NULL; ((var) = (typeof(var))my_config->GetNextRes( \
- (type), (BareosResource*)var));)
-#else
-# define foreach_res(var, type) \
- for (var = NULL; (*((void**)&(var)) = (void*)my_config->GetNextRes( \
- (type), (BareosResource*)var));)
-#endif
+#define foreach_res(var, type) \
+ for (auto _config_table_ = _init_foreach_res_(my_config, &var); \
+ ((var) \
+ = static_cast<decltype(var)>(my_config->GetNextRes((type), var)));)
#define LockRes(x) (x)->b_LockRes(__FILE__, __LINE__)
#define UnlockRes(x) (x)->b_UnlockRes(__FILE__, __LINE__)