Ejemplo n.º 1
0
void
ni_log_init(void)
{
	const char *var = getenv("WICKED_DEBUG");

	if (ni_string_empty(var) && (var = getenv("DEBUG"))) {
		if (ni_string_eq(var, "no"))
			var = "";
		else
		if (ni_string_eq(var, "yes"))
			var = "most";
	}
	if (!ni_string_empty(var))
		ni_enable_debug(var);

	if ((var = getenv("WICKED_LOG_LEVEL"))) {
		ni_log_level_set(var);
	}
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: kmroz/wicked
int
main(int argc, char **argv)
{
	dhcp4_tester_t * tester = NULL;
	int c, status = NI_WICKED_RC_USAGE;

	ni_log_init();
	program_name = ni_basename(argv[0]);

	while ((c = getopt_long(argc, argv, "+", options, NULL)) != EOF) {
		switch (c) {
		/* common */
		case OPT_HELP:
			status = NI_WICKED_RC_SUCCESS;
		default:
		usage:
			fprintf(stderr,
				"%s [options]\n"
				"This command understands the following options\n"
				"  --help\n"
				"  --version\n"
				"  --config filename\n"
				"        Read configuration file <filename> instead of system default.\n"
				"  --log-level level\n"
				"        Set log level to <error|warning|notice|info|debug>.\n"
				"  --log-target target\n"
				"        Set log destination to <stderr|syslog>.\n"
				"  --debug facility\n"
				"        Enable debugging for debug <facility>.\n"
				"        Use '--debug help' for a list of facilities.\n"
				"  --foreground\n"
				"        Do not background the service.\n"
				"  --recover\n"
				"        Enable automatic recovery of daemon's state.\n"
				"  --systemd\n"
				"        Enables behavior required by systemd service\n"
				"\n"
				"  --test [test-options] <ifname>\n"
				"    test-options:\n"
				"       --test-request <request.xml>\n"
				"       --test-timeout <timeout in sec> (default: 20+10)\n"
				"       --test-output  <output file name>\n"
				"       --test-format  <leaseinfo|lease-xml>\n"
				, program_name);
			return status;

		case OPT_VERSION:
			printf("%s %s\n", program_name, PACKAGE_VERSION);
			return NI_WICKED_RC_SUCCESS;

		case OPT_CONFIGFILE:
			if (!ni_set_global_config_path(optarg)) {
				fprintf(stderr, "Unable to set config file '%s': %m\n",
						optarg);
				return NI_WICKED_RC_ERROR;
			}
			break;

		case OPT_DEBUG:
			if (!strcmp(optarg, "help")) {
				printf("Supported debug facilities:\n");
				ni_debug_help();
				return NI_WICKED_RC_SUCCESS;
			}
			if (ni_enable_debug(optarg) < 0) {
				fprintf(stderr, "Bad debug facility \"%s\"\n", optarg);
				goto usage;
			}
			break;

		case OPT_LOG_LEVEL:
			if (!ni_log_level_set(optarg)) {
				fprintf(stderr, "Bad log level \%s\"\n", optarg);
				goto usage;
			}
			break;

		case OPT_LOG_TARGET:
			opt_log_target = optarg;
			break;

		/* daemon */
		case OPT_FOREGROUND:
			opt_foreground = TRUE;
			break;

		/* specific */
		case OPT_RECOVER:
			opt_recover_state = TRUE;
			break;

		case OPT_SYSTEMD:
			opt_systemd = TRUE;
			break;

		/* test run */
		case OPT_TEST:
			opt_foreground = TRUE;
			tester = dhcp4_tester_init();
			break;

		case OPT_TEST_REQUEST:
			if (!tester || ni_string_empty(optarg))
				goto usage;
			tester->request = optarg;
			break;

		case OPT_TEST_TIMEOUT:
			if (!tester || ni_parse_uint(optarg,
						&tester->timeout, 0) < 0)
				goto usage;
			break;

		case OPT_TEST_OUTPUT:
			if (!tester || ni_string_empty(optarg))
				goto usage;
			tester->output = optarg;
			break;

		case OPT_TEST_OUTFMT:
			if (!tester || !dhcp4_tester_set_outfmt(optarg,
						&tester->outfmt))
				goto usage;
			break;
		}
	}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: waytai/wicked
int
main(int argc, char **argv)
{
	int c;

	program_name = ni_basename(argv[0]);

	while ((c = getopt_long(argc, argv, "+", options, NULL)) != EOF) {
		switch (c) {
		case OPT_HELP:
		default:
		usage:
			fprintf(stderr,
				"%s [options]\n"
				"This command understands the following options\n"
				"  --help\n"
				"  --version\n"
				"  --config filename\n"
				"        Read configuration file <filename> instead of system default.\n"
				"  --debug facility\n"
				"        Enable debugging for debug <facility>.\n"
				"        Use '--debug help' for a list of debug facilities.\n"
				"  --log-devel level\n"
				"        Set log level to <error|warning|notice|info|debug>.\n"
				"  --log-target target\n"
				"        Set log destination to <stderr|syslog>.\n"
				"  --foreground\n"
				"        Run as a foreground process, rather than as a daemon.\n"
				"  --log-target target\n"
				"        Set log destination target to <target>.\n"
				, program_name);
			return (c == OPT_HELP ? 0 : 1);

		case OPT_VERSION:
			printf("%s %s\n", program_name, PACKAGE_VERSION);
			return 0;

		case OPT_CONFIGFILE:
			ni_set_global_config_path(optarg);
			break;

		case OPT_DEBUG:
			if (!strcmp(optarg, "help")) {
				printf("Supported debug facilities:\n");
				ni_debug_help();
				return 0;
			}
			if (ni_enable_debug(optarg) < 0) {
				fprintf(stderr, "Bad debug facility \"%s\"\n", optarg);
				return 1;
			}
			break;

		case OPT_LOG_LEVEL:
			if (!ni_log_level_set(optarg)) {
				fprintf(stderr, "Bad log level \%s\"\n", optarg);
				return 1;
			}
			break;

		case OPT_LOG_TARGET:
			opt_log_target = optarg;
			break;

		case OPT_FOREGROUND:
			opt_foreground = 1;
			break;

		case OPT_NOMODEMMGR:
			opt_no_modem_manager = 1;
			break;
		}
	}
Ejemplo n.º 4
0
int
main(int argc, char **argv)
{
	int c;

	ni_log_init();
	program_name = ni_basename(argv[0]);

	while ((c = getopt_long(argc, argv, "+", options, NULL)) != EOF) {
		switch (c) {
		case OPT_HELP:
		default:
		usage:
			fprintf(stderr,
				"%s [options]\n"
				"This command understands the following options\n"
				"  --help\n"
				"  --version\n"
				"  --config filename\n"
				"        Read configuration file <filename> instead of system default.\n"
				"  --debug facility\n"
				"        Enable debugging for debug <facility>.\n"
				"        Use '--debug help' for a list of facilities.\n"
				"  --log-level level\n"
				"        Set log level to <error|warning|notice|info|debug>.\n"
				"  --log-target target\n"
				"        Set log destination to <stderr|syslog>.\n"
				"  --foreground\n"
				"        Do not background the service.\n"
				"  --recover\n"
				"        Enable automatic recovery of daemon's state.\n"
				"  --systemd\n"
				"        Enables behavior required by systemd service\n"
				, program_name);
			return (c == OPT_HELP ? NI_LSB_RC_SUCCESS : NI_LSB_RC_USAGE);

		case OPT_VERSION:
			printf("%s %s\n", program_name, PACKAGE_VERSION);
			return NI_LSB_RC_SUCCESS;

		case OPT_CONFIGFILE:
			if (!ni_set_global_config_path(optarg)) {
				fprintf(stderr, "Unable to set config file '%s': %m\n", optarg);
				return NI_LSB_RC_ERROR;
			}
			break;

		case OPT_DEBUG:
			if (!strcmp(optarg, "help")) {
				printf("Supported debug facilities:\n");
				ni_debug_help();
				return NI_LSB_RC_SUCCESS;
			}
			if (ni_enable_debug(optarg) < 0) {
				fprintf(stderr, "Bad debug facility \"%s\"\n", optarg);
				goto usage;
			}
			break;

		case OPT_LOG_LEVEL:
			if (!ni_log_level_set(optarg)) {
				fprintf(stderr, "Bad log level \%s\"\n", optarg);
				goto usage;
			}
			break;

		case OPT_LOG_TARGET:
			opt_log_target = optarg;
			break;

		case OPT_FOREGROUND:
			opt_foreground = TRUE;
			break;

		case OPT_RECOVER:
			opt_recover_state = TRUE;
			break;

		case OPT_SYSTEMD:
			opt_systemd = TRUE;
			break;
		}
	}
Ejemplo n.º 5
0
Archivo: main.c Proyecto: mchf/wicked
int
main(int argc, char **argv)
{
	char *cmd;
	int c;

	mtrace();

	program_name = ni_basename(argv[0]);
	while ((c = getopt_long(argc, argv, "+", options, NULL)) != EOF) {
		switch (c) {
		case OPT_HELP:
		default:
		usage:
			fprintf(stderr,
				"wicked [options] cmd path\n"
				"This command understands the following options\n"
				"  --help\n"
				"  --version\n"
				"  --config filename\n"
				"        Use alternative configuration file.\n"
				"  --log-target target\n"
				"        Set log destination to <stderr|syslog>.\n"
				"  --log-level level\n"
				"        Set log level to <error|warning|notice|info|debug>.\n"
				"  --debug facility\n"
				"        Enable debugging for debug <facility>.\n"
				"        Use '--debug help' for a list of facilities.\n"
				"  --dry-run\n"
				"        Do not change the system in any way.\n"
				"  --root-directory\n"
				"        Search all config files below this directory.\n"
				"\n"
				"Supported commands:\n"
				"  ifup [options] ifname\n"
				"  ifdown [options] ifname\n"
				"  ifcheck\n"
				"  show [ifname}]\n"
				"  show-xml [--raw] [--modem] [ifname]\n"
				"  show-config [--mark] [source]\n"
				"  nanny [subcommand]\n"
				"  lease [subcommand]\n"
				"  check [subcommand]\n"
				"  getnames [subcommand]\n"
				"  convert [subcommand]\n"
				"  xpath [options] expr ...\n"
				);
			return (c == OPT_HELP ? 0 : 1);

		case OPT_VERSION:
			printf("%s %s\n", program_name, PACKAGE_VERSION);
			return 0;

		case OPT_CONFIGFILE:
			if (!ni_set_global_config_path(optarg)) {
				fprintf(stderr, "Unable to set config file '%s': %m\n", optarg);
				return 1;
			}
			break;

		case OPT_DEBUG:
			if (!strcmp(optarg, "help")) {
				printf("Supported debug facilities:\n");
				ni_debug_help();
				return 0;
			}
			if (ni_enable_debug(optarg) < 0) {
				fprintf(stderr, "Bad debug facility \"%s\"\n", optarg);
				return 1;
			}
			break;

		case OPT_LOG_TARGET:
			opt_log_target = optarg;
			break;

		case OPT_LOG_LEVEL:
			if (!ni_log_level_set(optarg)) {
				fprintf(stderr, "Bad log level \%s\"\n", optarg);
				return 1;
			}
			break;

		case OPT_DRYRUN:
			opt_global_dryrun = 1;
			break;

		case OPT_ROOTDIR:
			opt_global_rootdir = optarg;
			break;
		}
	}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: kmroz/wicked
int
main(int argc, char **argv)
{
	char *cmd;
	int c, status = NI_WICKED_RC_USAGE;

	mtrace();

	ni_log_init();
	program_name = ni_basename(argv[0]);

	while ((c = getopt_long(argc, argv, "+", options, NULL)) != EOF) {
		switch (c) {
		case OPT_HELP:
			status = NI_WICKED_ST_OK;
		default:
		usage:
			fprintf(stderr,
				"wicked [options] cmd path\n"
				"This command understands the following options\n"
				"  --help\n"
				"  --version\n"
				"  --config filename\n"
				"        Use alternative configuration file.\n"
				"  --log-target target\n"
				"        Set log destination to <stderr|syslog>.\n"
				"  --log-level level\n"
				"        Set log level to <error|warning|notice|info|debug>.\n"
				"  --debug facility\n"
				"        Enable debugging for debug <facility>.\n"
				"        Use '--debug help' for a list of facilities.\n"
				"  --dry-run\n"
				"        Do not change the system in any way.\n"
				"  --root-directory\n"
				"        Search all config files below this directory.\n"
				"  --systemd\n"
				"        Enables behavior required by systemd service\n"
				"\n"
				"Supported commands:\n"
				"  ifup        [options] <ifname ...>|all\n"
				"  ifdown      [options] <ifname ...>|all\n"
				"  ifcheck     [options] <ifname ...>|all\n"
				"  ifreload    [options] <ifname ...>|all\n"
				"  ifstatus    [options] <ifname ...>|all\n"
				"  show        [options] <ifname ...>|all\n"
#ifdef MODEM
				"  show-xml    [--raw] [--modem] <ifname|all>\n"
#endif
				"  show-xml    [--raw] <ifname|all>\n"
				"  show-config [--raw] [source]\n"
				"  nanny       [subcommand]\n"
				"  lease       [subcommand]\n"
				"  check       [subcommand]\n"
				"  getnames    [subcommand]\n"
				"  convert     [subcommand]\n"
				"  xpath       [options] expr ...\n"
				"  arp         [options] <ifname> <IP>\n"
				);
			goto done;

		case OPT_VERSION:
			printf("%s %s\n", program_name, PACKAGE_VERSION);
			status  = NI_WICKED_RC_SUCCESS;
			goto done;

		case OPT_CONFIGFILE:
			if (!ni_set_global_config_path(optarg)) {
				fprintf(stderr, "Unable to set config file '%s': %m\n", optarg);
				status = NI_WICKED_RC_ERROR;
				goto done;
			}
			break;

		case OPT_DEBUG:
			if (!strcmp(optarg, "help")) {
				printf("Supported debug facilities:\n");
				ni_debug_help();
				status = NI_WICKED_RC_SUCCESS;
				goto done;
			}
			if (ni_enable_debug(optarg) < 0) {
				fprintf(stderr, "Bad debug facility \"%s\"\n", optarg);
				goto usage;
			}
			break;

		case OPT_LOG_TARGET:
			opt_log_target = optarg;
			break;

		case OPT_LOG_LEVEL:
			if (!ni_log_level_set(optarg)) {
				fprintf(stderr, "Bad log level \%s\"\n", optarg);
				goto usage;
			}
			break;

		case OPT_DRYRUN:
			opt_global_dryrun = 1;
			break;

		case OPT_ROOTDIR:
			if (!ni_realpath(optarg, &opt_global_rootdir)) {
				fprintf(stderr, "Invalid root-directory path '%s': %m\n", optarg);
				status = NI_WICKED_RC_ERROR;
				goto done;
			}
			if (ni_string_eq(opt_global_rootdir, "/"))
				ni_string_free(&opt_global_rootdir);
			break;

		case OPT_SYSTEMD:
			opt_systemd = TRUE;
			break;
		}
	}
Ejemplo n.º 7
0
int
main(int argc, char **argv)
{
	const char *opt_reference = NULL;
	const char *expression = NULL, *filename = "-";
	xml_document_t *doc;
	xml_node_t *refnode;
	xpath_enode_t *enode;
	xpath_result_t *result;
	int c;

	while ((c = getopt_long(argc, argv, "", options, NULL)) != EOF) {
		switch (c) {
		default:
		usage:
			fprintf(stderr,
				"./xpath-test [--reference <expression>] <expression> [filename]\n"
			       );
			return 1;

		case OPT_DEBUG:
			if (ni_enable_debug(optarg) < 0) {
				fprintf(stderr, "Bad debug facility \"%s\"\n", optarg);
				return 1;
			}
			break;

		case OPT_REFERENCE:
			opt_reference = optarg;
			break;

		}
	}

	if (optind >= argc)
		goto usage;
	expression = argv[optind++];

	if (optind < argc)
		filename = argv[optind++];

	if (optind < argc)
		goto usage;

	doc = xml_document_read(filename);
	if (!doc) {
		fprintf(stderr, "Error parsing XML document %s\n", filename);
		return 1;
	}

	refnode = doc->root;
	if (opt_reference) {
		enode = xpath_expression_parse(opt_reference);
		if (!enode) {
			fprintf(stderr, "Error parsing XPATH expression %s\n", opt_reference);
			return 1;
		}

		result = xpath_expression_eval(enode, doc->root);
		if (!result) {
			fprintf(stderr, "Error evaluating XPATH expression\n");
			return 1;
		}

		if (result->type != XPATH_ELEMENT) {
			fprintf(stderr, "Failed to look up reference node - returned non-element result\n");
			return 1;
		}
		if (result->count == 0) {
			fprintf(stderr, "Failed to look up reference node - returned empty list\n");
			return 1;
		}
		refnode = result->node[0].value.node;

		xpath_result_free(result);
		xpath_expression_free(enode);
	}

	enode = xpath_expression_parse(expression);
	if (!enode) {
		fprintf(stderr, "Error parsing XPATH expression %s\n", expression);
		return 1;
	}

	result = xpath_expression_eval(enode, refnode);
	if (!result) {
		fprintf(stderr, "Error evaluating XPATH expression\n");
		return 1;
	}

	xpath_result_print(result, stdout);

	xpath_result_free(result);
	xpath_expression_free(enode);

	return 0;
}