[make-initrd] [PATCH v1 33/41] fork pipeline: bootchain-loop: primary changes

Leonid Krivoshein klark.devel at gmail.com
Fri Sep 24 18:58:58 MSK 2021


---
  .../bootchain-core/data/sbin/bootchain-loop   | 100 +++++++++++++-----
  1 file changed, 71 insertions(+), 29 deletions(-)

diff --git 
a/make-initrd/features/bootchain-core/data/sbin/bootchain-loop 
b/make-initrd/features/bootchain-core/data/sbin/bootchain-loop
index 0b9fdd3..70a5bf6 100755
--- a/make-initrd/features/bootchain-core/data/sbin/bootchain-loop
+++ b/make-initrd/features/bootchain-core/data/sbin/bootchain-loop
@@ -2,53 +2,95 @@
   . bootchain-sh-functions
  -stepnum=0
+stepnum="${stepnum:-0}"
  chainsteps="${chainsteps-}"
-datadir=
-destdir=
+prevdir="${prevdir-}"
  +
+debug()
+{
+	[ -z "$BC_DEBUG" ] ||
+		message "$*"
+}
+
+
+rc=0
  while [ -n "$chainsteps" ]; do
  	name="${chainsteps%%,*}"
  	exe="$handlerdir/$name"
   	if [ -x "$exe" ]; then
-		eval "callnum=\"\${callnum_$name:-0}\""
-
-		datadir="$mntdir/src/pipe$stepnum"
-		destdir="$mntdir/dst/pipe$stepnum"
+		assign "callnum" "\${callnum_$name:-0}"
+		datadir="$mntdir/src/step$stepnum"
+		destdir="$mntdir/dst/step$stepnum"
  -		[ "$stepnum" != 0 ] ||
-			prevdir=""
+		run mkdir -p -- "$datadir" "$destdir"
  -		mkdir -p -- "$datadir" "$destdir"
-
-		if ! mountpoint -q "$destdir"; then
+		if mountpoint -q -- "$destdir" ||
+			[ -s "$destdir/DEVNAME" ] ||
+			[ -b "$destdir/dev" ] ||
+			[ -c "$destdir/dev" ]
+		then
+			message "[$callnum] Handler: $exe skipped"
+		else
  			message "[$callnum] Handler: $exe"
   			export name callnum datadir destdir prevdir
  -			rc=0
-			"$exe" || rc=$?
-
-			if [ "$rc" != 0 ]; then
-				[ "$rc" != 2 ] ||
+			for try in 1 2 3 4 5; do
+				[ -z "$BC_DEBUG" ] ||
+					run "$handlerdir/debug" ||:
+				rc=0
+				run "$exe" ||
+					rc=$?
+				[ "$rc" != 0 ] ||
  					break
-				message "[$callnum] Handler failed (rc=$rc)"
-				sleep 1
-				continue
-			fi
-		else
-			message "[$callnum] Handler: $exe skipped"
+				[ "$rc" != 2 ] || [ -z "$pipeline_mode" ] ||
+					break 2
+				message "[$callnum] Handler failed (rc=$rc, try=$try)"
+				[ ! -f "$BC_PASSED/$PROG" ] ||
+					break 2
+				sleep 2
+			done
+
+			[ -r "$BC_NEXTCHAIN" ] ||
+				run touch "$BC_PASSED/$name"
+			[ ! -f "$BC_PASSED/$PROG" ] ||
+				break
+			[ "$rc" = 0 ] ||
+				break
  		fi
  -		prevdir="$destdir"
+		if [ ! -r "$BC_NEXTCHAIN" ]; then
+			callnum=$((1 + $callnum))
+			assign "callnum_$name" "\$callnum"
+			eval "export callnum_$name"
+		fi
  -		callnum=$(($callnum + 1))
-		eval "callnum_$name=\"\$callnum\""
+		stepnum=$((1 + $stepnum))
+		prevdir="$(readlink-e "$destdir" 2>/dev/null ||:)"
  	fi
  -	chainsteps="${chainsteps#$name}"
-	chainsteps="${chainsteps#,}"
+	if [ ! -r "$BC_NEXTCHAIN" ]; then
+		chainsteps="${chainsteps#$name}"
+		chainsteps="${chainsteps#,}"
+	else
+		debug "chain will be reloaded by $BC_NEXTCHAIN:"
+		fdump "$BC_NEXTCHAIN"
+		. "$BC_NEXTCHAIN"
+		run rm -f -- "$BC_NEXTCHAIN"
+	fi
  -	stepnum=$(($stepnum + 1))
+	debug "remaining steps: $chainsteps"
  done
+
+[ -z "$chainsteps" ] ||
+	message "remaining steps after breaking loop: $chainsteps"
+
+if [ "$rc" = 2 ] && [ -n "$pipeline_mode" ]; then
+	debug "finishing in pipeline mode"
+elif [ "$rc" = 0 ] && [ -f "$BC_PASSED/$PROG" ]; then
+	debug "finishing in bootchain mode"
+else
+	fatal "daemon terminated incorrectly (rc=$rc)"
+fi
-- 
2.21.0




More information about the Make-initrd mailing list