diff mbox series

[8/8] xfs_scrub_all: fix systemd escaping again

Message ID 153841351155.27952.8070566787187802754.stgit@magnolia
State Accepted
Headers show
Series xfsprogs-4.19: transaction cleanups | expand

Commit Message

Darrick J. Wong Oct. 1, 2018, 5:05 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Apparently newer versions of systemd than the one on this author's
laptop <cough> now complain about lack of (path) escaping in unit instance
variable contents:

 # xfs_scrub_all
 Scrubbing /home...
  Invalid unit name "xfs_scrub@/home" was escaped as "xfs_scrub@-home"
 (maybe you should use systemd-escape?)
 Starting Online XFS Metadata Check for /home...

So change the systemd_escape() function to escape paths unconditionally
to make the warning go away.

Reported-by: Matthias Bodenbinder <matthias@bodenbinder.de>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
 scrub/xfs_scrub_all.in |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series


diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in
index f7d9e6c7..c4e9899d 100644
--- a/scrub/xfs_scrub_all.in
+++ b/scrub/xfs_scrub_all.in
@@ -82,11 +82,16 @@  def run_killable(cmd, stdout, killfuncs, kill_fn):
 # 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.
 def systemd_escape(path):
 	'''Escape a path to avoid mangled systemd mangling.'''
-	if '-' not in path:
-		return path
+	if path == '/':
+		return '-'
 	cmd = ['systemd-escape', '--path', path]
 		proc = subprocess.Popen(cmd, stdout = subprocess.PIPE)