Пример #1
0
int sysctl_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
	int retval;
	int opt;

	opt = getopt32(argv, "+neAapw"); /* '+' - stop on first non-option */
	argv += optind;
	opt ^= (FLAG_SHOW_KEYS | FLAG_SHOW_KEY_ERRORS);
	option_mask32 ^= (FLAG_SHOW_KEYS | FLAG_SHOW_KEY_ERRORS);

	if (opt & (FLAG_TABLE_FORMAT | FLAG_SHOW_ALL))
		return sysctl_display_all(PROC_SYS);
	if (opt & FLAG_PRELOAD_FILE)
		return sysctl_preload_file_and_exit(*argv ? *argv : ETC_SYSCTL_CONF);

	retval = 0;
	while (*argv) {
		if (opt & FLAG_WRITE)
			retval |= sysctl_write_setting(*argv);
		else
			retval |= sysctl_read_setting(*argv);
		argv++;
	}

	return retval;
} /* end sysctl_main() */
Пример #2
0
int sysctl_main(int argc, char **argv)
{
    int retval = 0;
    int output = 1;
    int write_mode = 0;
    int switches_allowed = 1;

    if (argc < 2)
        bb_show_usage();

    argv++;

    for (; argv && *argv && **argv; argv++) {
        if (switches_allowed && **argv == '-') {	/* we have a switch */
            switch ((*argv)[1]) {
            case 'n':
                output = 0;
                break;
            case 'w':
                write_mode = 1;
                switches_allowed = 0;
                break;
            case 'p':
                argv++;
                return
                    sysctl_preload_file(((argv && *argv
                                          && **argv) ? *argv :
                                         DEFAULT_PRELOAD), output);
            case 'a':
            case 'A':
                switches_allowed = 0;
                return sysctl_display_all(PROC_PATH, output,
                                          ((*argv)[1] == 'a') ? 0 : 1);
            case 'h':
            case '?':
                bb_show_usage();
            default:
                bb_error_msg(ERR_UNKNOWN_PARAMETER, *argv);
                bb_show_usage();
            }
        } else {
            switches_allowed = 0;
            if (write_mode)
                retval = sysctl_write_setting(*argv, output);
            else
                sysctl_read_setting(*argv, output);
        }
    }
    return retval;
}						/* end sysctl_main() */
Пример #3
0
static int sysctl_preload_file_and_exit(const char *filename)
{
	int lineno;
	char oneline[PRELOAD_BUF];
	char buffer[PRELOAD_BUF];
	char *name, *value;
	FILE *fp;

	fp = xfopen(filename, "r");

	lineno = 0;
	while (fgets(oneline, sizeof(oneline) - 1, fp)) {
		lineno++;
		trim(oneline);
		if (oneline[0] == '#' || oneline[0] == ';')
			continue;
		if (!oneline[0] || !oneline[1])
			continue;

		name = strtok(oneline, "=");
		if (!name) {
			bb_error_msg(WARN_BAD_LINE, filename, lineno);
			continue;
		}
		trim(name);
		if (!*name) {
			bb_error_msg(WARN_BAD_LINE, filename, lineno);
			continue;
		}

		value = strtok(NULL, "\n\r");
		if (!value) {
			bb_error_msg(WARN_BAD_LINE, filename, lineno);
			continue;
		}
		while (*value == ' ' || *value == '\t')
			value++;
		if (!*value) {
			bb_error_msg(WARN_BAD_LINE, filename, lineno);
			continue;
		}

		/* safe because sizeof(oneline) == sizeof(buffer) */
		sprintf(buffer, "%s=%s", name, value);
		sysctl_write_setting(buffer);
	}
	if (ENABLE_FEATURE_CLEAN_UP)
		fclose(fp);
	return 0;
} /* end sysctl_preload_file_and_exit() */
Пример #4
0
int sysctl_preload_file(const char *filename, int output)
{
	int lineno = 0;
	char oneline[PRELOAD_BUF];
	char buffer[PRELOAD_BUF];
	char *name, *value, *ptr;
	FILE *fp = NULL;

	if (!filename || ((fp = fopen(filename, "r")) == NULL)) {
		bb_error_msg_and_die(ERR_PRELOAD_FILE, filename);
	}

	while (fgets(oneline, sizeof(oneline) - 1, fp)) {
		oneline[sizeof(oneline) - 1] = 0;
		lineno++;
		trim(oneline);
		ptr = (char *) oneline;

		if (*ptr == '#' || *ptr == ';')
			continue;

		if (bb_strlen(ptr) < 2)
			continue;

		name = strtok(ptr, "=");
		if (!name || !*name) {
			bb_error_msg(WARN_BAD_LINE, filename, lineno);
			continue;
		}

		trim(name);

		value = strtok(NULL, "\n\r");
		if (!value || !*value) {
			bb_error_msg(WARN_BAD_LINE, filename, lineno);
			continue;
		}

		while ((*value == ' ' || *value == '\t') && *value != 0)
			value++;
		strcpy(buffer, name);
		strcat(buffer, "=");
		strcat(buffer, value);
		sysctl_write_setting(buffer, output);
	}
	fclose(fp);
	return 0;
}						/* end sysctl_preload_file() */