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 Jun 9, 2021
1 parent 359d600 commit e26e413
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 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 @@ -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,
Expand Down

0 comments on commit e26e413

Please sign in to comment.