From 005c7b1d880e641f634534d24a43e2b5db58b476 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 4 Mar 2021 16:38:18 +0900 Subject: [PATCH 1/5] journal: make namespace invocation also support drop-in config --- man/journald.conf.xml | 8 ++++++-- src/journal/journald-server.c | 16 +++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/man/journald.conf.xml b/man/journald.conf.xml index 959815a8f1..86137a951d 100644 --- a/man/journald.conf.xml +++ b/man/journald.conf.xml @@ -28,6 +28,9 @@ /run/systemd/journald.conf.d/*.conf /usr/lib/systemd/journald.conf.d/*.conf /etc/systemd/journald@NAMESPACE.conf + /etc/systemd/journald@NAMESPACE.conf.d/*.conf + /run/systemd/journald@NAMESPACE.conf.d/*.conf + /usr/lib/systemd/journald@NAMESPACE.conf.d/*.conf @@ -41,8 +44,9 @@ The systemd-journald instance managing the default namespace is configured by /etc/systemd/journald.conf and associated drop-ins. Instances managing other - namespaces read /etc/systemd/journald@NAMESPACE.conf with - the namespace identifier filled in. This allows each namespace to carry a distinct configuration. See + namespaces read /etc/systemd/journald@NAMESPACE.conf + and associated drop-ins with the namespace identifier filled in. This allows each namespace to carry + a distinct configuration. See systemd-journald.service8 for details about journal namespaces. diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 5cad374083..372acf3354 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -1625,17 +1625,19 @@ static int server_parse_config_file(Server *s) { assert(s); if (s->namespace) { - const char *namespaced; + const char *namespaced, *dropin_dirname; /* If we are running in namespace mode, load the namespace specific configuration file, and nothing else */ namespaced = strjoina(PKGSYSCONFDIR "/journald@", s->namespace, ".conf"); + dropin_dirname = strjoina("journald@", s->namespace, ".conf.d"); - r = config_parse(NULL, - namespaced, NULL, - "Journal\0", - config_item_perf_lookup, journald_gperf_lookup, - CONFIG_PARSE_WARN, s, - NULL); + r = config_parse_many( + STRV_MAKE_CONST(namespaced), + (const char* const*) CONF_PATHS_STRV("systemd"), + dropin_dirname, + "Journal\0", + config_item_perf_lookup, journald_gperf_lookup, + CONFIG_PARSE_WARN, s, NULL); if (r < 0) return r; From e406e8a29a42d7418188c883f4efea58a0c9727b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 4 Mar 2021 16:48:57 +0900 Subject: [PATCH 2/5] udev/net: make .link files support drop-in config --- man/systemd.link.xml | 42 +++++++++++++++++++++++--------------- src/udev/net/link-config.c | 14 ++++++++----- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/man/systemd.link.xml b/man/systemd.link.xml index 93f7191b33..5918a32189 100644 --- a/man/systemd.link.xml +++ b/man/systemd.link.xml @@ -32,23 +32,31 @@ systemd.syntax7 for a general description of the syntax. - The link files are read from the files located in the system - network directory /usr/lib/systemd/network, - the volatile runtime network directory - /run/systemd/network, and the local - administration network directory - /etc/systemd/network. Link files must have - the extension .link; other extensions are - ignored. All link files are collectively sorted and processed in - lexical order, regardless of the directories in which they live. - However, files with identical filenames replace each other. Files - in /etc/ have the highest priority, files in - /run/ take precedence over files with the same - name in /usr/lib/. This can be used to - override a system-supplied link file with a local file if needed. - As a special case, an empty file (file size 0) or symlink with the - same name pointing to /dev/null disables the - configuration file entirely (it is "masked"). + The link files are read from the files located in the system network directory + /usr/lib/systemd/network, the volatile runtime network directory + /run/systemd/network, and the local administration network directory + /etc/systemd/network. Link files must have the extension + .link; other extensions are ignored. All link files are collectively sorted + and processed in lexical order, regardless of the directories in which they live. However, files + with identical filenames replace each other. Files in /etc/ have the highest + priority, files in /run/ take precedence over files with the same name in + /usr/lib/. This can be used to override a system-supplied link file with a + local file if needed. As a special case, an empty file (file size 0) or symlink with the same name + pointing to /dev/null disables the configuration file entirely (it is + "masked"). + + Along with the link file foo.link, a "drop-in" directory + foo.link.d/ may exist. All files with the suffix .conf + from this directory will be parsed after the file itself is parsed. This is useful to alter or add + configuration settings, without having to modify the main configuration file. Each drop-in file + must have appropriate section headers. + + In addition to /etc/systemd/network, drop-in .d + directories can be placed in /usr/lib/systemd/network or + /run/systemd/network directories. Drop-in files in /etc/ + take precedence over those in /run/ which in turn take precedence over those + in /usr/lib/. Drop-in files under any of these directories take precedence + over the main link file wherever located. The link file contains a [Match] section, which determines if a given link file may be applied to a given device, as well as a [Link] section specifying how the device should be configured. The first (in diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 10d64d5260..79281887e0 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -112,6 +112,7 @@ int link_load_one(link_config_ctx *ctx, const char *filename) { _cleanup_(link_config_freep) link_config *link = NULL; _cleanup_fclose_ FILE *file = NULL; _cleanup_free_ char *name = NULL; + const char *dropin_dirname; size_t i; int r; @@ -151,11 +152,14 @@ int link_load_one(link_config_ctx *ctx, const char *filename) { for (i = 0; i < ELEMENTSOF(link->features); i++) link->features[i] = -1; - r = config_parse(NULL, filename, file, - "Match\0Link\0", - config_item_perf_lookup, link_config_gperf_lookup, - CONFIG_PARSE_WARN, link, - NULL); + dropin_dirname = strjoina(basename(filename), ".d"); + r = config_parse_many( + STRV_MAKE_CONST(filename), + (const char* const*) CONF_PATHS_STRV("systemd/network"), + dropin_dirname, + "Match\0Link\0", + config_item_perf_lookup, link_config_gperf_lookup, + CONFIG_PARSE_WARN, link, NULL); if (r < 0) return r; From e8e2788dab5ddef7f486bfe3d31bf28bd0480ab2 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 4 Mar 2021 17:10:08 +0900 Subject: [PATCH 3/5] udev/net: use null_or_empty_path() --- src/udev/net/link-config.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 79281887e0..f06ecd455d 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -110,7 +110,6 @@ int link_config_ctx_new(link_config_ctx **ret) { int link_load_one(link_config_ctx *ctx, const char *filename) { _cleanup_(link_config_freep) link_config *link = NULL; - _cleanup_fclose_ FILE *file = NULL; _cleanup_free_ char *name = NULL; const char *dropin_dirname; size_t i; @@ -119,11 +118,12 @@ int link_load_one(link_config_ctx *ctx, const char *filename) { assert(ctx); assert(filename); - file = fopen(filename, "re"); - if (!file) - return errno == ENOENT ? 0 : -errno; - - if (null_or_empty_fd(fileno(file))) { + r = null_or_empty_path(filename); + if (r == -ENOENT) + return 0; + if (r < 0) + return r; + if (r > 0) { log_debug("Skipping empty file: %s", filename); return 0; } From 4e54a17dbb64adb182584f7a972c43ed6bf4f6b1 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 4 Mar 2021 17:25:22 +0900 Subject: [PATCH 4/5] network: use null_or_empty_path() This also drops unnecessary fseek(). --- src/network/netdev/netdev.c | 20 ++++++-------------- src/network/networkd-network.c | 16 ++++++---------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index fb03534869..b31f0fa81a 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -656,7 +656,6 @@ int netdev_join(NetDev *netdev, Link *link, link_netlink_message_handler_t callb int netdev_load_one(Manager *manager, const char *filename) { _cleanup_(netdev_unrefp) NetDev *netdev_raw = NULL, *netdev = NULL; - _cleanup_fclose_ FILE *file = NULL; const char *dropin_dirname; bool independent = false; int r; @@ -664,15 +663,12 @@ int netdev_load_one(Manager *manager, const char *filename) { assert(manager); assert(filename); - file = fopen(filename, "re"); - if (!file) { - if (errno == ENOENT) - return 0; - - return -errno; - } - - if (null_or_empty_fd(fileno(file))) { + r = null_or_empty_path(filename); + if (r == -ENOENT) + return 0; + if (r < 0) + return r; + if (r > 0) { log_debug("Skipping empty file: %s", filename); return 0; } @@ -714,10 +710,6 @@ int netdev_load_one(Manager *manager, const char *filename) { return 0; } - r = fseek(file, 0, SEEK_SET); - if (r < 0) - return -errno; - netdev = malloc0(NETDEV_VTABLE(netdev_raw)->object_size); if (!netdev) return log_oom(); diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 9865ebd255..e5ffd35b6f 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -288,7 +288,6 @@ int network_verify(Network *network) { int network_load_one(Manager *manager, OrderedHashmap **networks, const char *filename) { _cleanup_free_ char *fname = NULL, *name = NULL; _cleanup_(network_unrefp) Network *network = NULL; - _cleanup_fclose_ FILE *file = NULL; const char *dropin_dirname; char *d; int r; @@ -296,15 +295,12 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi assert(manager); assert(filename); - file = fopen(filename, "re"); - if (!file) { - if (errno == ENOENT) - return 0; - - return -errno; - } - - if (null_or_empty_fd(fileno(file))) { + r = null_or_empty_path(filename); + if (r == -ENOENT) + return 0; + if (r < 0) + return r; + if (r > 0) { log_debug("Skipping empty file: %s", filename); return 0; } From 0efaa4843edb7eff62c09c9fa7174dbdf2f43da4 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 4 Mar 2021 17:21:22 +0900 Subject: [PATCH 5/5] install: use null_or_empty_path() --- src/shared/install.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/shared/install.c b/src/shared/install.c index 183da5865e..0f18b1bb05 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1335,8 +1335,8 @@ static int unit_file_load_or_readlink( const char *path, const char *root_dir, SearchFlags flags) { + _cleanup_free_ char *resolved = NULL; - struct stat st; int r; r = unit_file_load(c, info, path, root_dir, flags); @@ -1351,9 +1351,7 @@ static int unit_file_load_or_readlink( * so let's see if the path is a (possibly dangling) symlink to /dev/null. */ info->type = UNIT_FILE_TYPE_MASKED; - else if (r > 0 && - stat(resolved, &st) >= 0 && - null_or_empty(&st)) + else if (r > 0 && null_or_empty_path(resolved) > 0) info->type = UNIT_FILE_TYPE_MASKED;