gchar * cfg_args_format_varargs(CfgArgs *self, CfgArgs *defaults) { GString *varargs = g_string_new(""); gpointer user_data[] = { defaults, varargs }; cfg_args_foreach(self, _resolve_unknown_blockargs_as_varargs, user_data); return g_string_free(varargs, FALSE); }
gboolean confgen_exec_generate(CfgBlockGenerator *s, GlobalConfig *cfg, CfgArgs *args, GString *result, const gchar *reference) { ConfgenExec *self = (ConfgenExec *) s; FILE *out; gchar buf[256]; gint res; g_snprintf(buf, sizeof(buf), "%s confgen %s", cfg_lexer_lookup_context_name_by_type(self->super.context), self->super.name); cfg_args_foreach(args, confgen_set_args_as_env, NULL); out = popen(self->exec, "r"); cfg_args_foreach(args, confgen_unset_args_from_env, NULL); if (!out) { msg_error("confgen: Error executing generator program", evt_tag_str("reference", reference), evt_tag_str("context", cfg_lexer_lookup_context_name_by_type(self->super.context)), evt_tag_str("block", self->super.name), evt_tag_str("exec", self->exec), evt_tag_error("error")); return FALSE; } _read_program_output(out, result); res = pclose(out); if (res != 0) { msg_error("confgen: Generator program returned with non-zero exit code", evt_tag_str("reference", reference), evt_tag_str("context", cfg_lexer_lookup_context_name_by_type(self->super.context)), evt_tag_str("block", self->super.name), evt_tag_str("exec", self->exec), evt_tag_int("rc", res)); return FALSE; } msg_debug("confgen: output from the executed program to be included is", evt_tag_printf("block", "%.*s", (gint) result->len, result->str)); return TRUE; }
gboolean cfg_args_validate(CfgArgs *self, CfgArgs *defs, const gchar *context) { gpointer validate_params[] = { defs, NULL, NULL }; cfg_args_foreach(self, cfg_args_validate_callback, validate_params); if (validate_params[1]) { msg_error("Unknown argument", evt_tag_str("context", context), evt_tag_str("arg", validate_params[1]), evt_tag_str("value", validate_params[2])); return FALSE; } return TRUE; }