/** * @param #tags is a comma separated string of words. * Both "" or NULL are equivalent. */ static void ClassInit(Class *cls, const char *ns, const char *name, bool is_soft, ContextScope scope, const char *tags) { if (ns == NULL || strcmp(ns, "default") == 0) { cls->ns = NULL; } else { cls->ns = xstrdup(ns); } cls->name = xstrdup(name); CanonifyNameInPlace(cls->name); cls->is_soft = is_soft; cls->scope = scope; cls->tags = StringSetFromString(tags, ','); if (!is_soft && !StringSetContains(cls->tags, "hardclass")) { StringSetAdd(cls->tags, xstrdup("hardclass")); } }
bool GenericAgentConfigParseWarningOptions(GenericAgentConfig *config, const char *warning_options) { if (strlen(warning_options) == 0) { return false; } if (strcmp("error", warning_options) == 0) { config->agent_specific.common.parser_warnings_error |= PARSER_WARNING_ALL; return true; } const char *options_start = warning_options; bool warnings_as_errors = false; if (StringStartsWith(warning_options, "error=")) { options_start = warning_options + strlen("error="); warnings_as_errors = true; } StringSet *warnings_set = StringSetFromString(options_start, ','); StringSetIterator it = StringSetIteratorInit(warnings_set); const char *warning_str = NULL; while ((warning_str = StringSetIteratorNext(&it))) { int warning = ParserWarningFromString(warning_str); if (warning == -1) { Log(LOG_LEVEL_ERR, "Unrecognized warning '%s'", warning_str); StringSetDestroy(warnings_set); return false; } if (warnings_as_errors) { config->agent_specific.common.parser_warnings_error |= warning; } else { config->agent_specific.common.parser_warnings |= warning; } } StringSetDestroy(warnings_set); return true; }
static GenericAgentConfig *CheckOpts(EvalContext *ctx, int argc, char **argv) { extern char *optarg; int optindex = 0; int c; char ld_library_path[CF_BUFSIZE]; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_EXECUTOR); while ((c = getopt_long(argc, argv, "dvnKIf:D:N:VxL:hFOV1gMW", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': if (optarg && strlen(optarg) < 5) { CfOut(OUTPUT_LEVEL_ERROR, "", " -f used but argument \"%s\" incorrect", optarg); exit(EXIT_FAILURE); } GenericAgentConfigSetInputFile(config, optarg); MINUSF = true; break; case 'd': config->debug_mode = true; break; case 'K': IGNORELOCK = true; break; case 'D': config->heap_soft = StringSetFromString(optarg, ','); break; case 'N': config->heap_negated = StringSetFromString(optarg, ','); break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; NO_FORK = true; break; case 'n': DONTDO = true; IGNORELOCK = true; EvalContextHeapAddHard(ctx, "opt_dry_run"); break; case 'L': snprintf(ld_library_path, CF_BUFSIZE - 1, "LD_LIBRARY_PATH=%s", optarg); if (putenv(xstrdup(ld_library_path)) != 0) { } break; case 'W': WINSERVICE = false; break; case 'F': NO_FORK = true; break; case 'O': ONCE = true; NO_FORK = true; break; case 'V': PrintVersion(); exit(0); case 'h': Syntax("cf-execd - cfengine's execution agent", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-execd - cfengine's execution agent", OPTIONS, HINTS, ID); exit(0); case 'x': CfOut(OUTPUT_LEVEL_ERROR, "", "Self-diagnostic functionality is retired."); exit(0); default: Syntax("cf-execd - cfengine's execution agent", OPTIONS, HINTS, ID); exit(1); } } if (argv[optind] != NULL) { CfOut(OUTPUT_LEVEL_ERROR, "", "Unexpected argument: %s\n", argv[optind]); } return config; }
GenericAgentConfig *CheckOpts(int argc, char **argv) { extern char *optarg; int c; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_SERVER, GetTTYInteractive()); while ((c = getopt_long(argc, argv, "dvIKf:D:N:VSxLFMhAC::l", OPTIONS, NULL)) != -1) { switch (c) { case 'f': GenericAgentConfigSetInputFile(config, GetInputDir(), optarg); MINUSF = true; break; case 'd': LogSetGlobalLevel(LOG_LEVEL_DEBUG); NO_FORK = true; break; case 'K': config->ignore_locks = true; break; case 'D': { StringSet *defined_classes = StringSetFromString(optarg, ','); if (! config->heap_soft) { config->heap_soft = defined_classes; } else { StringSetJoin(config->heap_soft, defined_classes); free(defined_classes); } } break; case 'N': { StringSet *negated_classes = StringSetFromString(optarg, ','); if (! config->heap_negated) { config->heap_negated = negated_classes; } else { StringSetJoin(config->heap_negated, negated_classes); free(negated_classes); } } break; case 'I': LogSetGlobalLevel(LOG_LEVEL_INFO); break; case 'v': LogSetGlobalLevel(LOG_LEVEL_VERBOSE); NO_FORK = true; break; case 'F': NO_FORK = true; break; case 'L': { static char ld_library_path[CF_BUFSIZE]; /* GLOBAL_A */ Log(LOG_LEVEL_VERBOSE, "Setting LD_LIBRARY_PATH to '%s'", optarg); snprintf(ld_library_path, CF_BUFSIZE - 1, "LD_LIBRARY_PATH=%s", optarg); putenv(ld_library_path); break; } case 'V': { Writer *w = FileWriter(stdout); GenericAgentWriteVersion(w); FileWriterDetach(w); } exit(EXIT_SUCCESS); case 'h': { Writer *w = FileWriter(stdout); WriterWriteHelp(w, "cf-serverd", OPTIONS, HINTS, true, NULL); FileWriterDetach(w); } exit(EXIT_SUCCESS); case 'M': { Writer *out = FileWriter(stdout); ManPageWrite(out, "cf-serverd", time(NULL), CF_SERVERD_SHORT_DESCRIPTION, CF_SERVERD_MANPAGE_LONG_DESCRIPTION, OPTIONS, HINTS, true); FileWriterDetach(out); exit(EXIT_SUCCESS); } case 'x': Log(LOG_LEVEL_ERR, "Self-diagnostic functionality is retired."); exit(EXIT_SUCCESS); case 'A': #ifdef SUPPORT_AVAHI_CONFIG Log(LOG_LEVEL_NOTICE, "Generating Avahi configuration file."); if (GenerateAvahiConfig("/etc/avahi/services/cfengine-hub.service") != 0) { exit(EXIT_FAILURE); } cf_popen("/etc/init.d/avahi-daemon restart", "r", true); Log(LOG_LEVEL_NOTICE, "Avahi configuration file generated successfully."); #else Log(LOG_LEVEL_ERR, "Generating avahi configuration can only be done when avahi-daemon and libavahi are installed on the machine."); #endif exit(EXIT_SUCCESS); case 'C': if (!GenericAgentConfigParseColor(config, optarg)) { exit(EXIT_FAILURE); } break; case 'l': LoggingEnableTimestamps(true); break; default: { Writer *w = FileWriter(stdout); WriterWriteHelp(w, "cf-serverd", OPTIONS, HINTS, true, NULL); FileWriterDetach(w); } exit(EXIT_FAILURE); } } if (!GenericAgentConfigParseArguments(config, argc - optind, argv + optind)) { Log(LOG_LEVEL_ERR, "Too many arguments"); exit(EXIT_FAILURE); } return config; }
GenericAgentConfig *CheckOpts(int argc, char **argv) { extern char *optarg; int optindex = 0; int c; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_COMMON); while ((c = getopt_long(argc, argv, "dvnIf:D:N:VSrxMb:i:p:s:cg:hW:lC::", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 0: switch (optindex) { case PROMISES_OPTION_EVAL_FUNCTIONS: if (!optarg) { optarg = "yes"; } config->agent_specific.common.eval_functions = strcmp("yes", optarg) == 0; break; case PROMISES_OPTION_SHOW_CLASSES: if (!optarg) { optarg = "yes"; } config->agent_specific.common.show_classes = strcmp("yes", optarg) == 0; break; case PROMISES_OPTION_SHOW_VARIABLES: if (!optarg) { optarg = "yes"; } config->agent_specific.common.show_variables = strcmp("yes", optarg) == 0; break; default: break; } case 'l': LEGACY_OUTPUT = true; break; case 'c': config->check_runnable = true; break; case 'f': if (optarg && (strlen(optarg) < 5)) { Log(LOG_LEVEL_ERR, " -f used but argument '%s' incorrect", optarg); exit(EXIT_FAILURE); } GenericAgentConfigSetInputFile(config, GetInputDir(), optarg); MINUSF = true; break; case 'd': LogSetGlobalLevel(LOG_LEVEL_DEBUG); break; case 'b': if (optarg) { Rlist *bundlesequence = RlistFromSplitString(optarg, ','); GenericAgentConfigSetBundleSequence(config, bundlesequence); RlistDestroy(bundlesequence); } break; case 'p': if (strcmp("none", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_NONE; } else if (strcmp("cf", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_CF; } else if (strcmp("json", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_JSON; } else { Log(LOG_LEVEL_ERR, "Invalid policy output format: '%s'. Possible values are 'none', 'cf', 'json'", optarg); exit(EXIT_FAILURE); } break; case 's': if (strcmp("none", optarg) == 0) { break; } else if (strcmp("json", optarg) == 0) { JsonElement *json_syntax = SyntaxToJson(); Writer *out = FileWriter(stdout); JsonWrite(out, json_syntax, 0); FileWriterDetach(out); JsonDestroy(json_syntax); exit(EXIT_SUCCESS); } else { Log(LOG_LEVEL_ERR, "Invalid syntax description output format: '%s'. Possible values are 'none', 'json'", optarg); exit(EXIT_FAILURE); } break; case 'K': config->ignore_locks = true; break; case 'D': config->heap_soft = StringSetFromString(optarg, ','); break; case 'N': config->heap_negated = StringSetFromString(optarg, ','); break; case 'I': LogSetGlobalLevel(LOG_LEVEL_INFO); break; case 'v': LogSetGlobalLevel(LOG_LEVEL_VERBOSE); break; case 'n': DONTDO = true; config->ignore_locks = true; break; case 'V': { Writer *w = FileWriter(stdout); GenericAgentWriteVersion(w); FileWriterDetach(w); } exit(EXIT_SUCCESS); case 'h': { Writer *w = FileWriter(stdout); GenericAgentWriteHelp(w, "cf-promises", OPTIONS, HINTS, true); FileWriterDetach(w); } exit(EXIT_SUCCESS); case 'M': { Writer *out = FileWriter(stdout); ManPageWrite(out, "cf-promises", time(NULL), CF_PROMISES_SHORT_DESCRIPTION, CF_PROMISES_MANPAGE_LONG_DESCRIPTION, OPTIONS, HINTS, true); FileWriterDetach(out); exit(EXIT_SUCCESS); } case 'r': SHOWREPORTS = true; break; case 'W': if (!GenericAgentConfigParseWarningOptions(config, optarg)) { Log(LOG_LEVEL_ERR, "Error parsing warning option"); exit(EXIT_FAILURE); } break; case 'x': Log(LOG_LEVEL_ERR, "Self-diagnostic functionality is retired."); exit(EXIT_SUCCESS); case 'C': if (!GenericAgentConfigParseColor(config, optarg)) { exit(EXIT_FAILURE); } break; default: { Writer *w = FileWriter(stdout); GenericAgentWriteHelp(w, "cf-promises", OPTIONS, HINTS, true); FileWriterDetach(w); } exit(EXIT_FAILURE); } } if (!GenericAgentConfigParseArguments(config, argc - optind, argv + optind)) { Log(LOG_LEVEL_ERR, "Too many arguments"); exit(EXIT_FAILURE); } return config; }
static GenericAgentConfig *CheckOpts(int argc, char **argv) { extern char *optarg; int optindex = 0; int c; char ld_library_path[CF_BUFSIZE]; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_EXECUTOR); while ((c = getopt_long(argc, argv, "dvnKIf:D:N:VxL:hFOV1gMWlC::", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'l': LEGACY_OUTPUT = true; break; case 'f': GenericAgentConfigSetInputFile(config, GetInputDir(), optarg); MINUSF = true; break; case 'd': LogSetGlobalLevel(LOG_LEVEL_DEBUG); break; case 'K': config->ignore_locks = true; break; case 'D': config->heap_soft = StringSetFromString(optarg, ','); break; case 'N': config->heap_negated = StringSetFromString(optarg, ','); break; case 'I': LogSetGlobalLevel(LOG_LEVEL_INFO); break; case 'v': LogSetGlobalLevel(LOG_LEVEL_VERBOSE); NO_FORK = true; // TODO: really? break; case 'n': DONTDO = true; config->ignore_locks = true; break; case 'L': snprintf(ld_library_path, CF_BUFSIZE - 1, "LD_LIBRARY_PATH=%s", optarg); putenv(xstrdup(ld_library_path)); break; case 'W': WINSERVICE = false; break; case 'F': NO_FORK = true; break; case 'O': ONCE = true; NO_FORK = true; break; case 'V': { Writer *w = FileWriter(stdout); GenericAgentWriteVersion(w); FileWriterDetach(w); } exit(EXIT_SUCCESS); case 'h': { Writer *w = FileWriter(stdout); GenericAgentWriteHelp(w, "cf-execd", OPTIONS, HINTS, true); FileWriterDetach(w); } exit(EXIT_SUCCESS); case 'M': { Writer *out = FileWriter(stdout); ManPageWrite(out, "cf-execd", time(NULL), CF_EXECD_SHORT_DESCRIPTION, CF_EXECD_MANPAGE_LONG_DESCRIPTION, OPTIONS, HINTS, true); FileWriterDetach(out); exit(EXIT_SUCCESS); } case 'x': Log(LOG_LEVEL_ERR, "Self-diagnostic functionality is retired."); exit(EXIT_SUCCESS); case 'C': if (!GenericAgentConfigParseColor(config, optarg)) { exit(EXIT_FAILURE); } break; default: { Writer *w = FileWriter(stdout); GenericAgentWriteHelp(w, "cf-execd", OPTIONS, HINTS, true); FileWriterDetach(w); } exit(EXIT_FAILURE); } } if (!GenericAgentConfigParseArguments(config, argc - optind, argv + optind)) { Log(LOG_LEVEL_ERR, "Too many arguments"); exit(EXIT_FAILURE); } return config; }
GenericAgentConfig *CheckOpts(int argc, char **argv) { extern char *optarg; char ld_library_path[CF_BUFSIZE]; int optindex = 0; int c; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_SERVER); while ((c = getopt_long(argc, argv, "dvIKf:D:N:VSxLFMhAlC::", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'l': LEGACY_OUTPUT = true; break; case 'f': if (optarg && (strlen(optarg) < 5)) { Log(LOG_LEVEL_ERR, " -f used but argument '%s' incorrect", optarg); exit(EXIT_FAILURE); } GenericAgentConfigSetInputFile(config, GetInputDir(), optarg); MINUSF = true; break; case 'd': LogSetGlobalLevel(LOG_LEVEL_DEBUG); NO_FORK = true; case 'K': config->ignore_locks = true; break; case 'D': config->heap_soft = StringSetFromString(optarg, ','); break; case 'N': config->heap_negated = StringSetFromString(optarg, ','); break; case 'I': LogSetGlobalLevel(LOG_LEVEL_INFO); break; case 'v': LogSetGlobalLevel(LOG_LEVEL_VERBOSE); NO_FORK = true; break; case 'F': NO_FORK = true; break; case 'L': Log(LOG_LEVEL_VERBOSE, "Setting LD_LIBRARY_PATH to '%s'", optarg); snprintf(ld_library_path, CF_BUFSIZE - 1, "LD_LIBRARY_PATH=%s", optarg); putenv(ld_library_path); break; case 'V': { Writer *w = FileWriter(stdout); GenericAgentWriteVersion(w); FileWriterDetach(w); } exit(EXIT_SUCCESS); case 'h': { Writer *w = FileWriter(stdout); GenericAgentWriteHelp(w, "cf-serverd", OPTIONS, HINTS, true); FileWriterDetach(w); } exit(EXIT_SUCCESS); case 'M': { Writer *out = FileWriter(stdout); ManPageWrite(out, "cf-serverd", time(NULL), CF_SERVERD_SHORT_DESCRIPTION, CF_SERVERD_MANPAGE_LONG_DESCRIPTION, OPTIONS, HINTS, true); FileWriterDetach(out); exit(EXIT_SUCCESS); } case 'x': Log(LOG_LEVEL_ERR, "Self-diagnostic functionality is retired."); exit(EXIT_SUCCESS); case 'A': #ifdef HAVE_AVAHI_CLIENT_CLIENT_H #ifdef HAVE_AVAHI_COMMON_ADDRESS_H Log(LOG_LEVEL_NOTICE, "Generating Avahi configuration file."); if (GenerateAvahiConfig("/etc/avahi/services/cfengine-hub.service") != 0) { exit(EXIT_FAILURE); } cf_popen("/etc/init.d/avahi-daemon restart", "r", true); Log(LOG_LEVEL_NOTICE, "Avahi configuration file generated successfuly."); exit(EXIT_SUCCESS); #endif #endif Log(LOG_LEVEL_ERR, "Generating avahi configuration can only be done when avahi-daemon and libavahi are installed on the machine."); exit(EXIT_SUCCESS); case 'C': if (!GenericAgentConfigParseColor(config, optarg)) { exit(EXIT_FAILURE); } break; default: { Writer *w = FileWriter(stdout); GenericAgentWriteHelp(w, "cf-serverd", OPTIONS, HINTS, true); FileWriterDetach(w); } exit(EXIT_FAILURE); } } if (!GenericAgentConfigParseArguments(config, argc - optind, argv + optind)) { Log(LOG_LEVEL_ERR, "Too many arguments"); exit(EXIT_FAILURE); } return config; }
GenericAgentConfig *CheckOpts(EvalContext *ctx, int argc, char **argv) { extern char *optarg; int optindex = 0; int c; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_COMMON); while ((c = getopt_long(argc, argv, "dvnIf:D:N:VSrxMb:i:p:cg:h", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'c': config->check_runnable = true; break; case 'f': if (optarg && (strlen(optarg) < 5)) { CfOut(OUTPUT_LEVEL_ERROR, "", " -f used but argument \"%s\" incorrect", optarg); exit(EXIT_FAILURE); } GenericAgentConfigSetInputFile(config, optarg); MINUSF = true; break; case 'd': config->debug_mode = true; break; case 'b': if (optarg) { Rlist *bundlesequence = RlistFromSplitString(optarg, ','); GenericAgentConfigSetBundleSequence(config, bundlesequence); RlistDestroy(bundlesequence); CBUNDLESEQUENCE_STR = optarg; // TODO: wtf is this } break; case 'p': if (strcmp("none", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_NONE; } else if (strcmp("cf", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_CF; } else if (strcmp("json", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_JSON; } else { CfOut(OUTPUT_LEVEL_ERROR, "", "Invalid policy output format: '%s'. Possible values are 'none', 'cf', 'json'", optarg); exit(EXIT_FAILURE); } break; case 'K': IGNORELOCK = true; break; case 'D': config->heap_soft = StringSetFromString(optarg, ','); break; case 'N': config->heap_negated = StringSetFromString(optarg, ','); break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; break; case 'n': DONTDO = true; IGNORELOCK = true; LOOKUP = true; EvalContextHeapAddHard(ctx, "opt_dry_run"); break; case 'V': PrintVersionBanner("cf-promises"); exit(0); case 'h': Syntax("cf-promises - cfengine's promise analyzer", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-promises - cfengine's promise analyzer", OPTIONS, HINTS, ID); exit(0); case 'r': SHOWREPORTS = true; break; case 'x': CfOut(OUTPUT_LEVEL_ERROR, "", "Self-diagnostic functionality is retired."); exit(0); default: Syntax("cf-promises - cfengine's promise analyzer", OPTIONS, HINTS, ID); exit(1); } } if (argv[optind] != NULL) { CfOut(OUTPUT_LEVEL_ERROR, "", "Unexpected argument: %s\n", argv[optind]); } CfDebug("Set debugging\n"); return config; }
GenericAgentConfig *CheckOpts(int argc, char **argv) { extern char *optarg; int c; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_COMMON, GetTTYInteractive()); config->tag_release_dir = NULL; while ((c = getopt_long(argc, argv, "dvnIw:f:D:N:VSrxMb:i:p:s:cg:hW:C::T:l", OPTIONS, NULL)) != -1) { switch (c) { case OPT_EVAL_FUNCTIONS: if (!optarg) { optarg = "yes"; } config->agent_specific.common.eval_functions = strcmp("yes", optarg) == 0; break; case OPT_SHOW_CLASSES: config->agent_specific.common.show_classes = true; break; case OPT_SHOW_VARS: config->agent_specific.common.show_variables = true; break; case 'w': Log(LOG_LEVEL_INFO, "Setting workdir to '%s'", optarg); putenv(StringConcatenate(2, "CFENGINE_TEST_OVERRIDE_WORKDIR=", optarg)); break; case 'c': config->check_runnable = true; break; case 'f': GenericAgentConfigSetInputFile(config, GetInputDir(), optarg); MINUSF = true; break; case 'd': LogSetGlobalLevel(LOG_LEVEL_DEBUG); break; case 'b': if (optarg) { Rlist *bundlesequence = RlistFromSplitString(optarg, ','); GenericAgentConfigSetBundleSequence(config, bundlesequence); RlistDestroy(bundlesequence); } break; case 'p': if (strcmp("none", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_NONE; } else if (strcmp("cf", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_CF; } else if (strcmp("json", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_JSON; } else if (strcmp("cf-full", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_CF_FULL; } else if (strcmp("json-full", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_JSON_FULL; } else { Log(LOG_LEVEL_ERR, "Invalid policy output format: '%s'. Possible values are 'none', 'cf', 'json', 'cf-full', 'json-full'", optarg); exit(EXIT_FAILURE); } break; case 's': if (strcmp("none", optarg) == 0) { break; } else if (strcmp("json", optarg) == 0) { JsonElement *json_syntax = SyntaxToJson(); Writer *out = FileWriter(stdout); JsonWrite(out, json_syntax, 0); FileWriterDetach(out); JsonDestroy(json_syntax); exit(EXIT_SUCCESS); } else { Log(LOG_LEVEL_ERR, "Invalid syntax description output format: '%s'. Possible values are 'none', 'json'", optarg); exit(EXIT_FAILURE); } break; case 'K': config->ignore_locks = true; break; case 'D': { StringSet *defined_classes = StringSetFromString(optarg, ','); if (! config->heap_soft) { config->heap_soft = defined_classes; } else { StringSetJoin(config->heap_soft, defined_classes); free(defined_classes); } } break; case 'N': { StringSet *negated_classes = StringSetFromString(optarg, ','); if (! config->heap_negated) { config->heap_negated = negated_classes; } else { StringSetJoin(config->heap_negated, negated_classes); free(negated_classes); } } break; case 'I': LogSetGlobalLevel(LOG_LEVEL_INFO); break; case 'v': LogSetGlobalLevel(LOG_LEVEL_VERBOSE); break; case 'n': DONTDO = true; config->ignore_locks = true; break; case 'V': { Writer *w = FileWriter(stdout); GenericAgentWriteVersion(w); FileWriterDetach(w); } exit(EXIT_SUCCESS); case 'h': { Writer *w = FileWriter(stdout); GenericAgentWriteHelp(w, "cf-promises", OPTIONS, HINTS, true); FileWriterDetach(w); } exit(EXIT_SUCCESS); case 'M': { Writer *out = FileWriter(stdout); ManPageWrite(out, "cf-promises", time(NULL), CF_PROMISES_SHORT_DESCRIPTION, CF_PROMISES_MANPAGE_LONG_DESCRIPTION, OPTIONS, HINTS, true); FileWriterDetach(out); exit(EXIT_SUCCESS); } case 'r': Log(LOG_LEVEL_ERR, "Option '-r' has been deprecated"); exit(EXIT_FAILURE); break; case 'W': if (!GenericAgentConfigParseWarningOptions(config, optarg)) { Log(LOG_LEVEL_ERR, "Error parsing warning option"); exit(EXIT_FAILURE); } break; case 'x': Log(LOG_LEVEL_ERR, "Self-diagnostic functionality is retired."); exit(EXIT_SUCCESS); case 'C': if (!GenericAgentConfigParseColor(config, optarg)) { exit(EXIT_FAILURE); } break; case 'T': GenericAgentConfigSetInputFile(config, optarg, "promises.cf"); MINUSF = true; config->tag_release_dir = xstrdup(optarg); break; case 'l': LoggingEnableTimestamps(true); break; default: { Writer *w = FileWriter(stdout); GenericAgentWriteHelp(w, "cf-promises", OPTIONS, HINTS, true); FileWriterDetach(w); } exit(EXIT_FAILURE); } } if (!GenericAgentConfigParseArguments(config, argc - optind, argv + optind)) { Log(LOG_LEVEL_ERR, "Too many arguments"); exit(EXIT_FAILURE); } return config; }
GenericAgentConfig *CheckOpts(int argc, char **argv) { extern char *optarg; char ld_library_path[CF_BUFSIZE]; int optindex = 0; int c; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_SERVER); while ((c = getopt_long(argc, argv, "dvIKf:D:N:VSxLFMhA", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': if (optarg && (strlen(optarg) < 5)) { CfOut(OUTPUT_LEVEL_ERROR, "", " -f used but argument \"%s\" incorrect", optarg); exit(EXIT_FAILURE); } GenericAgentConfigSetInputFile(config, GetWorkDir(), optarg); MINUSF = true; break; case 'd': config->debug_mode = true; NO_FORK = true; case 'K': IGNORELOCK = true; break; case 'D': config->heap_soft = StringSetFromString(optarg, ','); break; case 'N': config->heap_negated = StringSetFromString(optarg, ','); break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; NO_FORK = true; break; case 'F': NO_FORK = true; break; case 'L': CfOut(OUTPUT_LEVEL_VERBOSE, "", "Setting LD_LIBRARY_PATH=%s\n", optarg); snprintf(ld_library_path, CF_BUFSIZE - 1, "LD_LIBRARY_PATH=%s", optarg); putenv(ld_library_path); break; case 'V': PrintVersion(); exit(0); case 'h': Syntax("cf-serverd", OPTIONS, HINTS, ID, true); exit(0); case 'M': ManPage("cf-serverd - CFEngine's server agent", OPTIONS, HINTS, ID); exit(0); case 'x': CfOut(OUTPUT_LEVEL_ERROR, "", "Self-diagnostic functionality is retired."); exit(0); case 'A': #ifdef HAVE_AVAHI_CLIENT_CLIENT_H #ifdef HAVE_AVAHI_COMMON_ADDRESS_H printf("Generating Avahi configuration file.\n"); if (GenerateAvahiConfig("/etc/avahi/services/cfengine-hub.service") != 0) { exit(1); } cf_popen("/etc/init.d/avahi-daemon restart", "r", true); printf("Avahi configuration file generated successfuly.\n"); exit(0); #else printf("This option can only be used when avahi-daemon and libavahi are installed on the machine.\n"); #endif #endif default: Syntax("cf-serverd", OPTIONS, HINTS, ID, true); exit(1); } } if (!GenericAgentConfigParseArguments(config, argc - optind, argv + optind)) { Log(LOG_LEVEL_ERR, "Too many arguments"); exit(EXIT_FAILURE); } return config; }