diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-20 13:01:56 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-20 13:01:56 +0000 |
| commit | 4a717e0c19098111d7fc41f260e01258556ddfbb (patch) | |
| tree | d65386c0c0a0c2d80d712847221551ebecee33e3 /procps/sysctl.c | |
| parent | dcb3fcb042612bfbb311a488379c65024bafd52b (diff) | |
| download | busybox-w32-4a717e0c19098111d7fc41f260e01258556ddfbb.tar.gz busybox-w32-4a717e0c19098111d7fc41f260e01258556ddfbb.tar.bz2 busybox-w32-4a717e0c19098111d7fc41f260e01258556ddfbb.zip | |
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/sysctl.c')
| -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 3607a2364..6e582b0f9 100644 --- a/procps/sysctl.c +++ b/procps/sysctl.c | |||
| @@ -88,56 +88,32 @@ int sysctl_main(int argc UNUSED_PARAM, char **argv) | |||
| 88 | * preload the sysctl's from a conf file | 88 | * preload the sysctl's from a conf file |
| 89 | * - we parse the file and then reform it (strip out whitespace) | 89 | * - we parse the file and then reform it (strip out whitespace) |
| 90 | */ | 90 | */ |
| 91 | #define PRELOAD_BUF 256 | ||
| 92 | 91 | ||
| 93 | static int sysctl_preload_file_and_exit(const char *filename) | 92 | static int sysctl_preload_file_and_exit(const char *filename) |
| 94 | { | 93 | { |
| 95 | int lineno; | 94 | char *token[2]; |
| 96 | char oneline[PRELOAD_BUF]; | 95 | parser_t *parser; |
| 97 | char buffer[PRELOAD_BUF]; | ||
| 98 | char *name, *value; | ||
| 99 | FILE *fp; | ||
| 100 | 96 | ||
| 101 | fp = xfopen(filename, "r"); | 97 | parser = config_open(filename); |
| 102 | 98 | if (!parser) | |
| 103 | lineno = 0; | 99 | return 1; |
| 104 | while (fgets(oneline, sizeof(oneline) - 1, fp)) { | ||
| 105 | lineno++; | ||
| 106 | trim(oneline); | ||
| 107 | if (oneline[0] == '#' || oneline[0] == ';') | ||
| 108 | continue; | ||
| 109 | if (!oneline[0] || !oneline[1]) | ||
| 110 | continue; | ||
| 111 | |||
| 112 | name = strtok(oneline, "="); | ||
| 113 | if (!name) { | ||
| 114 | bb_error_msg(WARN_BAD_LINE, filename, lineno); | ||
| 115 | continue; | ||
| 116 | } | ||
| 117 | trim(name); | ||
| 118 | if (!*name) { | ||
| 119 | bb_error_msg(WARN_BAD_LINE, filename, lineno); | ||
| 120 | continue; | ||
| 121 | } | ||
| 122 | 100 | ||
| 123 | value = strtok(NULL, "\n\r"); | 101 | while (config_read(parser, token, 2, 0, "# \t=", PARSE_LAST_IS_GREEDY)) { // TODO: ';' is comment char too |
| 124 | if (!value) { | 102 | if (!token[1]) { |
| 125 | bb_error_msg(WARN_BAD_LINE, filename, lineno); | 103 | bb_error_msg(WARN_BAD_LINE, filename, parser->lineno); |
| 126 | continue; | 104 | } else { |
| 127 | } | 105 | #if 0 |
| 128 | while (*value == ' ' || *value == '\t') | 106 | char *s = xasprintf("%s=%s", token[0], token[1]); |
| 129 | value++; | 107 | sysctl_write_setting(s); |
| 130 | if (!*value) { | 108 | free(s); |
| 131 | bb_error_msg(WARN_BAD_LINE, filename, lineno); | 109 | #else // PLAY_WITH_FIRE for -4 bytes? |
| 132 | continue; | 110 | sprintf(parser->line, "%s=%s", token[0], token[1]); // must have room by definition |
| 111 | sysctl_write_setting(parser->line); | ||
| 112 | #endif | ||
| 133 | } | 113 | } |
| 134 | |||
| 135 | /* safe because sizeof(oneline) == sizeof(buffer) */ | ||
| 136 | sprintf(buffer, "%s=%s", name, value); | ||
| 137 | sysctl_write_setting(buffer); | ||
| 138 | } | 114 | } |
| 139 | if (ENABLE_FEATURE_CLEAN_UP) | 115 | if (ENABLE_FEATURE_CLEAN_UP) |
| 140 | fclose(fp); | 116 | config_close(parser); |
| 141 | return 0; | 117 | return 0; |
| 142 | } /* end sysctl_preload_file_and_exit() */ | 118 | } /* end sysctl_preload_file_and_exit() */ |
| 143 | 119 | ||
