From e26e41397cad35ba8c49344ab4081f7a727f2672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 29 Apr 2021 23:12:19 +0200 Subject: [PATCH] etc/systemd/zfs-mount-generator: pull in network for keylocation=https: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also removes empty Wants= and After=s from they key-load services, with no ill effect, since we already set DefaultDependencies=no Signed-off-by: Ahelenia ZiemiaƄska Ref: #11956 --- .../system-generators/zfs-mount-generator.c | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/etc/systemd/system-generators/zfs-mount-generator.c b/etc/systemd/system-generators/zfs-mount-generator.c index 1aac5b45b5e2..be0470511d04 100644 --- a/etc/systemd/system-generators/zfs-mount-generator.c +++ b/etc/systemd/system-generators/zfs-mount-generator.c @@ -277,21 +277,23 @@ line_worker(char *line, const char *cachefile) if (strcmp(dataset, p_encroot) == 0) { const char *keymountdep = NULL; bool is_prompt = false; + bool need_network = false; regmatch_t uri_matches[3]; if (regexec(&uri_regex, p_keyloc, nitems(uri_matches), uri_matches, 0) == 0) { + p_keyloc[uri_matches[1].rm_eo] = '\0'; p_keyloc[uri_matches[2].rm_eo] = '\0'; + const char *scheme = + &p_keyloc[uri_matches[1].rm_so]; const char *path = &p_keyloc[uri_matches[2].rm_so]; - /* - * Assumes all URI keylocations need - * the mount for their path; - * http://, for example, wouldn't - * (but it'd need network-online.target et al.) - */ - keymountdep = path; + if (strcmp(scheme, "https") == 0 || + strcmp(scheme, "http") == 0) + need_network = true; + else + keymountdep = path; } else { if (strcmp(p_keyloc, "prompt") != 0) fprintf(stderr, PROGNAME "[%d]: %s: " @@ -320,10 +322,32 @@ line_worker(char *line, const char *cachefile) "Description=Load ZFS key for %s\n" "SourcePath=" FSLIST "/%s\n" "Documentation=man:zfs-mount-generator(8)\n" - "DefaultDependencies=no\n" - "Wants=%s\n" - "After=%s\n", - dataset, cachefile, wants, after); + "DefaultDependencies=no\n", + dataset, cachefile); + + if (wants[0] || need_network) { + fprintf(keyloadunit_f, "Wants="); + if (wants[0]) + fprintf(keyloadunit_f, "%s", wants); + if (wants[0] && need_network) + fprintf(keyloadunit_f, " "); + if (need_network) + fprintf(keyloadunit_f, + "network-online.target"); + fprintf(keyloadunit_f, "\n"); + } + + if (after[0] || need_network) { + fprintf(keyloadunit_f, "After="); + if (after[0]) + fprintf(keyloadunit_f, "%s", after); + if (after[0] && need_network) + fprintf(keyloadunit_f, " "); + if (need_network) + fprintf(keyloadunit_f, + "network-online.target"); + fprintf(keyloadunit_f, "\n"); + } if (p_systemd_requires) fprintf(keyloadunit_f,