Make-initrd development discussion
 help / color / mirror / Atom feed
* [make-initrd] [PATCH v1 33/41] fork pipeline: bootchain-loop: primary changes
@ 2021-09-24 15:58 Leonid Krivoshein
  0 siblings, 0 replies; only message in thread
From: Leonid Krivoshein @ 2021-09-24 15:58 UTC (permalink / raw)
  To: make-initrd

---
  .../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




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-24 15:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-24 15:58 [make-initrd] [PATCH v1 33/41] fork pipeline: bootchain-loop: primary changes Leonid Krivoshein

Make-initrd development discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/make-initrd/0 make-initrd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 make-initrd make-initrd/ http://lore.altlinux.org/make-initrd \
		make-initrd@lists.altlinux.org make-initrd@lists.altlinux.ru make-initrd@lists.altlinux.com
	public-inbox-index make-initrd

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.make-initrd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git