diff options
-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() */ | ||