[CRIU] [PATCH] scripts: use absolute binaries paths systemd-autofs-restart.sh

Stanislav Kinsburskiy skinsbursky at virtuozzo.com
Fri Jun 2 18:45:10 MSK 2017


That's the way to support multiple distributions, including those without
$PATH variable being set.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
 scripts/systemd-autofs-restart.sh |   28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/scripts/systemd-autofs-restart.sh b/scripts/systemd-autofs-restart.sh
index 23a016c..2f2d2ca 100755
--- a/scripts/systemd-autofs-restart.sh
+++ b/scripts/systemd-autofs-restart.sh
@@ -36,8 +36,16 @@ fi
 
 JOIN_CT="$NS_ENTER -t $CRTOOLS_INIT_PID -m -u -p"
 
+BASENAME=/usr/bin/basename
+READLINK=/bin/readlink
+UMOUNT=/bin/umount
+MOUNT=/bin/mount
+RM=/bin/rm
+SYSTEMCTL=/bin/systemctl
+MKTEMP=/bin/mktemp
+
 # Skip container, if it's not systemd based
-[ "$($JOIN_CT basename -- $($JOIN_CT readlink /proc/1/exe))" == "systemd" ] || exit 0
+[ "$($JOIN_CT $BASENAME -- $($JOIN_CT $READLINK /proc/1/exe))" == "systemd" ] || exit 0
 
 AUTOFS_SERVICES="proc-sys-fs-binfmt_misc.automount"
 
@@ -45,8 +53,8 @@ bindmount=""
 
 function remove_bindmount {
 	if [ -n "$bindmount" ]; then
-		$JOIN_CT umount $bindmount
-		$JOIN_CT rm -rf $bindmount
+		$JOIN_CT $UMOUNT $bindmount
+		$JOIN_CT $RM -rf $bindmount
 		bindmount=""
 	fi
 }
@@ -86,7 +94,7 @@ function bind_mount {
 	local from=$1
 	local to=$2
 
-	$JOIN_CT mount --bind $from $to && return 0
+	$JOIN_CT $MOUNT --bind $from $to && return 0
 
 	echo "Failed to bind mount $from to $to"
 	return 1
@@ -105,7 +113,7 @@ function save_mountpoint {
 	# Nothing to do, if no file system is on top of autofs
 	[ "$top_mount_fs_type" = "autofs" ] && return
 
-	bindmount=$($JOIN_CT mktemp -d)
+	bindmount=$($JOIN_CT $MKTEMP -d)
 	if [ -z "$bindmount" ]; then
 		echo "Failed to create temporary directory"
 		return 1
@@ -113,7 +121,7 @@ function save_mountpoint {
 
 	# No need to unmount fs on top of autofs:
 	# systemd will does it for us on service restart
-	bind_mount $mountpoint $bindmount || $JOIN_CT rm -rf $bindmount
+	bind_mount $mountpoint $bindmount || $JOIN_CT $RM -rf $bindmount
 }
 
 function restore_mountpoint {
@@ -140,13 +148,13 @@ function restore_mountpoint {
 
 function restart_service {
 	local service=$1
-	local mountpoint=$($JOIN_CT systemctl show $service -p Where | sed 's/.*=//g')
+	local mountpoint=$($JOIN_CT $SYSTEMCTL show $service -p Where | sed 's/.*=//g')
 
 	# Try to move restored bind-mount aside and exit if Failed
 	# Nothing to do, if we Failed
 	save_mountpoint $mountpoint || return
 
-	$JOIN_CT systemctl restart $service
+	$JOIN_CT $SYSTEMCTL restart $service
 	if [ $? -ne 0 ]; then
 		echo "Failed to restart $service service"
 		return
@@ -159,8 +167,8 @@ function restart_service {
 
 function skip_service {
 	local service=$1
-	local status=$($JOIN_CT systemctl is-active $service)
-	local mountpoint=$($JOIN_CT systemctl show $service -p Where | sed 's/.*=//g')
+	local status=$($JOIN_CT $SYSTEMCTL is-active $service)
+	local mountpoint=$($JOIN_CT $SYSTEMCTL show $service -p Where | sed 's/.*=//g')
 	local top_mount_fs_type=""
 
 	if [ $status != "active" ]; then



More information about the CRIU mailing list