dhcpc: code shrink in good_hostname
[oweals/busybox.git] / procps / sysctl.c
index 94a3079012bc40f95320b3d7353e9b16f349a7ad..6d77185caec8ef5b2c6887b2a1df85f749acab13 100644 (file)
@@ -56,7 +56,31 @@ enum {
 
 static void sysctl_dots_to_slashes(char *name)
 {
-       char *cptr, *last_good, *end;
+       char *cptr, *last_good, *end, *slash;
+       char end_ch;
+
+       end = strchrnul(name, '=');
+
+       slash = strchrnul(name, '/');
+       if (slash < end
+        && strchrnul(name, '.') < slash
+       ) {
+               /* There are both dots and slashes, and 1st dot is
+                * before 1st slash.
+                * (IOW: not raw, unmangled a/b/c.d format)
+                *
+                * procps supports this syntax for names with dots:
+                *  net.ipv4.conf.eth0/100.mc_forwarding
+                * (dots and slashes are simply swapped)
+                */
+               while (end != name) {
+                       end--;
+                       if (*end == '.') *end = '/';
+                       else if (*end == '/') *end = '.';
+               }
+               return;
+       }
+       /* else: use our old behavior: */
 
        /* Convert minimum number of '.' to '/' so that
         * we end up with existing file's name.
@@ -76,10 +100,10 @@ static void sysctl_dots_to_slashes(char *name)
         *
         * To set up testing: modprobe 8021q; vconfig add eth0 100
         */
-       end = name + strlen(name);
-       last_good = name - 1;
+       end_ch = *end;
        *end = '.'; /* trick the loop into trying full name too */
 
+       last_good = name - 1;
  again:
        cptr = end;
        while (cptr > last_good) {
@@ -96,7 +120,7 @@ static void sysctl_dots_to_slashes(char *name)
                }
                cptr--;
        }
-       *end = '\0';
+       *end = end_ch;
 }
 
 static int sysctl_act_on_setting(char *setting)
@@ -112,6 +136,8 @@ static int sysctl_act_on_setting(char *setting)
        while (*cptr) {
                if (*cptr == '/')
                        *cptr = '.';
+               else if (*cptr == '.')
+                       *cptr = '/';
                cptr++;
        }