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
Also simplify RequiresMountsFor= handling

Ref: openzfs#11956
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
  • Loading branch information
nabijaczleweli committed Nov 30, 2021
1 parent 364451f commit 449c714
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 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,20 +327,22 @@ 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);

if (p_systemd_requiresmountsfor || keymountdep) {
fprintf(keyloadunit_f, "RequiresMountsFor=");
if (p_systemd_requiresmountsfor)
fprintf(keyloadunit_f,
"%s ", p_systemd_requiresmountsfor);
if (keymountdep)
fprintf(keyloadunit_f,
"'%s'", keymountdep);
fprintf(keyloadunit_f, "\n");
}
if (p_systemd_requiresmountsfor)
fprintf(keyloadunit_f,
"RequiresMountsFor=%s\n",
p_systemd_requiresmountsfor);
if (keymountdep)
fprintf(keyloadunit_f,
"RequiresMountsFor='%s'\n", keymountdep);

/* BEGIN CSTYLED */
fprintf(keyloadunit_f,
Expand Down

0 comments on commit 449c714

Please sign in to comment.