void journal_reader_options_init(JournalReaderOptions *options, GlobalConfig *cfg, const gchar *group_name) { if (options->initialized) return; log_source_options_init(&options->super, cfg, group_name); if (cfg->threaded) options->flags |= JR_THREADED; if (options->recv_time_zone == NULL) options->recv_time_zone = g_strdup(cfg->recv_time_zone); if (options->recv_time_zone_info == NULL) options->recv_time_zone_info = time_zone_info_new(options->recv_time_zone); gchar *value = ".journald."; if (options->prefix == NULL && cfg_is_config_version_older(cfg, VERSION_VALUE_3_8)) { msg_warning("WARNING: Default value changed for the prefix() option of systemd-journal source in " VERSION_3_8, evt_tag_str("old_value", ""), evt_tag_str("new_value", value)); } else if (!cfg_is_config_version_older(cfg, VERSION_VALUE_3_8)) { options->prefix = g_strdup(value); } options->initialized = TRUE; }
static gboolean date_parser_init(LogPipe *s) { DateParser *self = (DateParser *) s; if (self->date_tz_info) time_zone_info_free(self->date_tz_info); self->date_tz_info = self->date_tz ? time_zone_info_new(self->date_tz) : NULL; return log_parser_init_method(s); }
void test_pattern(const gchar *pattern, const gchar *rule, gboolean match) { gboolean result; LogMessage *msg = log_msg_new_empty(); static LogTemplate *templ; GString *res = g_string_sized_new(128); static TimeZoneInfo *tzinfo = NULL; PDBInput input; if (!tzinfo) tzinfo = time_zone_info_new(NULL); if (!templ) { templ = log_template_new(configuration, "dummy"); log_template_compile(templ, "$TEST", NULL); } log_msg_set_value(msg, LM_V_HOST, MYHOST, strlen(MYHOST)); log_msg_set_value(msg, LM_V_PROGRAM, "test", strlen(MYHOST)); log_msg_set_value(msg, LM_V_MESSAGE, pattern, strlen(pattern)); result = pattern_db_process(patterndb, PDB_INPUT_WRAP_MESSAGE(&input, msg)); log_template_format(templ, msg, NULL, LTZ_LOCAL, 0, NULL, res); if (strcmp(res->str, pattern) == 0) { test_msg("Rule: '%s' Value '%s' is inserted into $TEST res:(%s)\n", rule, pattern, res->str); } if ((match && !result) || (!match && result)) { test_fail("FAIL: Value '%s' is %smatching for pattern '%s' \n", rule, !!result ? "" : "not ", pattern); } else { test_msg("Value '%s' is %smatching for pattern '%s' \n", rule, !!result ? "" : "not ", pattern); } g_string_free(res, TRUE); log_msg_unref(msg); }
void journal_reader_options_init(JournalReaderOptions *options, GlobalConfig *cfg, const gchar *group_name) { if (options->initialized) return; log_source_options_init(&options->super, cfg, group_name); if (cfg->threaded) options->flags |= JR_THREADED; if (options->recv_time_zone == NULL) options->recv_time_zone = g_strdup(cfg->recv_time_zone); if (options->recv_time_zone_info == NULL) options->recv_time_zone_info = time_zone_info_new(options->recv_time_zone); options->initialized = TRUE; }
/* * NOTE: options_init and options_destroy are a bit weird, because their * invocation is not completely symmetric: * * - init is called from driver init (e.g. affile_sd_init), * - destroy is called from driver free method (e.g. affile_sd_free, NOT affile_sd_deinit) * * The reason: * - when initializing the reloaded configuration fails for some reason, * we have to fall back to the old configuration, thus we cannot dump * the information stored in the Options structure. * * For the reasons above, init and destroy behave the following way: * * - init is idempotent, it can be called multiple times without leaking * memory, and without loss of information * - destroy is only called once, when the options are indeed to be destroyed * * As init allocates memory, it has to take care about freeing memory * allocated by the previous init call (or it has to reuse those). * */ void msg_format_options_init(MsgFormatOptions *options, GlobalConfig *cfg) { gchar *recv_time_zone, *format; TimeZoneInfo *recv_time_zone_info; MsgFormatHandler *format_handler; Plugin *p; recv_time_zone = options->recv_time_zone; options->recv_time_zone = NULL; recv_time_zone_info = options->recv_time_zone_info; options->recv_time_zone_info = NULL; format = options->format; options->format = NULL; format_handler = options->format_handler; options->format_handler = NULL; msg_format_options_destroy(options); options->format = format; options->format_handler = format_handler; options->recv_time_zone = recv_time_zone; options->recv_time_zone_info = recv_time_zone_info; if (cfg->bad_hostname_compiled) options->bad_hostname = &cfg->bad_hostname; if (options->recv_time_zone == NULL) options->recv_time_zone = g_strdup(cfg->recv_time_zone); if (options->recv_time_zone_info == NULL) options->recv_time_zone_info = time_zone_info_new(options->recv_time_zone); if (!options->format) options->format = g_strdup("syslog"); p = plugin_find(cfg, LL_CONTEXT_FORMAT, options->format); if (p) options->format_handler = plugin_construct(p, cfg, LL_CONTEXT_FORMAT, options->format); }
/* NOTE: _init needs to be idempotent when called multiple times w/o invoking _destroy */ void msg_format_options_init(MsgFormatOptions *options, GlobalConfig *cfg) { Plugin *p; if (options->initialized) return; if (cfg->bad_hostname_compiled) options->bad_hostname = &cfg->bad_hostname; if (options->recv_time_zone == NULL) options->recv_time_zone = g_strdup(cfg->recv_time_zone); if (options->recv_time_zone_info == NULL) options->recv_time_zone_info = time_zone_info_new(options->recv_time_zone); if (!options->format) options->format = g_strdup("syslog"); p = plugin_find(cfg, LL_CONTEXT_FORMAT, options->format); if (p) options->format_handler = plugin_construct(p, cfg, LL_CONTEXT_FORMAT, options->format); options->initialized = TRUE; }