chiark / gitweb /
sysctl: replaces some slashes with dots
[elogind.git] / src / sysctl / sysctl.c
index 283eefe1a1d233e49786034668d64c80cbe507f6..06defa5b7cdf69c567a360f16fd0fbe4ccddf44d 100644 (file)
@@ -48,12 +48,26 @@ static const char conf_file_dirs[] =
 #endif
         ;
 
 #endif
         ;
 
-static char *normalize_sysctl(char *s) {
+static charnormalize_sysctl(char *s) {
         char *n;
 
         char *n;
 
-        for (n = s; *n; n++)
+        n = strpbrk(s, "/.");
+        /* If the first separator is a slash, the path is
+         * assumed to be normalized and slashes remain slashes
+         * and dots remains dots. */
+        if (!n || *n == '/')
+                return s;
+
+        /* Otherwise, dots become slashes and slashes become
+         * dots. Fun. */
+        while (n) {
                 if (*n == '.')
                         *n = '/';
                 if (*n == '.')
                         *n = '/';
+                else
+                        *n = '.';
+
+                n = strpbrk(n + 1, "/.");
+        }
 
         return s;
 }
 
         return s;
 }