1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-09 01:18:19 +03:00

Merge pull request #22956 from yuwata/network-fix-permission-error

network: ignore all errors in loading .network files
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-04-05 08:59:44 +02:00 committed by GitHub
commit 42ac3bf1a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 56 deletions

View File

@ -749,10 +749,8 @@ int netdev_load_one(Manager *manager, const char *filename) {
assert(filename); assert(filename);
r = null_or_empty_path(filename); r = null_or_empty_path(filename);
if (r == -ENOENT)
return 0;
if (r < 0) if (r < 0)
return r; return log_warning_errno(r, "Failed to check if \"%s\" is empty: %m", filename);
if (r > 0) { if (r > 0) {
log_debug("Skipping empty file: %s", filename); log_debug("Skipping empty file: %s", filename);
return 0; return 0;
@ -777,7 +775,7 @@ int netdev_load_one(Manager *manager, const char *filename) {
netdev_raw, netdev_raw,
NULL); NULL);
if (r < 0) if (r < 0)
return r; return r; /* config_parse_many() logs internally. */
/* skip out early if configuration does not match the environment */ /* skip out early if configuration does not match the environment */
if (!condition_test_list(netdev_raw->conditions, environ, NULL, NULL, NULL)) { if (!condition_test_list(netdev_raw->conditions, environ, NULL, NULL, NULL)) {
@ -785,15 +783,11 @@ int netdev_load_one(Manager *manager, const char *filename) {
return 0; return 0;
} }
if (netdev_raw->kind == _NETDEV_KIND_INVALID) { if (netdev_raw->kind == _NETDEV_KIND_INVALID)
log_warning("NetDev has no Kind= configured in %s. Ignoring", filename); return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), "NetDev has no Kind= configured in \"%s\", ignoring.", filename);
return 0;
}
if (!netdev_raw->ifname) { if (!netdev_raw->ifname)
log_warning("NetDev without Name= configured in %s. Ignoring", filename); return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), "NetDev without Name= configured in \"%s\", ignoring.", filename);
return 0;
}
netdev = malloc0(NETDEV_VTABLE(netdev_raw)->object_size); netdev = malloc0(NETDEV_VTABLE(netdev_raw)->object_size);
if (!netdev) if (!netdev)
@ -815,13 +809,13 @@ int netdev_load_one(Manager *manager, const char *filename) {
CONFIG_PARSE_WARN, CONFIG_PARSE_WARN,
netdev, NULL); netdev, NULL);
if (r < 0) if (r < 0)
return r; return r; /* config_parse_many() logs internally. */
/* verify configuration */ /* verify configuration */
if (NETDEV_VTABLE(netdev)->config_verify) { if (NETDEV_VTABLE(netdev)->config_verify) {
r = NETDEV_VTABLE(netdev)->config_verify(netdev, filename); r = NETDEV_VTABLE(netdev)->config_verify(netdev, filename);
if (r < 0) if (r < 0)
return 0; return r; /* config_verify() logs internally. */
} }
netdev->filename = strdup(filename); netdev->filename = strdup(filename);
@ -837,22 +831,21 @@ int netdev_load_one(Manager *manager, const char *filename) {
assert(n); assert(n);
if (!streq(netdev->filename, n->filename)) if (!streq(netdev->filename, n->filename))
log_netdev_warning_errno(netdev, r, log_netdev_warning_errno(netdev, r,
"Device was already configured by file %s, ignoring %s.", "Device was already configured by \"%s\", ignoring %s.",
n->filename, netdev->filename); n->filename, netdev->filename);
/* Clear ifname before netdev_free() is called. Otherwise, the NetDev object 'n' is /* Clear ifname before netdev_free() is called. Otherwise, the NetDev object 'n' is
* removed from the hashmap 'manager->netdevs'. */ * removed from the hashmap 'manager->netdevs'. */
netdev->ifname = mfree(netdev->ifname); netdev->ifname = mfree(netdev->ifname);
return 0; return -EEXIST;
} }
if (r < 0) assert(r > 0);
return r;
log_netdev_debug(netdev, "loaded %s", netdev_kind_to_string(netdev->kind)); log_netdev_debug(netdev, "loaded \"%s\"", netdev_kind_to_string(netdev->kind));
r = netdev_request_to_create(netdev); r = netdev_request_to_create(netdev);
if (r < 0) if (r < 0)
return r; return r; /* netdev_request_to_create() logs internally. */
TAKE_PTR(netdev); TAKE_PTR(netdev);
return 0; return 0;
@ -871,11 +864,8 @@ int netdev_load(Manager *manager, bool reload) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to enumerate netdev files: %m"); return log_error_errno(r, "Failed to enumerate netdev files: %m");
STRV_FOREACH(f, files) { STRV_FOREACH(f, files)
r = netdev_load_one(manager, *f); (void) netdev_load_one(manager, *f);
if (r < 0)
log_error_errno(r, "Failed to load %s, ignoring: %m", *f);
}
return 0; return 0;
} }

View File

@ -313,7 +313,7 @@ int network_verify(Network *network) {
r = network_drop_invalid_addresses(network); r = network_drop_invalid_addresses(network);
if (r < 0) if (r < 0)
return r; return r; /* network_drop_invalid_addresses() logs internally. */
network_drop_invalid_routes(network); network_drop_invalid_routes(network);
network_drop_invalid_nexthops(network); network_drop_invalid_nexthops(network);
network_drop_invalid_bridge_fdb_entries(network); network_drop_invalid_bridge_fdb_entries(network);
@ -327,7 +327,7 @@ int network_verify(Network *network) {
network_drop_invalid_tclass(network); network_drop_invalid_tclass(network);
r = sr_iov_drop_invalid_sections(UINT32_MAX, network->sr_iov_by_section); r = sr_iov_drop_invalid_sections(UINT32_MAX, network->sr_iov_by_section);
if (r < 0) if (r < 0)
return r; return r; /* sr_iov_drop_invalid_sections() logs internally. */
network_drop_invalid_static_leases(network); network_drop_invalid_static_leases(network);
network_adjust_dhcp_server(network); network_adjust_dhcp_server(network);
@ -346,10 +346,8 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
assert(filename); assert(filename);
r = null_or_empty_path(filename); r = null_or_empty_path(filename);
if (r == -ENOENT)
return 0;
if (r < 0) if (r < 0)
return r; return log_warning_errno(r, "Failed to check if \"%s\" is empty: %m", filename);
if (r > 0) { if (r > 0) {
log_debug("Skipping empty file: %s", filename); log_debug("Skipping empty file: %s", filename);
return 0; return 0;
@ -365,7 +363,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
d = strrchr(name, '.'); d = strrchr(name, '.');
if (!d) if (!d)
return -EINVAL; return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid file name: %s", filename);
*d = '\0'; *d = '\0';
@ -552,7 +550,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
network, network,
&network->stats_by_path); &network->stats_by_path);
if (r < 0) if (r < 0)
return r; return r; /* config_parse_many() logs internally. */
r = network_add_ipv4ll_route(network); r = network_add_ipv4ll_route(network);
if (r < 0) if (r < 0)
@ -564,15 +562,12 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
network->filename); network->filename);
r = network_verify(network); r = network_verify(network);
if (r == -ENOMEM)
return r;
if (r < 0) if (r < 0)
/* Ignore .network files that do not match the conditions. */ return r; /* network_verify() logs internally. */
return 0;
r = ordered_hashmap_ensure_put(networks, &string_hash_ops, network->name, network); r = ordered_hashmap_ensure_put(networks, &string_hash_ops, network->name, network);
if (r < 0) if (r < 0)
return r; return log_warning_errno(r, "%s: Failed to store configuration into hashmap: %m", filename);
TAKE_PTR(network); TAKE_PTR(network);
return 0; return 0;
@ -590,11 +585,8 @@ int network_load(Manager *manager, OrderedHashmap **networks) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to enumerate network files: %m"); return log_error_errno(r, "Failed to enumerate network files: %m");
STRV_FOREACH(f, files) { STRV_FOREACH(f, files)
r = network_load_one(manager, networks, *f); (void) network_load_one(manager, networks, *f);
if (r < 0)
return log_error_errno(r, "Failed to load %s: %m", *f);
}
return 0; return 0;
} }

View File

@ -218,10 +218,8 @@ int link_load_one(LinkConfigContext *ctx, const char *filename) {
assert(filename); assert(filename);
r = null_or_empty_path(filename); r = null_or_empty_path(filename);
if (r == -ENOENT)
return 0;
if (r < 0) if (r < 0)
return r; return log_warning_errno(r, "Failed to check if \"%s\" is empty: %m", filename);
if (r > 0) { if (r > 0) {
log_debug("Skipping empty file: %s", filename); log_debug("Skipping empty file: %s", filename);
return 0; return 0;
@ -229,11 +227,11 @@ int link_load_one(LinkConfigContext *ctx, const char *filename) {
name = strdup(filename); name = strdup(filename);
if (!name) if (!name)
return -ENOMEM; return log_oom();
config = new(LinkConfig, 1); config = new(LinkConfig, 1);
if (!config) if (!config)
return -ENOMEM; return log_oom();
*config = (LinkConfig) { *config = (LinkConfig) {
.filename = TAKE_PTR(name), .filename = TAKE_PTR(name),
@ -266,7 +264,7 @@ int link_load_one(LinkConfigContext *ctx, const char *filename) {
config_item_perf_lookup, link_config_gperf_lookup, config_item_perf_lookup, link_config_gperf_lookup,
CONFIG_PARSE_WARN, config, NULL); CONFIG_PARSE_WARN, config, NULL);
if (r < 0) if (r < 0)
return r; return r; /* config_parse_many() logs internally. */
if (net_match_is_empty(&config->match) && !config->conditions) { if (net_match_is_empty(&config->match) && !config->conditions) {
log_warning("%s: No valid settings found in the [Match] section, ignoring file. " log_warning("%s: No valid settings found in the [Match] section, ignoring file. "
@ -288,13 +286,13 @@ int link_load_one(LinkConfigContext *ctx, const char *filename) {
r = link_adjust_wol_options(config); r = link_adjust_wol_options(config);
if (r < 0) if (r < 0)
return r; return r; /* link_adjust_wol_options() logs internally. */
r = sr_iov_drop_invalid_sections(config->sr_iov_num_vfs, config->sr_iov_by_section); r = sr_iov_drop_invalid_sections(config->sr_iov_num_vfs, config->sr_iov_by_section);
if (r < 0) if (r < 0)
return r; return r; /* sr_iov_drop_invalid_sections() logs internally. */
log_debug("Parsed configuration file %s", filename); log_debug("Parsed configuration file \"%s\"", filename);
LIST_PREPEND(configs, ctx->configs, TAKE_PTR(config)); LIST_PREPEND(configs, ctx->configs, TAKE_PTR(config));
return 0; return 0;
@ -340,11 +338,8 @@ int link_config_load(LinkConfigContext *ctx) {
if (r < 0) if (r < 0)
return log_error_errno(r, "failed to enumerate link files: %m"); return log_error_errno(r, "failed to enumerate link files: %m");
STRV_FOREACH_BACKWARDS(f, files) { STRV_FOREACH_BACKWARDS(f, files)
r = link_load_one(ctx, *f); (void) link_load_one(ctx, *f);
if (r < 0)
log_error_errno(r, "Failed to load %s, ignoring: %m", *f);
}
return 0; return 0;
} }