diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-10-15 08:22:55 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-10-15 08:22:55 +0000 |
commit | 58cc52aa76462d668a37af8e5ae70a190e54f105 (patch) | |
tree | 30ec182f532bcbe85ee1cfd6780983bf5ee3aa0d /procps | |
parent | d44c1535ae0e92ad300cd728783ec9672d662816 (diff) | |
download | busybox-w32-58cc52aa76462d668a37af8e5ae70a190e54f105.tar.gz busybox-w32-58cc52aa76462d668a37af8e5ae70a190e54f105.tar.bz2 busybox-w32-58cc52aa76462d668a37af8e5ae70a190e54f105.zip |
sysctl: fix bug 3894 (by Kryzhanovskyy Maksym)
function old new delta
sysctl_dots_to_slashes - 47 +47
sysctl_write_setting 310 298 -12
sysctl_read_setting 296 284 -12
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 47/-24) Total: 23 bytes
Diffstat (limited to 'procps')
-rw-r--r-- | procps/sysctl.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/procps/sysctl.c b/procps/sysctl.c index 79f0074c9..18caa2c11 100644 --- a/procps/sysctl.c +++ b/procps/sysctl.c | |||
@@ -20,6 +20,7 @@ static int sysctl_read_setting(const char *setting); | |||
20 | static int sysctl_write_setting(const char *setting); | 20 | static int sysctl_write_setting(const char *setting); |
21 | static int sysctl_display_all(const char *path); | 21 | static int sysctl_display_all(const char *path); |
22 | static int sysctl_preload_file_and_exit(const char *filename); | 22 | static int sysctl_preload_file_and_exit(const char *filename); |
23 | static void sysctl_dots_to_slashes(char *name); | ||
23 | 24 | ||
24 | static const char ETC_SYSCTL_CONF[] ALIGN1 = "/etc/sysctl.conf"; | 25 | static const char ETC_SYSCTL_CONF[] ALIGN1 = "/etc/sysctl.conf"; |
25 | static const char PROC_SYS[] ALIGN1 = "/proc/sys/"; | 26 | static const char PROC_SYS[] ALIGN1 = "/proc/sys/"; |
@@ -143,8 +144,7 @@ static int sysctl_write_setting(const char *setting) | |||
143 | tmpname = xasprintf("%s%.*s", PROC_SYS, (int)(equals - name), name); | 144 | tmpname = xasprintf("%s%.*s", PROC_SYS, (int)(equals - name), name); |
144 | outname = xstrdup(tmpname + strlen_PROC_SYS); | 145 | outname = xstrdup(tmpname + strlen_PROC_SYS); |
145 | 146 | ||
146 | while ((cptr = strchr(tmpname, '.')) != NULL) | 147 | sysctl_dots_to_slashes(tmpname); |
147 | *cptr = '/'; | ||
148 | 148 | ||
149 | while ((cptr = strchr(outname, '/')) != NULL) | 149 | while ((cptr = strchr(outname, '/')) != NULL) |
150 | *cptr = '.'; | 150 | *cptr = '.'; |
@@ -198,8 +198,8 @@ static int sysctl_read_setting(const char *name) | |||
198 | tmpname = concat_path_file(PROC_SYS, name); | 198 | tmpname = concat_path_file(PROC_SYS, name); |
199 | outname = xstrdup(tmpname + strlen_PROC_SYS); | 199 | outname = xstrdup(tmpname + strlen_PROC_SYS); |
200 | 200 | ||
201 | while ((cptr = strchr(tmpname, '.')) != NULL) | 201 | sysctl_dots_to_slashes(tmpname); |
202 | *cptr = '/'; | 202 | |
203 | while ((cptr = strchr(outname, '/')) != NULL) | 203 | while ((cptr = strchr(outname, '/')) != NULL) |
204 | *cptr = '.'; | 204 | *cptr = '.'; |
205 | 205 | ||
@@ -266,3 +266,22 @@ static int sysctl_display_all(const char *path) | |||
266 | 266 | ||
267 | return retval; | 267 | return retval; |
268 | } /* end sysctl_display_all() */ | 268 | } /* end sysctl_display_all() */ |
269 | |||
270 | static void sysctl_dots_to_slashes(char *name) | ||
271 | { | ||
272 | char *cptr = name; | ||
273 | |||
274 | /* Example from bug 3894: | ||
275 | * net.ipv4.conf.eth0.100.mc_forwarding -> | ||
276 | * net/ipv4/conf/eth0.100/mc_forwarding */ | ||
277 | while (*cptr != '\0') { | ||
278 | if (*cptr == '.') { | ||
279 | *cptr = '\0'; | ||
280 | if (access(name, F_OK) == 0) | ||
281 | *cptr = '/'; | ||
282 | else | ||
283 | *cptr = '.'; | ||
284 | } | ||
285 | cptr++; | ||
286 | } | ||
287 | } /* end sysctl_dots_to_slashes() */ | ||