Пример #1
0
/*
 * Loads all the NDMP configuration parameters and sets up the
 * config table.
 */
int
ndmpd_load_prop(void)
{
	ndmpd_cfg_id_t id;
	ndmpd_cfg_param_t *cfg;
	char *value;

	for (id = 0; id < NDMP_MAXALL; id++) {
		cfg = &ndmpd_cfg_table[id];
		if ((ndmp_get_prop(cfg->sc_name, &value)) == -1) {
			syslog(LOG_DEBUG, "%s %s",
			    cfg->sc_name, ndmp_strerror(ndmp_errno));
			continue;
		}
		/*
		 * enval == 0 could mean two things, either the
		 * config param is not defined, or it has been
		 * removed. If the variable has already been defined
		 * and now enval is 0, it should be removed, otherwise
		 * we don't need to do anything in this case.
		 */
		if ((cfg->sc_flags & NDMP_CF_DEFINED) || value) {
			if (ndmpd_config_update(cfg, value)) {
				free(value);
				return (-1);
			}
		}
		free(value);
	}
	return (0);
}
Пример #2
0
/*ARGSUSED*/
static int
ndmp_get_config(int argc, char **argv, ndmp_command_t *cur_cmd)
{
	char *propval;
	int i, c;

	if (argc == 1) {
		/*
		 * Get all the properties and variables ndmpadm is allowed
		 * to see.
		 */
		for (i = 0; i < NDMPADM_NPROP; i++) {
			if (ndmp_get_prop(prop_table[i], &propval)) {
				(void) fprintf(stdout, "\t%s=\n",
				    prop_table[i]);
			} else {
				(void) fprintf(stdout, "\t%s=%s\n",
				    prop_table[i], propval);
				free(propval);
			}
		}
	} else if (argc > 1) {
		while ((c = getopt(argc, argv, ":p:")) != -1) {
			switch (c) {
			case 'p':
				ndmp_get_config_process(optarg);
				break;
			case ':':
				(void) fprintf(stderr, gettext("Option -%c "
				    "requires an operand\n"), optopt);
				break;
			case '?':
				(void) fprintf(stderr, gettext("Unrecognized "
				    "option: -%c\n"), optopt);
			}
		}
		/*
		 * optind is initialized to 1 if the -p option is not used,
		 * otherwise index to argv.
		 */
		argc -= optind;
		argv += optind;

		for (i = 0; i < argc; i++) {
			if (strncmp(argv[i], "-p", 2) == 0)
				continue;

			ndmp_get_config_process(argv[i]);
		}
	}
	return (0);
}
Пример #3
0
static void
ndmp_get_config_process(char *arg)
{
	int j;
	char *propval;

	for (j = 0; j < NDMPADM_NPROP; j++) {
		if (strcmp(arg, prop_table[j]) == 0) {
			if (ndmp_get_prop(arg, &propval)) {
				(void) fprintf(stdout, "\t%s=\n", arg);
			} else {
				(void) fprintf(stdout, "\t%s=%s\n",
				    arg, propval);
				free(propval);
			}
			break;
		}
	}
	if (j == NDMPADM_NPROP) {
		(void) fprintf(stdout, gettext("\t%s is invalid property "
		    "or variable\n"), arg);
	}
}