@@ -20,6 +20,32 @@ if [ ! -x "${mailer}" ]; then
exit 1
fi
+# systemd doesn't like unit instance names with slashes in them, so it
+# replaces them with dashes when it invokes the service. However, it's not
+# smart enough to convert the dashes to something else, so when it unescapes
+# the instance name to feed to xfs_scrub, it turns all dashes into slashes.
+# "/moo-cow" becomes "-moo-cow" becomes "/moo/cow", which is wrong. systemd
+# actually /can/ escape the dashes correctly if it is told that this is a path
+# (and not a unit name), but it didn't do this prior to January 2017, so fix
+# this for them.
+#
+# systemd path escaping also drops the initial slash so we add that back in so
+# that log messages from the service units preserve the full path and users can
+# look up log messages using full paths. However, for "/" the escaping rules
+# do /not/ drop the initial slash, so we have to special-case that here.
+escape_path() {
+ local arg="$1"
+
+ if [ "${arg}" = "/" ]; then
+ echo "-"
+ exit 0
+ fi
+
+ echo "-$(systemd-escape --path "${mntpoint}")"
+}
+
+mntpoint_esc="$(escape_path "${mntpoint}")"
+
(cat << ENDL
To: $1
From: <xfs_scrub@${hostname}>
@@ -29,4 +55,4 @@ So sorry, the automatic xfs_scrub of ${mntpoint} on ${hostname} failed.
A log of what happened follows:
ENDL
-systemctl status --full --lines 4294967295 "xfs_scrub@${mntpoint}") | "${mailer}" -t -i
+systemctl status --full --lines 4294967295 "xfs_scrub@${mntpoint_esc}") | "${mailer}" -t -i