From: Darrick J. Wong Date: Wed, 10 Oct 2018 19:35:48 +0000 (-0500) Subject: xfs_scrub_all: fix systemd escaping again X-Git-Tag: v4.19.0-rc1~32 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fxfsprogs-dev.git;a=commitdiff_plain;h=29370436c1d426e51d644f1358dcc04e03791a5a xfs_scrub_all: fix systemd escaping again Apparently newer versions of systemd than the one on this author's laptop 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 Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen Signed-off-by: Eric Sandeen --- diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in index f7d9e6c7b..c4e9899d4 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] try: proc = subprocess.Popen(cmd, stdout = subprocess.PIPE)