aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
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)
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
93static int sysctl_preload_file_and_exit(const char *filename) 92static 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