summaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorDenis Vlasenko2008-10-15 08:22:55 +0000
committerDenis Vlasenko2008-10-15 08:22:55 +0000
commit58cc52aa76462d668a37af8e5ae70a190e54f105 (patch)
tree30ec182f532bcbe85ee1cfd6780983bf5ee3aa0d /procps
parentd44c1535ae0e92ad300cd728783ec9672d662816 (diff)
downloadbusybox-58cc52aa76462d668a37af8e5ae70a190e54f105.zip
busybox-58cc52aa76462d668a37af8e5ae70a190e54f105.tar.gz
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.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/procps/sysctl.c b/procps/sysctl.c
index 79f0074..18caa2c 100644
--- a/procps/sysctl.c
+++ b/procps/sysctl.c
@@ -20,6 +20,7 @@ static int sysctl_read_setting(const char *setting);
static int sysctl_write_setting(const char *setting);
static int sysctl_display_all(const char *path);
static int sysctl_preload_file_and_exit(const char *filename);
+static void sysctl_dots_to_slashes(char *name);
static const char ETC_SYSCTL_CONF[] ALIGN1 = "/etc/sysctl.conf";
static const char PROC_SYS[] ALIGN1 = "/proc/sys/";
@@ -143,8 +144,7 @@ static int sysctl_write_setting(const char *setting)
tmpname = xasprintf("%s%.*s", PROC_SYS, (int)(equals - name), name);
outname = xstrdup(tmpname + strlen_PROC_SYS);
- while ((cptr = strchr(tmpname, '.')) != NULL)
- *cptr = '/';
+ sysctl_dots_to_slashes(tmpname);
while ((cptr = strchr(outname, '/')) != NULL)
*cptr = '.';
@@ -198,8 +198,8 @@ static int sysctl_read_setting(const char *name)
tmpname = concat_path_file(PROC_SYS, name);
outname = xstrdup(tmpname + strlen_PROC_SYS);
- while ((cptr = strchr(tmpname, '.')) != NULL)
- *cptr = '/';
+ sysctl_dots_to_slashes(tmpname);
+
while ((cptr = strchr(outname, '/')) != NULL)
*cptr = '.';
@@ -266,3 +266,22 @@ static int sysctl_display_all(const char *path)
return retval;
} /* end sysctl_display_all() */
+
+static void sysctl_dots_to_slashes(char *name)
+{
+ char *cptr = name;
+
+ /* Example from bug 3894:
+ * net.ipv4.conf.eth0.100.mc_forwarding ->
+ * net/ipv4/conf/eth0.100/mc_forwarding */
+ while (*cptr != '\0') {
+ if (*cptr == '.') {
+ *cptr = '\0';
+ if (access(name, F_OK) == 0)
+ *cptr = '/';
+ else
+ *cptr = '.';
+ }
+ cptr++;
+ }
+} /* end sysctl_dots_to_slashes() */