Skip to content

Commit 5611bdc

Browse files
nabijaczlewelibehlendorf
authored andcommitted
etc/systemd/zfs-mount-generator: output tweaks
git-diff--w-dirty, but: * zfs-load-key-$DSET.service -> zfs-load-key@$DSET.service * flattened set -eu into other /bin/sh flags * simpler (for 1 2 3 vs while [ counter ]; counter+=1) prompt loop * exec $ZFS where applicable Reviewed-by: Antonio Russo <[email protected]> Reviewed-by: Richard Laager <[email protected]> Reviewed-by: InsanePrawn <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Issue #11915 Closes #11917
1 parent 5a1fb06 commit 5611bdc

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

etc/systemd/system-generators/zfs-mount-generator.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ line_worker(char *line, const char *cachefile)
281281

282282
if (strcmp(p_encroot, "-") != 0) {
283283
char *keyloadunit =
284-
systemd_escape(p_encroot, "zfs-load-key-", ".service");
284+
systemd_escape(p_encroot, "zfs-load-key@", ".service");
285285

286286
if (strcmp(dataset, p_encroot) == 0) {
287287
const char *keymountdep = NULL;
@@ -360,33 +360,27 @@ line_worker(char *line, const char *cachefile)
360360
"# dataset is a parent of the root filesystem.\n"
361361
"StandardOutput=null\n"
362362
"StandardError=null\n"
363-
"ExecStart=/bin/sh -c '"
364-
"set -eu;"
365-
"keystatus=\"$$(" ZFS " get -H -o value keystatus \"%s\")\";"
366-
"[ \"$$keystatus\" = \"unavailable\" ] || exit 0;",
363+
"ExecStart=/bin/sh -euc '"
364+
"[ \"$$(" ZFS " get -H -o value keystatus \"%s\")\" = \"unavailable\" ] || exit 0;",
367365
dataset);
368366
if (is_prompt)
369367
fprintf(keyloadunit_f,
370-
"count=0;"
371-
"while [ $$count -lt 3 ]; do "
368+
"for i in 1 2 3; do "
372369
"systemd-ask-password --id=\"zfs:%s\" \"Enter passphrase for %s:\" |"
373370
"" ZFS " load-key \"%s\" && exit 0;"
374-
"count=$$((count + 1));"
375371
"done;"
376372
"exit 1",
377373
dataset, dataset, dataset);
378374
else
379375
fprintf(keyloadunit_f,
380-
"" ZFS " load-key \"%s\"",
376+
"exec " ZFS " load-key \"%s\"",
381377
dataset);
382378

383379
fprintf(keyloadunit_f,
384380
"'\n"
385-
"ExecStop=/bin/sh -c '"
386-
"set -eu;"
387-
"keystatus=\"$$(" ZFS " get -H -o value keystatus \"%s\")\";"
388-
"[ \"$$keystatus\" = \"available\" ] || exit 0;"
389-
"" ZFS " unload-key \"%s\""
381+
"ExecStop=/bin/sh -euc '"
382+
"[ \"$$(" ZFS " get -H -o value keystatus \"%s\")\" = \"available\" ] || exit 0;"
383+
"exec " ZFS " unload-key \"%s\""
390384
"'\n",
391385
dataset, dataset);
392386
/* END CSTYLED */

0 commit comments

Comments
 (0)