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

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