-static const char conf_file_dirs[] =
- "/etc/sysctl.d\0"
- "/run/sysctl.d\0"
- "/usr/local/lib/sysctl.d\0"
- "/usr/lib/sysctl.d\0"
-#ifdef HAVE_SPLIT_USR
- "/lib/sysctl.d\0"
-#endif
- ;
-
-static char *normalize_sysctl(char *s) {
- char *n;
-
- for (n = s; *n; n++)
- if (*n == '.')
- *n = '/';
-
- return s;
-}
-
-static int apply_sysctl(const char *property, const char *value) {
- _cleanup_free_ char *p = NULL;
- char *n;
- int r = 0, k;
-
- log_debug("Setting '%s' to '%s'", property, value);
-
- p = new(char, sizeof("/proc/sys/") + strlen(property));
- if (!p)
- return log_oom();
-
- n = stpcpy(p, "/proc/sys/");
- strcpy(n, property);
-
- if (!strv_isempty(arg_prefixes)) {
- char **i;
- bool good = false;
-
- STRV_FOREACH(i, arg_prefixes)
- if (path_startswith(p, *i)) {
- good = true;
- break;
- }
-
- if (!good) {
- log_debug("Skipping %s", p);
- return 0;
- }
- }
-
- k = write_string_file(p, value);
- if (k < 0) {
- log_full(k == -ENOENT ? LOG_DEBUG : LOG_WARNING,
- "Failed to write '%s' to '%s': %s", value, p, strerror(-k));
-
- if (k != -ENOENT && r == 0)
- r = k;
- }
-
- return r;
-}