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; }
/* * NOTE: _init needs to be idempotent when called multiple times w/o invoking _destroy * * Rationale: * - 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 at deinit time, but * have to recover it when the old configuration is initialized. * * 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 * * Also important to note is that when init is called multiple times, the * GlobalConfig reference is the same, this means that it is enough to * remember whether init was called already and return w/o doing anything in * that case, which is actually how idempotency is implemented here. */ void log_reader_options_init(LogReaderOptions *options, GlobalConfig *cfg, const gchar *group_name) { if (options->initialized) return; log_source_options_init(&options->super, cfg, group_name); log_proto_server_options_init(&options->proto_options.super, cfg); msg_format_options_init(&options->parse_options, cfg); if (options->check_hostname == -1) options->check_hostname = cfg->check_hostname; if (options->check_hostname) { options->parse_options.flags |= LP_CHECK_HOSTNAME; } if (!options->super.keep_timestamp) { options->parse_options.flags |= LP_NO_PARSE_DATE; } if (options->parse_options.default_pri == 0xFFFF) { if (options->flags & LR_KERNEL) options->parse_options.default_pri = LOG_KERN | LOG_NOTICE; else options->parse_options.default_pri = LOG_USER | LOG_NOTICE; } if (options->proto_options.super.encoding) options->parse_options.flags |= LP_ASSUME_UTF8; if (cfg->threaded) options->flags |= LR_THREADED; options->initialized = TRUE; }
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; }
static gboolean afinter_sd_init(LogPipe *s) { AFInterSourceDriver *self = (AFInterSourceDriver *) s; GlobalConfig *cfg = log_pipe_get_config(s); if (!log_src_driver_init_method(s)) return FALSE; if (current_internal_source != NULL) { msg_error("Multiple internal() sources were detected, this is not possible", NULL); return FALSE; } log_source_options_init(&self->source_options, cfg, self->super.group); self->source = afinter_source_new(self, &self->source_options); log_pipe_append(&self->source->super, s); log_pipe_init(&self->source->super, cfg); return TRUE; }
static gboolean trigger_sd_init (LogPipe *s) { TriggerSourceDriver *self = (TriggerSourceDriver *)s; GlobalConfig *cfg = log_pipe_get_config (s); if (!log_src_driver_init_method (s)) return FALSE; if (self->options.trigger_freq <= 0) self->options.trigger_freq = 10; if (!self->options.message) self->options.message = g_strdup ("Trigger source is trigger happy."); log_source_options_init (&self->source_options, cfg, self->super.super.group); self->source = trigger_source_new (self, &self->source_options, cfg); log_pipe_append (&self->source->super, s); log_pipe_init (&self->source->super); return 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 log_reader_options_init(LogReaderOptions *options, GlobalConfig *cfg, const gchar *group_name) { gchar *recv_time_zone; TimeZoneInfo *recv_time_zone_info; gchar *host_override, *program_override, *text_encoding, *format; MsgFormatHandler *format_handler; GArray *tags; recv_time_zone = options->parse_options.recv_time_zone; options->parse_options.recv_time_zone = NULL; recv_time_zone_info = options->parse_options.recv_time_zone_info; options->parse_options.recv_time_zone_info = NULL; text_encoding = options->text_encoding; options->text_encoding = NULL; /* NOTE: having to save super's variables is a crude hack, but I know of * no other way to do it in the scheme described above. Be sure that you * know what you are doing when you modify this code. */ tags = options->super.tags; options->super.tags = NULL; host_override = options->super.host_override; options->super.host_override = NULL; program_override = options->super.program_override; options->super.program_override = NULL; format = options->parse_options.format; options->parse_options.format = NULL; format_handler = options->parse_options.format_handler; options->parse_options.format_handler = NULL; /*********************************************************************** * PLEASE NOTE THIS. please read the comment at the top of the function ***********************************************************************/ log_reader_options_destroy(options); options->parse_options.format = format; options->parse_options.format_handler = format_handler; options->super.host_override = host_override; options->super.program_override = program_override; options->super.tags = tags; options->parse_options.recv_time_zone = recv_time_zone; options->parse_options.recv_time_zone_info = recv_time_zone_info; options->text_encoding = text_encoding; options->parse_options.format = format; log_source_options_init(&options->super, cfg, group_name); msg_format_options_init(&options->parse_options, cfg); if (options->msg_size == -1) options->msg_size = cfg->log_msg_size; if (options->follow_freq == -1) options->follow_freq = cfg->follow_freq; if (options->check_hostname == -1) options->check_hostname = cfg->check_hostname; if (options->check_hostname) { options->parse_options.flags |= LP_CHECK_HOSTNAME; } if (options->parse_options.default_pri == 0xFFFF) { if (options->flags & LR_KERNEL) options->parse_options.default_pri = LOG_KERN | LOG_NOTICE; else options->parse_options.default_pri = LOG_USER | LOG_NOTICE; } if (options->text_encoding) options->parse_options.flags |= LP_ASSUME_UTF8; if (cfg->threaded) options->flags |= LR_THREADED; }