aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-03-29 02:22:19 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-03-29 02:22:19 +0000
commit5a6617acb81020a3becd91bd21f427157d7c9dcd (patch)
tree476c2a0e3092c891e36bd87daac88544917f9ff8
parentb975febeea845d3731bbed46f8936f352ffc3be6 (diff)
downloadbusybox-w32-5a6617acb81020a3becd91bd21f427157d7c9dcd.tar.gz
busybox-w32-5a6617acb81020a3becd91bd21f427157d7c9dcd.tar.bz2
busybox-w32-5a6617acb81020a3becd91bd21f427157d7c9dcd.zip
sysctl: fix broken -p [file] - close bug 231
-rw-r--r--procps/sysctl.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/procps/sysctl.c b/procps/sysctl.c
index 862cd1756..dce264dac 100644
--- a/procps/sysctl.c
+++ b/procps/sysctl.c
@@ -76,12 +76,15 @@ static int sysctl_handle_preload_file(const char *filename)
76 xchdir("/proc/sys"); 76 xchdir("/proc/sys");
77 /* xchroot(".") - if you are paranoid */ 77 /* xchroot(".") - if you are paranoid */
78 78
79// TODO: ';' is comment char too 79//TODO: ';' is comment char too
80//TODO: comment may be only at line start. "var=1 #abc" - "1 #abc" is the value
81// (but _whitespace_ from ends should be trimmed first (and we do it right))
82//TODO: "var==1" is mishandled (must use "=1" as a value, but uses "1")
80 while (config_read(parser, token, 2, 2, "# \t=", PARSE_NORMAL)) { 83 while (config_read(parser, token, 2, 2, "# \t=", PARSE_NORMAL)) {
84 sysctl_dots_to_slashes(token[0]);
81 /* Save ~4 bytes by using parser internals */ 85 /* Save ~4 bytes by using parser internals */
82 /* parser->line is big enough for sprintf */ 86 /* parser->line is big enough for sprintf */
83 sprintf(parser->line, "%s=%s", token[0], token[1]); 87 sprintf(parser->line, "%s=%s", token[0], token[1]);
84 sysctl_dots_to_slashes(parser->line);
85 sysctl_display_all(parser->line); 88 sysctl_display_all(parser->line);
86 } 89 }
87 if (ENABLE_FEATURE_CLEAN_UP) 90 if (ENABLE_FEATURE_CLEAN_UP)
@@ -119,6 +122,8 @@ static int sysctl_act_on_setting(char *setting)
119 goto end; 122 goto end;
120 } 123 }
121 *cptr = '\0'; 124 *cptr = '\0';
125 outname[cptr - setting] = '\0';
126 /* procps 3.2.7 actually uses these flags */
122 fd = open(setting, O_WRONLY|O_CREAT|O_TRUNC, 0666); 127 fd = open(setting, O_WRONLY|O_CREAT|O_TRUNC, 0666);
123 } else { 128 } else {
124 fd = open(setting, O_RDONLY); 129 fd = open(setting, O_RDONLY);
@@ -142,6 +147,7 @@ static int sysctl_act_on_setting(char *setting)
142 } 147 }
143 148
144 if (option_mask32 & FLAG_WRITE) { 149 if (option_mask32 & FLAG_WRITE) {
150//TODO: procps 3.2.7 writes "value\n", note trailing "\n"
145 xwrite_str(fd, value); 151 xwrite_str(fd, value);
146 close(fd); 152 close(fd);
147 if (option_mask32 & FLAG_SHOW_KEYS) 153 if (option_mask32 & FLAG_SHOW_KEYS)
@@ -194,8 +200,7 @@ static int sysctl_display_all(const char *path)
194 if (dirp == NULL) 200 if (dirp == NULL)
195 return -1; 201 return -1;
196 while ((entry = readdir(dirp)) != NULL) { 202 while ((entry = readdir(dirp)) != NULL) {
197 next = concat_subpath_file( 203 next = concat_subpath_file(path, entry->d_name);
198 path, entry->d_name);
199 if (next == NULL) 204 if (next == NULL)
200 continue; /* d_name is "." or ".." */ 205 continue; /* d_name is "." or ".." */
201 /* if path was ".", drop "./" prefix: */ 206 /* if path was ".", drop "./" prefix: */