2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2010-11-18 21:52:26 +01:00
|
|
|
|
|
|
|
#include <errno.h>
|
2011-07-12 03:36:17 +02:00
|
|
|
#include <getopt.h>
|
2015-09-23 03:01:06 +02:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2019-03-27 11:32:41 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2010-11-18 21:52:26 +01:00
|
|
|
|
2012-05-07 18:55:45 +02:00
|
|
|
#include "conf-files.h"
|
2015-11-03 12:26:12 +01:00
|
|
|
#include "def.h"
|
2020-01-16 14:45:28 +01:00
|
|
|
#include "errno-util.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "fd-util.h"
|
2013-02-14 12:26:13 +01:00
|
|
|
#include "fileio.h"
|
2020-01-16 19:38:21 +01:00
|
|
|
#include "glob-util.h"
|
2015-09-23 03:01:06 +02:00
|
|
|
#include "hashmap.h"
|
|
|
|
#include "log.h"
|
2018-11-20 11:28:19 +01:00
|
|
|
#include "main-func.h"
|
2018-06-12 15:37:53 +02:00
|
|
|
#include "pager.h"
|
2015-09-23 03:01:06 +02:00
|
|
|
#include "path-util.h"
|
2018-11-20 15:42:57 +01:00
|
|
|
#include "pretty-print.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
2015-09-23 03:01:06 +02:00
|
|
|
#include "strv.h"
|
2015-03-11 10:37:45 +01:00
|
|
|
#include "sysctl-util.h"
|
2010-11-18 21:52:26 +01:00
|
|
|
|
2013-02-11 23:48:36 +01:00
|
|
|
static char **arg_prefixes = NULL;
|
2018-04-26 21:08:53 +02:00
|
|
|
static bool arg_cat_config = false;
|
2018-11-11 12:56:29 +01:00
|
|
|
static PagerFlags arg_pager_flags = 0;
|
2010-11-18 21:52:26 +01:00
|
|
|
|
2018-11-20 11:29:54 +01:00
|
|
|
STATIC_DESTRUCTOR_REGISTER(arg_prefixes, strv_freep);
|
|
|
|
|
2019-07-26 09:17:01 +02:00
|
|
|
typedef struct Option {
|
|
|
|
char *key;
|
|
|
|
char *value;
|
|
|
|
bool ignore_failure;
|
|
|
|
} Option;
|
|
|
|
|
|
|
|
static Option *option_free(Option *o) {
|
|
|
|
if (!o)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
free(o->key);
|
|
|
|
free(o->value);
|
|
|
|
|
|
|
|
return mfree(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(Option*, option_free);
|
|
|
|
DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(option_hash_ops, char, string_hash_func, string_compare_func, Option, option_free);
|
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
static bool test_prefix(const char *p) {
|
|
|
|
char **i;
|
|
|
|
|
|
|
|
if (strv_isempty(arg_prefixes))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
STRV_FOREACH(i, arg_prefixes) {
|
|
|
|
const char *t;
|
|
|
|
|
|
|
|
t = path_startswith(*i, "/proc/sys/");
|
|
|
|
if (!t)
|
|
|
|
t = *i;
|
|
|
|
|
|
|
|
if (path_startswith(p, t))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-26 09:17:01 +02:00
|
|
|
static Option *option_new(
|
|
|
|
const char *key,
|
|
|
|
const char *value,
|
|
|
|
bool ignore_failure) {
|
|
|
|
|
|
|
|
_cleanup_(option_freep) Option *o = NULL;
|
|
|
|
|
|
|
|
assert(key);
|
|
|
|
|
|
|
|
o = new(Option, 1);
|
|
|
|
if (!o)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*o = (Option) {
|
|
|
|
.key = strdup(key),
|
2020-01-16 19:38:21 +01:00
|
|
|
.value = value ? strdup(value) : NULL,
|
2019-07-26 09:17:01 +02:00
|
|
|
.ignore_failure = ignore_failure,
|
|
|
|
};
|
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
if (!o->key)
|
|
|
|
return NULL;
|
|
|
|
if (value && !o->value)
|
2019-07-26 09:17:01 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return TAKE_PTR(o);
|
|
|
|
}
|
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
static int sysctl_write_or_warn(const char *key, const char *value, bool ignore_failure) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = sysctl_write(key, value);
|
|
|
|
if (r < 0) {
|
|
|
|
/* If the sysctl is not available in the kernel or we are running with reduced privileges and
|
|
|
|
* cannot write it, then log about the issue, and proceed without failing. (EROFS is treated
|
|
|
|
* as a permission problem here, since that's how container managers usually protected their
|
|
|
|
* sysctls.) In all other cases log an error and make the tool fail. */
|
|
|
|
if (ignore_failure || r == -EROFS || ERRNO_IS_PRIVILEGE(r))
|
|
|
|
log_debug_errno(r, "Couldn't write '%s' to '%s', ignoring: %m", value, key);
|
|
|
|
else if (r == -ENOENT)
|
|
|
|
log_info_errno(r, "Couldn't write '%s' to '%s', ignoring: %m", value, key);
|
|
|
|
else
|
|
|
|
return log_error_errno(r, "Couldn't write '%s' to '%s': %m", value, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-24 14:56:07 +02:00
|
|
|
static int apply_all(OrderedHashmap *sysctl_options) {
|
2019-07-26 09:17:01 +02:00
|
|
|
Option *option;
|
2015-04-24 19:55:16 +02:00
|
|
|
int r = 0;
|
2013-02-11 23:48:36 +01:00
|
|
|
|
2020-09-08 11:58:29 +02:00
|
|
|
ORDERED_HASHMAP_FOREACH(option, sysctl_options) {
|
2012-08-03 16:20:31 +02:00
|
|
|
int k;
|
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
/* Ignore "negative match" options, they are there only to exclude stuff from globs. */
|
|
|
|
if (!option->value)
|
|
|
|
continue;
|
2015-04-24 19:55:16 +02:00
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
if (string_is_glob(option->key)) {
|
|
|
|
_cleanup_strv_free_ char **paths = NULL;
|
|
|
|
_cleanup_free_ char *pattern = NULL;
|
|
|
|
char **s;
|
2012-08-03 16:20:31 +02:00
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
pattern = path_join("/proc/sys", option->key);
|
|
|
|
if (!pattern)
|
|
|
|
return log_oom();
|
2016-10-25 09:25:21 +02:00
|
|
|
|
2020-05-12 23:36:27 +02:00
|
|
|
k = glob_extend(&paths, pattern, GLOB_NOCHECK);
|
2020-01-16 19:38:21 +01:00
|
|
|
if (k < 0) {
|
2020-05-12 23:43:48 +02:00
|
|
|
if (option->ignore_failure || ERRNO_IS_PRIVILEGE(k))
|
2020-01-16 19:38:21 +01:00
|
|
|
log_debug_errno(k, "Failed to resolve glob '%s', ignoring: %m",
|
|
|
|
option->key);
|
|
|
|
else {
|
|
|
|
log_error_errno(k, "Couldn't resolve glob '%s': %m",
|
|
|
|
option->key);
|
|
|
|
if (r == 0)
|
|
|
|
r = k;
|
|
|
|
}
|
2016-10-25 09:25:21 +02:00
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
} else if (strv_isempty(paths))
|
|
|
|
log_debug("No match for glob: %s", option->key);
|
2016-10-25 09:25:21 +02:00
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
STRV_FOREACH(s, paths) {
|
|
|
|
const char *key;
|
|
|
|
|
|
|
|
assert_se(key = path_startswith(*s, "/proc/sys"));
|
|
|
|
|
|
|
|
if (!test_prefix(key))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ordered_hashmap_contains(sysctl_options, key)) {
|
|
|
|
log_info("Not setting %s (explicit setting exists).", key);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
k = sysctl_write_or_warn(key, option->value, option->ignore_failure);
|
|
|
|
if (r == 0)
|
|
|
|
r = k;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
k = sysctl_write_or_warn(option->key, option->value, option->ignore_failure);
|
|
|
|
if (r == 0)
|
|
|
|
r = k;
|
|
|
|
}
|
2016-10-25 09:25:21 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
return r;
|
2016-10-25 09:25:21 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 13:05:32 +01:00
|
|
|
static int parse_file(OrderedHashmap **sysctl_options, const char *path, bool ignore_enoent) {
|
2013-02-11 23:48:36 +01:00
|
|
|
_cleanup_fclose_ FILE *f = NULL;
|
2016-10-25 09:26:10 +02:00
|
|
|
unsigned c = 0;
|
2013-02-11 23:48:36 +01:00
|
|
|
int r;
|
2010-11-18 21:52:26 +01:00
|
|
|
|
|
|
|
assert(path);
|
|
|
|
|
2018-04-27 18:20:17 +02:00
|
|
|
r = search_and_fopen(path, "re", NULL, (const char**) CONF_PATHS_STRV("sysctl.d"), &f);
|
2013-02-11 23:48:36 +01:00
|
|
|
if (r < 0) {
|
2013-03-27 13:41:59 +01:00
|
|
|
if (ignore_enoent && r == -ENOENT)
|
2011-03-03 22:17:09 +01:00
|
|
|
return 0;
|
|
|
|
|
2014-11-28 19:13:53 +01:00
|
|
|
return log_error_errno(r, "Failed to open file '%s', ignoring: %m", path);
|
2010-11-18 21:52:26 +01:00
|
|
|
}
|
|
|
|
|
2015-03-15 03:56:01 +01:00
|
|
|
log_debug("Parsing %s", path);
|
2016-10-25 09:26:31 +02:00
|
|
|
for (;;) {
|
2019-07-26 09:17:01 +02:00
|
|
|
_cleanup_(option_freep) Option *new_option = NULL;
|
2017-12-12 16:43:17 +01:00
|
|
|
_cleanup_free_ char *l = NULL;
|
2020-01-16 19:38:21 +01:00
|
|
|
bool ignore_failure = false;
|
2019-07-26 09:17:01 +02:00
|
|
|
Option *existing;
|
|
|
|
char *p, *value;
|
2013-02-11 23:48:36 +01:00
|
|
|
int k;
|
2018-02-08 18:58:35 +01:00
|
|
|
|
2017-12-12 16:43:17 +01:00
|
|
|
k = read_line(f, LONG_LINE_MAX, &l);
|
|
|
|
if (k == 0)
|
|
|
|
break;
|
|
|
|
if (k < 0)
|
|
|
|
return log_error_errno(k, "Failed to read file '%s', ignoring: %m", path);
|
2010-11-18 21:52:26 +01:00
|
|
|
|
2016-10-25 09:26:10 +02:00
|
|
|
c++;
|
|
|
|
|
2010-11-18 21:52:26 +01:00
|
|
|
p = strstrip(l);
|
|
|
|
|
2018-02-08 18:58:35 +01:00
|
|
|
if (isempty(p))
|
|
|
|
continue;
|
2013-04-14 02:22:53 +02:00
|
|
|
if (strchr(COMMENTS "\n", *p))
|
2010-11-18 21:52:26 +01:00
|
|
|
continue;
|
|
|
|
|
2012-08-03 16:20:31 +02:00
|
|
|
value = strchr(p, '=');
|
2020-01-16 19:38:21 +01:00
|
|
|
if (value) {
|
|
|
|
if (p[0] == '-') {
|
|
|
|
ignore_failure = true;
|
|
|
|
p++;
|
|
|
|
}
|
2010-11-18 21:52:26 +01:00
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
*value = 0;
|
|
|
|
value++;
|
|
|
|
value = strstrip(value);
|
2010-11-18 21:52:26 +01:00
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
} else {
|
|
|
|
if (p[0] == '-')
|
|
|
|
/* We have a "negative match" option. Let's continue with value==NULL. */
|
|
|
|
p++;
|
|
|
|
else {
|
|
|
|
log_syntax(NULL, LOG_WARNING, path, c, 0,
|
|
|
|
"Line is not an assignment, ignoring: %s", p);
|
|
|
|
if (r == 0)
|
|
|
|
r = -EINVAL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2019-07-26 09:17:01 +02:00
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
p = strstrip(p);
|
2019-07-26 09:17:01 +02:00
|
|
|
p = sysctl_normalize(p);
|
2013-02-11 23:48:36 +01:00
|
|
|
|
2020-01-16 19:38:21 +01:00
|
|
|
/* We can't filter out globs at this point, we'll need to do that later. */
|
|
|
|
if (!string_is_glob(p) &&
|
|
|
|
!test_prefix(p))
|
2015-02-07 14:12:41 +01:00
|
|
|
continue;
|
|
|
|
|
2020-01-16 13:05:32 +01:00
|
|
|
if (ordered_hashmap_ensure_allocated(sysctl_options, &option_hash_ops) < 0)
|
|
|
|
return log_oom();
|
|
|
|
|
|
|
|
existing = ordered_hashmap_get(*sysctl_options, p);
|
2013-02-11 23:48:36 +01:00
|
|
|
if (existing) {
|
2020-02-06 11:13:11 +01:00
|
|
|
if (streq_ptr(value, existing->value)) {
|
2019-07-26 09:17:01 +02:00
|
|
|
existing->ignore_failure = existing->ignore_failure || ignore_failure;
|
2013-08-15 18:35:03 +02:00
|
|
|
continue;
|
2019-07-26 09:17:01 +02:00
|
|
|
}
|
2013-02-11 23:48:36 +01:00
|
|
|
|
2016-10-25 09:26:10 +02:00
|
|
|
log_debug("Overwriting earlier assignment of %s at '%s:%u'.", p, path, c);
|
2020-01-16 13:05:32 +01:00
|
|
|
option_free(ordered_hashmap_remove(*sysctl_options, p));
|
2012-08-03 16:20:31 +02:00
|
|
|
}
|
|
|
|
|
2019-07-26 09:17:01 +02:00
|
|
|
new_option = option_new(p, value, ignore_failure);
|
|
|
|
if (!new_option)
|
2013-02-11 23:48:36 +01:00
|
|
|
return log_oom();
|
|
|
|
|
2020-01-16 13:05:32 +01:00
|
|
|
k = ordered_hashmap_put(*sysctl_options, new_option->key, new_option);
|
2019-07-26 09:17:01 +02:00
|
|
|
if (k < 0)
|
|
|
|
return log_error_errno(k, "Failed to add sysctl variable %s to hashmap: %m", p);
|
2012-08-03 16:20:31 +02:00
|
|
|
|
2019-07-26 09:17:01 +02:00
|
|
|
TAKE_PTR(new_option);
|
2010-11-18 21:52:26 +01:00
|
|
|
}
|
|
|
|
|
2011-03-03 22:17:09 +01:00
|
|
|
return r;
|
2010-11-18 21:52:26 +01:00
|
|
|
}
|
|
|
|
|
2018-08-09 10:32:31 +02:00
|
|
|
static int help(void) {
|
|
|
|
_cleanup_free_ char *link = NULL;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = terminal_urlify_man("systemd-sysctl.service", "8", &link);
|
|
|
|
if (r < 0)
|
|
|
|
return log_oom();
|
|
|
|
|
2011-07-12 03:36:17 +02:00
|
|
|
printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
|
|
|
|
"Applies kernel sysctl settings.\n\n"
|
|
|
|
" -h --help Show this help\n"
|
2013-11-06 18:28:39 +01:00
|
|
|
" --version Show package version\n"
|
2018-04-26 21:08:53 +02:00
|
|
|
" --cat-config Show configuration files\n"
|
2014-09-17 09:06:49 +02:00
|
|
|
" --prefix=PATH Only apply rules with the specified prefix\n"
|
2018-06-12 15:37:53 +02:00
|
|
|
" --no-pager Do not pipe output into a pager\n"
|
2018-08-09 10:32:31 +02:00
|
|
|
"\nSee the %s for details.\n"
|
|
|
|
, program_invocation_short_name
|
|
|
|
, link
|
|
|
|
);
|
|
|
|
|
|
|
|
return 0;
|
2011-07-12 03:36:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_argv(int argc, char *argv[]) {
|
|
|
|
|
|
|
|
enum {
|
2013-11-06 18:28:39 +01:00
|
|
|
ARG_VERSION = 0x100,
|
2018-04-26 21:08:53 +02:00
|
|
|
ARG_CAT_CONFIG,
|
|
|
|
ARG_PREFIX,
|
2018-06-12 15:37:53 +02:00
|
|
|
ARG_NO_PAGER,
|
2011-07-12 03:36:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct option options[] = {
|
2018-04-26 21:08:53 +02:00
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "version", no_argument, NULL, ARG_VERSION },
|
|
|
|
{ "cat-config", no_argument, NULL, ARG_CAT_CONFIG },
|
|
|
|
{ "prefix", required_argument, NULL, ARG_PREFIX },
|
2018-06-12 15:37:53 +02:00
|
|
|
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
|
2013-11-06 18:28:39 +01:00
|
|
|
{}
|
2011-07-12 03:36:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
assert(argc >= 0);
|
|
|
|
assert(argv);
|
|
|
|
|
2014-08-02 17:12:21 +02:00
|
|
|
while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
|
2011-07-12 03:36:17 +02:00
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
|
|
|
|
case 'h':
|
2018-08-09 10:32:31 +02:00
|
|
|
return help();
|
2013-11-06 18:28:39 +01:00
|
|
|
|
|
|
|
case ARG_VERSION:
|
2015-09-23 03:01:06 +02:00
|
|
|
return version();
|
2011-07-12 03:36:17 +02:00
|
|
|
|
2018-04-26 21:08:53 +02:00
|
|
|
case ARG_CAT_CONFIG:
|
|
|
|
arg_cat_config = true;
|
|
|
|
break;
|
|
|
|
|
2011-07-12 03:36:17 +02:00
|
|
|
case ARG_PREFIX: {
|
|
|
|
char *p;
|
|
|
|
|
2014-09-17 09:06:49 +02:00
|
|
|
/* We used to require people to specify absolute paths
|
|
|
|
* in /proc/sys in the past. This is kinda useless, but
|
|
|
|
* we need to keep compatibility. We now support any
|
|
|
|
* sysctl name available. */
|
2015-03-11 10:37:45 +01:00
|
|
|
sysctl_normalize(optarg);
|
2015-04-24 19:55:16 +02:00
|
|
|
|
2017-08-09 19:03:39 +02:00
|
|
|
if (path_startswith(optarg, "/proc/sys"))
|
2014-09-17 09:06:49 +02:00
|
|
|
p = strdup(optarg);
|
|
|
|
else
|
2019-07-11 19:14:16 +02:00
|
|
|
p = path_join("/proc/sys", optarg);
|
2014-09-17 09:06:49 +02:00
|
|
|
if (!p)
|
|
|
|
return log_oom();
|
2015-04-24 19:55:16 +02:00
|
|
|
|
2014-09-17 09:06:49 +02:00
|
|
|
if (strv_consume(&arg_prefixes, p) < 0)
|
2012-07-25 23:55:59 +02:00
|
|
|
return log_oom();
|
2011-07-15 02:01:31 +02:00
|
|
|
|
2011-07-12 03:36:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-06-12 15:37:53 +02:00
|
|
|
case ARG_NO_PAGER:
|
2018-11-11 12:56:29 +01:00
|
|
|
arg_pager_flags |= PAGER_DISABLE;
|
2018-06-12 15:37:53 +02:00
|
|
|
break;
|
|
|
|
|
2011-07-12 03:36:17 +02:00
|
|
|
case '?':
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
default:
|
2013-11-06 18:28:39 +01:00
|
|
|
assert_not_reached("Unhandled option");
|
2011-07-12 03:36:17 +02:00
|
|
|
}
|
|
|
|
|
2018-11-20 23:40:44 +01:00
|
|
|
if (arg_cat_config && argc > optind)
|
|
|
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
|
|
|
"Positional arguments are not allowed with --cat-config");
|
2018-04-26 21:08:53 +02:00
|
|
|
|
2011-07-12 03:36:17 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-11-20 11:28:19 +01:00
|
|
|
static int run(int argc, char *argv[]) {
|
2019-07-26 09:17:01 +02:00
|
|
|
_cleanup_(ordered_hashmap_freep) OrderedHashmap *sysctl_options = NULL;
|
2018-11-20 14:03:46 +01:00
|
|
|
int r, k;
|
2010-11-18 21:52:26 +01:00
|
|
|
|
2011-07-12 03:36:17 +02:00
|
|
|
r = parse_argv(argc, argv);
|
|
|
|
if (r <= 0)
|
2018-11-20 14:03:46 +01:00
|
|
|
return r;
|
2011-07-12 03:36:17 +02:00
|
|
|
|
2018-11-20 11:18:22 +01:00
|
|
|
log_setup_service();
|
2010-11-18 21:52:26 +01:00
|
|
|
|
2011-08-01 20:52:18 +02:00
|
|
|
umask(0022);
|
|
|
|
|
2012-03-20 15:31:09 +01:00
|
|
|
if (argc > optind) {
|
|
|
|
int i;
|
|
|
|
|
2019-07-26 09:04:15 +02:00
|
|
|
r = 0;
|
|
|
|
|
2012-03-20 15:31:09 +01:00
|
|
|
for (i = optind; i < argc; i++) {
|
2020-01-16 13:05:32 +01:00
|
|
|
k = parse_file(&sysctl_options, argv[i], false);
|
2013-02-11 23:48:36 +01:00
|
|
|
if (k < 0 && r == 0)
|
2012-03-20 15:31:09 +01:00
|
|
|
r = k;
|
|
|
|
}
|
|
|
|
} else {
|
2013-02-11 23:48:36 +01:00
|
|
|
_cleanup_strv_free_ char **files = NULL;
|
|
|
|
char **f;
|
2011-03-03 22:17:09 +01:00
|
|
|
|
2018-04-27 18:20:17 +02:00
|
|
|
r = conf_files_list_strv(&files, ".conf", NULL, 0, (const char**) CONF_PATHS_STRV("sysctl.d"));
|
2018-11-20 14:03:46 +01:00
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to enumerate sysctl.d files: %m");
|
2011-04-25 20:41:47 +02:00
|
|
|
|
2018-04-26 21:08:53 +02:00
|
|
|
if (arg_cat_config) {
|
2018-11-11 12:56:29 +01:00
|
|
|
(void) pager_open(arg_pager_flags);
|
2018-06-12 15:37:53 +02:00
|
|
|
|
2018-11-20 14:03:46 +01:00
|
|
|
return cat_files(NULL, files, 0);
|
2018-04-26 21:08:53 +02:00
|
|
|
}
|
|
|
|
|
2013-02-11 23:48:36 +01:00
|
|
|
STRV_FOREACH(f, files) {
|
2020-01-16 13:05:32 +01:00
|
|
|
k = parse_file(&sysctl_options, *f, true);
|
2013-02-11 23:48:36 +01:00
|
|
|
if (k < 0 && r == 0)
|
2011-04-25 20:41:47 +02:00
|
|
|
r = k;
|
|
|
|
}
|
2010-11-18 21:52:26 +01:00
|
|
|
}
|
2012-08-03 16:20:31 +02:00
|
|
|
|
2013-02-11 23:48:36 +01:00
|
|
|
k = apply_all(sysctl_options);
|
|
|
|
if (k < 0 && r == 0)
|
2012-09-21 17:01:39 +02:00
|
|
|
r = k;
|
|
|
|
|
2018-11-20 11:28:19 +01:00
|
|
|
return r;
|
2010-11-18 21:52:26 +01:00
|
|
|
}
|
2018-11-20 11:28:19 +01:00
|
|
|
|
|
|
|
DEFINE_MAIN_FUNCTION(run);
|