On Sat, 2025-04-26 at 21:25 +0200, Ben Hutchings wrote:
> On Sat, 2025-04-26 at 18:43 +0100, Adam D. Barratt wrote:
> > Control: tags -1 + moreinfo
> > 
> > On Fri, 2025-04-25 at 04:24 +0200, Ben Hutchings wrote:
> > > - Fix regressions to copy_file caused by the previous fixes.
> > > - Fix missing reset drivers when using MODULES=dep to reduce the size
> > >   of the initramfs.
> > 
> > The debdiff seems somewhat dirty:
> > 
> >  
> > initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/usr/bin/unmkinitramfs
> >                           |binary
> >  
> > initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/usr/share/doc/initramfs-tools-bin/changelog.gz
> >  |binary
> >  
> > initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/usr/share/man/man8/unmkinitramfs.8.gz
> >           |binary
> >  initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin.substvars         
> >                              |    3 
> >  initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/DEBIAN/control    
> >                              |   14 +
> >  initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/DEBIAN/md5sums    
> >                              |    4 
> >  
> > initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/usr/share/doc/initramfs-tools-bin/copyright
> >     |   28 ++
> 
> Uh, oops, let me try that again.

And again, with the right distribution.  (Sorry, it has been a long
day.)

Ben.

-- 
Ben Hutchings
[W]e found...that it wasn't as easy to get programs right as we had
thought. I realized that a large part of my life from then on was going
to be spent in finding mistakes in my own programs.
                                                 - Maurice Wilkes, 1949
diff -Nru initramfs-tools-0.142+deb12u1/debian/changelog initramfs-tools-0.142+deb12u3/debian/changelog
--- initramfs-tools-0.142+deb12u1/debian/changelog	2024-08-25 01:14:50.000000000 +0200
+++ initramfs-tools-0.142+deb12u3/debian/changelog	2025-04-26 22:00:24.000000000 +0200
@@ -1,3 +1,22 @@
+initramfs-tools (0.142+deb12u3) bookworm; urgency=medium
+
+  * Re-upload with clean debian directory
+
+ -- Ben Hutchings <b...@debian.org>  Sat, 26 Apr 2025 22:00:24 +0200
+
+initramfs-tools (0.142+deb12u2) bookworm; urgency=medium
+
+  * [37a6e9e] hook-functions: Expand documentation of copy_exec and copy_file
+  * [31c50bc] hook-functions: Restore copy_file's handling of target ending in
+    slash (Closes: #1082647)
+  * [d6d1883] hook-functions: Exclude usr-merge symlinks in copy_file
+    (Closes: #1088959)
+  * [38cf275] autopkgtest: Add tests for copy_file function
+  * [065a03f] hook-functions: Add reset drivers when MODULES=dep
+    (Closes: #1027458)
+
+ -- Ben Hutchings <b...@debian.org>  Thu, 24 Apr 2025 17:45:07 +0200
+
 initramfs-tools (0.142+deb12u1) bookworm; urgency=medium
 
   [ Ben Hutchings ]
diff -Nru initramfs-tools-0.142+deb12u1/debian/tests/control initramfs-tools-0.142+deb12u3/debian/tests/control
--- initramfs-tools-0.142+deb12u1/debian/tests/control	2024-08-22 20:38:38.000000000 +0200
+++ initramfs-tools-0.142+deb12u3/debian/tests/control	2025-04-24 17:40:53.000000000 +0200
@@ -21,3 +21,7 @@
 Tests: amd64-panic-shell
 Depends: @, qemu-system-x86, linux-image-amd64 | linux-image-generic:amd64, klibc-utils, genext2fs, zstd
 Restrictions: skip-not-installable
+
+Tests: copy-file
+Restrictions: needs-root, breaks-testbed, skip-not-installable, superficial, allow-stderr
+Depends: linux-image-generic, zstd, @
diff -Nru initramfs-tools-0.142+deb12u1/debian/tests/copy-file initramfs-tools-0.142+deb12u3/debian/tests/copy-file
--- initramfs-tools-0.142+deb12u1/debian/tests/copy-file	1970-01-01 01:00:00.000000000 +0100
+++ initramfs-tools-0.142+deb12u3/debian/tests/copy-file	2025-04-24 17:40:53.000000000 +0200
@@ -0,0 +1,95 @@
+#!/bin/sh -e
+
+SUPPORTED_FLAVOURS='alpha-smp amd64 arm64 armmp parisc loong64 m68k powerpc64 powerpc64le riscv64 s390x sparc64-smp generic'
+. debian/tests/test-common
+
+SOURCEDIR=/usr/lib/initramfs-test-copy-file
+
+mkdir -p "${SOURCEDIR}/dir1"
+echo -n 1 >"${SOURCEDIR}/dir1/file1"
+ln -s dir1 "${SOURCEDIR}/dir2"
+echo -n 22 >"${SOURCEDIR}/file2"
+echo -n 333 >"${SOURCEDIR}/file3"
+
+cat >>"${CONFDIR}/initramfs.conf" <<EOF
+MODULES=list
+BUSYBOX=n
+EOF
+
+cat >"${CONFDIR}/hooks/initramfs-test-copy-file" <<EOF
+#!/bin/sh -e
+
+test "\$1" = prereqs && exit
+
+. /usr/share/initramfs-tools/hook-functions
+
+set -x
+
+# Source named via directory symlink should be symlinked (#1076539)
+copy_file test "${SOURCEDIR}/dir1/file1"
+copy_file test "${SOURCEDIR}/dir2/file1"
+
+# Usr-merged target must be recognised with or without leading slash
+# (#1079276)
+copy_file test "${SOURCEDIR#/usr}/file3" "${SOURCEDIR#/usr/}/file3"
+
+# Target that exists as directory must be treated as directory
+mkdir "\${DESTDIR}/${SOURCEDIR}/dir3"
+copy_file test "${SOURCEDIR}/file2" "${SOURCEDIR}/dir3"
+
+# Target with trailing slash must be treated as directory (#1082647)
+copy_file test "${SOURCEDIR}/file2" "${SOURCEDIR}/dir4/"
+
+# Check combination of #1079276 and #1082647 cases
+copy_file test "${SOURCEDIR#/usr}/file3" "${SOURCEDIR#/usr/}/dir5/"
+EOF
+chmod +x "${CONFDIR}/hooks/initramfs-test-copy-file"
+
+build_initramfs
+lsinitramfs -l "${INITRAMFS}" >"${AUTOPKGTEST_TMP}/listing"
+
+rc=0
+
+check_file() {
+	local ftype="$1"
+	local name="$2"
+	local extra="$3"
+	local size_re='[0-9]*'
+	local tail_re=''
+
+	case "$ftype" in
+	-)
+		# Regular file: extra is size
+		size_re="${extra}"
+		;;
+	l)
+		# Symbolic link: extra is link text
+		size_re="${#extra}"
+		tail_re=" -> $(printf %s "$extra" | sed 's/\./\\./g')"
+		;;
+	esac
+
+	if ! grep -q "^${ftype}......... *[0-9]* root *root *${size_re} ............ ${name#/}${tail_re}$" "${AUTOPKGTEST_TMP}/listing"; then
+		echo >&2 "E: $name did not get copied correctly"
+		rc=1
+	fi
+}
+
+# Check that files, directories, and symlinks were created as expected
+check_file d ${SOURCEDIR}/dir1       -
+check_file - ${SOURCEDIR}/dir1/file1 1
+check_file d ${SOURCEDIR}/dir2       -
+check_file l ${SOURCEDIR}/dir2/file1 ../dir1/file1
+check_file - ${SOURCEDIR}/file3      3
+check_file d ${SOURCEDIR}/dir3       -
+check_file - ${SOURCEDIR}/dir3/file2 2
+check_file d ${SOURCEDIR}/dir4       -
+check_file - ${SOURCEDIR}/dir4/file2 2
+check_file - ${SOURCEDIR}/dir5/file3 3
+
+if [ $rc -ne 0 ]; then
+	echo "I: Initramfs contents:"
+	cat "$AUTOPKGTEST_TMP/listing"
+fi
+
+exit $rc
diff -Nru initramfs-tools-0.142+deb12u1/debian/tests/test-common initramfs-tools-0.142+deb12u3/debian/tests/test-common
--- initramfs-tools-0.142+deb12u1/debian/tests/test-common	2024-08-22 21:30:14.000000000 +0200
+++ initramfs-tools-0.142+deb12u3/debian/tests/test-common	2025-04-24 17:40:53.000000000 +0200
@@ -21,6 +21,7 @@
 CONFDIR="$(mktemp -d)"
 cp conf/initramfs.conf "${CONFDIR}/initramfs.conf"
 echo "RESUME=none" >>"${CONFDIR}/initramfs.conf"
+mkdir "${CONFDIR}/hooks"
 touch "${CONFDIR}/modules"
 mkdir "${CONFDIR}/scripts"
 
diff -Nru initramfs-tools-0.142+deb12u1/hook-functions initramfs-tools-0.142+deb12u3/hook-functions
--- initramfs-tools-0.142+deb12u1/hook-functions	2024-08-22 21:30:14.000000000 +0200
+++ initramfs-tools-0.142+deb12u3/hook-functions	2025-04-24 17:40:56.000000000 +0200
@@ -153,12 +153,28 @@
 	done
 }
 
-# $1 = file type (for logging)
-# $2 = file to copy to initramfs
-# $3 (optional) Name for the file on the initramfs
-# Location of the image dir is assumed to be $DESTDIR
-# If the target exists, we leave it and return 1.
-# On any other error, we return >1.
+# Copy a file to the initramfs:
+# $1 = file type, for debug logging
+# $2 = source file name
+# $3 (optional) = target file or directory name in the initramfs
+#
+# * If the target is not specified, it defaults to the source file
+#   name.
+# * If the target is specified and exists as a directory under
+#   $DESTDIR or ends in a slash, the basename of the source is
+#   appended to it.
+#
+# The target file's containing directories are created if necessary.
+#
+# If the source file name includes a symlink, other than usr-merge
+# symlinks, and the canonical name of the source is not the same as
+# the target, the source file is copied to its canonical name in the
+# initramfs and the target is created as a symlink.
+#
+# Returns:
+# * If the file was copied successfully, 0
+# * If the target file already existed, 1
+# * On error, >1
 copy_file() {
 	local type src target link_target
 
@@ -168,7 +184,7 @@
 
 	[ -f "${src}" ] || return 2
 
-	if [ -d "${DESTDIR}/${target}" ]; then
+	if [ -d "${DESTDIR}/${target}" ] || [ "${target%/}" != "$target" ]; then
 		target="${target}/${src##*/}"
 	fi
 
@@ -176,7 +192,12 @@
 	# will work
 	target="$(realpath -ms "/${target}")" || return 2
 
-	# Canonicalise usr-merged target directories
+	# Canonicalise usr-merged directories
+	case "${src}" in
+	/bin/* | /lib* | /sbin/*)
+		[ "$(readlink -f /bin)" = /usr/bin ] && src="/usr${src}"
+		;;
+	esac
 	case "${target}" in
 	/bin/* | /lib* | /sbin/*) target="/usr${target}" ;;
 	esac
@@ -219,10 +240,16 @@
 	cp -pP "${src}" "${DESTDIR}/${target}" || return $(($? + 1))
 }
 
-# $1 = executable/shared library to copy to initramfs, with dependencies
-# $2 (optional) Name for the file on the initramfs
-# Location of the image dir is assumed to be $DESTDIR
-# We never overwrite the target if it exists.
+# Copy an executable or shared library to the initramfs:
+# $1 = source file name
+# $2 (optional) = target file or directory name in the initramfs
+#
+# The source and all its shared library dependencies are copied
+# using copy_file.
+#
+# Returns:
+# * If the files were copied successfully or already exited, 0
+# * On error, >0
 copy_exec() {
 	local src target x nonoptlib ret
 
@@ -528,11 +555,12 @@
 		class_add_modules "$class"
 	done
 
-	# clk, USB-PHY and pinctrl devices are outside the device model (!) so
-	# match loaded modules by name
+	# clk, USB-PHY, pinctrl and reset devices are outside the device
+	# model (!) so match loaded modules by name
 	add_loaded_modules 'clk[-_]*'
 	add_loaded_modules 'phy[-_]*'
 	add_loaded_modules 'pinctrl[-_]*'
+	add_loaded_modules 'reset[-_]*'
 
 	# Sys walk keyboards.  We identify keyboards as input devices
 	# that can generate at least key events 1-31; udev has the

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to