Align dev_unit_name() with systemd's function.
Add more corner cases from systemd's unit_name_from_path_instance() C function. Signed-off-by: Thorsten Behrens <tbehrens@suse.com> Signed-off-by: Thomas Renninger <trenn@suse.de>master
parent
fe273e3901
commit
e3eec4b8a2
|
|
@ -866,18 +866,30 @@ wait_for_mount()
|
|||
} >> "$hookdir/emergency/90-${_name}.sh"
|
||||
}
|
||||
|
||||
# get a systemd-compatible unit name from a path
|
||||
# (mimicks unit_name_from_path_instance())
|
||||
dev_unit_name()
|
||||
{
|
||||
local dev="$1"
|
||||
|
||||
if command -v systemd-escape >/dev/null; then
|
||||
systemd-escape -p "$1"
|
||||
systemd-escape -p "$dev"
|
||||
return
|
||||
fi
|
||||
|
||||
_name="${1%%/}"
|
||||
_name="${_name##/}"
|
||||
_name="$(str_replace "$_name" '-' '\x2d')"
|
||||
_name="$(str_replace "$_name" '/' '-')"
|
||||
echo "$_name"
|
||||
if [ "$dev" = "/" -o -z "$dev" ]; then
|
||||
printf -- "-"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
dev="${1%%/}"
|
||||
dev="${dev##/}"
|
||||
dev="$(str_replace "$dev" '\' '\x5c')"
|
||||
dev="$(str_replace "$dev" '-' '\x2d')"
|
||||
dev=${dev/#\./\\x2e}
|
||||
dev="$(str_replace "$dev" '/' '-')"
|
||||
|
||||
printf -- "%s" "$dev"
|
||||
}
|
||||
|
||||
# wait_for_dev <dev>
|
||||
|
|
|
|||
Loading…
Reference in New Issue