diff options
Diffstat (limited to 'procps')
-rw-r--r-- | procps/sysctl.c | 60 |
1 files changed, 18 insertions, 42 deletions
diff --git a/procps/sysctl.c b/procps/sysctl.c index 3607a23..6e582b0 100644 --- a/procps/sysctl.c +++ b/procps/sysctl.c @@ -88,56 +88,32 @@ int sysctl_main(int argc UNUSED_PARAM, char **argv) * preload the sysctl's from a conf file * - we parse the file and then reform it (strip out whitespace) */ -#define PRELOAD_BUF 256 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; + char *token[2]; + parser_t *parser; - 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; - } + parser = config_open(filename); + if (!parser) + return 1; - 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; + while (config_read(parser, token, 2, 0, "# \t=", PARSE_LAST_IS_GREEDY)) { // TODO: ';' is comment char too + if (!token[1]) { + bb_error_msg(WARN_BAD_LINE, filename, parser->lineno); + } else { +#if 0 + char *s = xasprintf("%s=%s", token[0], token[1]); + sysctl_write_setting(s); + free(s); +#else // PLAY_WITH_FIRE for -4 bytes? + sprintf(parser->line, "%s=%s", token[0], token[1]); // must have room by definition + sysctl_write_setting(parser->line); +#endif } - - /* safe because sizeof(oneline) == sizeof(buffer) */ - sprintf(buffer, "%s=%s", name, value); - sysctl_write_setting(buffer); } if (ENABLE_FEATURE_CLEAN_UP) - fclose(fp); + config_close(parser); return 0; } /* end sysctl_preload_file_and_exit() */ |