sysctl: replaces some slashes with dots

It turns out that plain sysctl understands a.b/c syntax to write to
/proc/sys/a/b.c. Support this for compatibility.

https://bugs.freedesktop.org/show_bug.cgi?id=77466
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2014-04-16 21:52:36 -04:00
parent 806a37e743
commit 2e573fcf87
2 changed files with 36 additions and 9 deletions
+16 -2
View File
@@ -48,12 +48,26 @@ static const char conf_file_dirs[] =
#endif
;
static char *normalize_sysctl(char *s) {
static char* normalize_sysctl(char *s) {
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 = '/';
else
*n = '.';
n = strpbrk(n + 1, "/.");
}
return s;
}