degesch: only apply relevant attributes on change

This commit is contained in:
Přemysl Eric Janouch 2015-07-05 16:15:30 +02:00
parent 3a922c3c1a
commit 6de7ae9583
1 changed files with 17 additions and 8 deletions

View File

@ -1868,23 +1868,32 @@ log_message_attributed (void *user_data, const char *quote, const char *fmt,
input_show (&ctx->input); input_show (&ctx->input);
} }
static void
apply_attribute_change (struct config_item_ *item, int id)
{
struct app_context *ctx = item->user_data;
free (ctx->attrs[id]);
ctx->attrs[id] = xstrdup (item->type == CONFIG_ITEM_NULL
? ctx->attrs_defaults[id]
: item->value.string.str);
}
static void static void
on_config_attribute_change (struct config_item_ *item) on_config_attribute_change (struct config_item_ *item)
{ {
static const char *table[ATTR_COUNT] = static const char *table[ATTR_COUNT] =
{ {
#define XX(x, y, z) [ATTR_ ## x] = "attributes." y, #define XX(x, y, z) [ATTR_ ## x] = y,
ATTR_TABLE (XX) ATTR_TABLE (XX)
#undef XX #undef XX
}; };
struct app_context *ctx = item->user_data; for (size_t i = 0; i < N_ELEMENTS (table); i++)
for (int id = 0; id < ATTR_COUNT; id++) if (!strcmp (item->schema->name, table[i]))
{ {
const char *user = get_config_string (ctx->config.root, table[id]); apply_attribute_change (item, i);
free (ctx->attrs[id]); return;
ctx->attrs[id] = xstrdup (user ? user : ctx->attrs_defaults[id]); }
}
} }
static void static void