aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-20 13:01:56 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-20 13:01:56 +0000
commit4a717e0c19098111d7fc41f260e01258556ddfbb (patch)
treed65386c0c0a0c2d80d712847221551ebecee33e3 /procps
parentdcb3fcb042612bfbb311a488379c65024bafd52b (diff)
downloadbusybox-4a717e0c19098111d7fc41f260e01258556ddfbb.tar.gz
libbb: fixes to config_read() by maintainer
sysctl: use config_read() function old new delta sysctl_main 121 232 +111 config_read 478 502 +24 parse_main 239 241 +2 sysctl_preload_file_and_exit 234 - -234 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 3/0 up/down: 137/-234) Total: -97 bytes
Diffstat (limited to 'procps')
-rw-r--r--procps/sysctl.c60
1 files changed, 18 insertions, 42 deletions
diff --git a/procps/sysctl.c b/procps/sysctl.c
index 3607a2364..6e582b0f9 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() */