Blame SOURCES/0531-Align-dev_unit_name-with-systemd-s-function.patch

18971c
From 014a78261db67c287d25aafa33266593d816315a Mon Sep 17 00:00:00 2001
18971c
From: Thorsten Behrens <tbehrens@suse.com>
18971c
Date: Thu, 11 Dec 2014 15:46:08 +0100
18971c
Subject: [PATCH] Align dev_unit_name() with systemd's function.
18971c
18971c
Add more corner cases from systemd's
18971c
unit_name_from_path_instance() C function.
18971c
18971c
Signed-off-by: Thorsten Behrens <tbehrens@suse.com>
18971c
Signed-off-by: Thomas Renninger <trenn@suse.de>
18971c
18971c
Cherry-picked from: e3eec4b8
18971c
Resolves: #1306640
18971c
---
18971c
 modules.d/99base/dracut-lib.sh | 24 ++++++++++++++++++------
18971c
 1 file changed, 18 insertions(+), 6 deletions(-)
18971c
18971c
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
18971c
index e04a9b3d..46cee5a9 100755
18971c
--- a/modules.d/99base/dracut-lib.sh
18971c
+++ b/modules.d/99base/dracut-lib.sh
18971c
@@ -868,18 +868,30 @@ wait_for_mount()
18971c
     } >> "$hookdir/emergency/90-${_name}.sh"
18971c
 }
18971c
 
18971c
+# get a systemd-compatible unit name from a path
18971c
+# (mimicks unit_name_from_path_instance())
18971c
 dev_unit_name()
18971c
 {
18971c
+    local dev="$1"
18971c
+
18971c
     if command -v systemd-escape >/dev/null; then
18971c
-        systemd-escape -p  "$1"
18971c
+        systemd-escape -p  "$dev"
18971c
         return
18971c
     fi
18971c
 
18971c
-    _name="${1%%/}"
18971c
-    _name="${_name##/}"
18971c
-    _name="$(str_replace "$_name" '-' '\x2d')"
18971c
-    _name="$(str_replace "$_name" '/' '-')"
18971c
-    echo "$_name"
18971c
+    if [ "$dev" = "/" -o -z "$dev" ]; then
18971c
+        printf -- "-"
18971c
+        exit 0
18971c
+    fi
18971c
+
18971c
+    dev="${1%%/}"
18971c
+    dev="${dev##/}"
18971c
+    dev="$(str_replace "$dev" '\' '\x5c')"
18971c
+    dev="$(str_replace "$dev" '-' '\x2d')"
18971c
+    dev=${dev/#\./\\x2e}
18971c
+    dev="$(str_replace "$dev" '/' '-')"
18971c
+
18971c
+    printf -- "%s" "$dev"
18971c
 }
18971c
 
18971c
 # wait_for_dev <dev>