Skip to content

Commit

Permalink
etc/systemd/zfs-mount-generator: pull in network for keylocation=https:
Browse files Browse the repository at this point in the history
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 <[email protected]>
Ref: openzfs#11956
  • Loading branch information
nabijaczleweli committed Nov 12, 2021
1 parent 364451f commit 1060996
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions etc/systemd/system-generators/zfs-mount-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand Down Expand Up @@ -325,6 +327,11 @@ line_worker(char *line, const char *cachefile)
"After=%s\n",
dataset, cachefile, wants, after);

if (need_network)
fprintf(keyloadunit_f,
"Wants=network-online.target\n"
"After=network-online.target\n");

if (p_systemd_requires)
fprintf(keyloadunit_f,
"Requires=%s\n", p_systemd_requires);
Expand Down

0 comments on commit 1060996

Please sign in to comment.