diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-10-08 16:30:08 +0200 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2026-10-08 16:30:08 +0200 |
| commit | 7f4e17413c44c65a759e0be380f3fe60b01b754d (patch) | |
| tree | 886a17cf25420806e3e775e65f561702524c3f01 /src | |
| parent | 1ac0219e62c7b0efee9e81e7266558dffc7b14e6 (diff) | |
| download | vyos-1x-7f4e17413c44c65a759e0be380f3fe60b01b754d.tar.gz vyos-1x-7f4e17413c44c65a759e0be380f3fe60b01b754d.zip | |
vyos-router: T9447: stop copying a directory when restoring the bootup hooks
A boot whose configuration directory carries no pre/post-config hook scripts
copies them out of the running image. That copy named the image root twice,
because the image's squashfs is mounted at two paths and the variable holding
it kept both. One extra operand reached cp as a bare directory:
cp: -r not specified; omitting directory '/run/live/rootfs/<image>.squashfs'
The hook itself still landed, so nothing broke, but the copy reported failure
and was one word-split away from restoring the wrong file. It shows up where
the encrypted configuration volume stays shut, leaving the directory beneath
it empty.
The image root is now a single path, the two identical restore paths share one
implementation, and a copy that fails is logged rather than passing silently.
A missing hook is not escalated - on a first boot that would hand the system to
the upgrade-failure rollback.
Diffstat (limited to 'src')
| -rw-r--r-- | src/etc/default/vyatta | 5 | ||||
| -rwxr-xr-x | src/init/vyos-router | 43 |
2 files changed, 23 insertions, 25 deletions
diff --git a/src/etc/default/vyatta b/src/etc/default/vyatta index 0a5129e8b..6c73269af 100644 --- a/src/etc/default/vyatta +++ b/src/etc/default/vyatta @@ -195,7 +195,10 @@ unset _vyatta_extglob declare -x -r vyos_persistence_dir="/usr/lib/live/mount/persistence/${UNION_NAME}" fi if test -z "$vyos_rootfs_dir" ; then - ROOTFS=$(mount -t squashfs | grep loop0 | cut -d' ' -f3) + # the running image's squashfs is mounted twice, under /run/live and + # under the legacy /usr/lib/live/mount tree, and both match - take one + # or unquoted uses of this variable split into two words + ROOTFS=$(mount -t squashfs | grep loop0 | cut -d' ' -f3 | head -n1) declare -x -r vyos_rootfs_dir="${ROOTFS}" fi if test -z "$VRF" ; then diff --git a/src/init/vyos-router b/src/init/vyos-router index 8e270602e..f109b95da 100755 --- a/src/init/vyos-router +++ b/src/init/vyos-router @@ -227,17 +227,25 @@ load_bootfile () return 0 } -# restore if missing pre-config script -restore_if_missing_preconfig_script () +# restore a bootup script from the image if the config volume has none +restore_if_missing_bootup_script () { - if [ ! -x ${vyatta_sysconfdir}/config/scripts/vyos-preconfig-bootup.script ]; then - mkdir -p ${vyatta_sysconfdir}/config/scripts - chgrp ${GROUP} ${vyatta_sysconfdir}/config/scripts - chmod 775 ${vyatta_sysconfdir}/config/scripts - cp ${vyos_rootfs_dir}/opt/vyatta/etc/config/scripts/vyos-preconfig-bootup.script ${vyatta_sysconfdir}/config/scripts/ - chgrp ${GROUP} ${vyatta_sysconfdir}/config/scripts/vyos-preconfig-bootup.script - chmod 750 ${vyatta_sysconfdir}/config/scripts/vyos-preconfig-bootup.script + local script=vyos-${1}config-bootup.script + local dir=${vyatta_sysconfdir}/config/scripts + + [ -x "${dir}/${script}" ] && return 0 + + mkdir -p "${dir}" + chgrp ${GROUP} "${dir}" + chmod 775 "${dir}" + # quoted, so a rootfs path that is empty or not a single word fails here + # instead of copying whatever the words happen to name + if ! cp "${vyos_rootfs_dir}/opt/vyatta/etc/config/scripts/${script}" "${dir}/"; then + log_failure_msg "could not restore ${script}" + return 1 fi + chgrp ${GROUP} "${dir}/${script}" + chmod 750 "${dir}/${script}" } # execute the pre-config script @@ -248,19 +256,6 @@ run_preconfig_script () fi } -# restore if missing post-config script -restore_if_missing_postconfig_script () -{ - if [ ! -x ${vyatta_sysconfdir}/config/scripts/vyos-postconfig-bootup.script ]; then - mkdir -p ${vyatta_sysconfdir}/config/scripts - chgrp ${GROUP} ${vyatta_sysconfdir}/config/scripts - chmod 775 ${vyatta_sysconfdir}/config/scripts - cp ${vyos_rootfs_dir}/opt/vyatta/etc/config/scripts/vyos-postconfig-bootup.script ${vyatta_sysconfdir}/config/scripts/ - chgrp ${GROUP} ${vyatta_sysconfdir}/config/scripts/vyos-postconfig-bootup.script - chmod 750 ${vyatta_sysconfdir}/config/scripts/vyos-postconfig-bootup.script - fi -} - # execute the post-config scripts run_postconfig_scripts () { @@ -637,7 +632,7 @@ start () # resolved against it before anything below applies interface config. systemctl start vyos-net-name-resolve.service || overall_status=1 - restore_if_missing_preconfig_script + restore_if_missing_bootup_script pre run_preconfig_script @@ -707,7 +702,7 @@ start () telinit q chmod g-w,o-w / - restore_if_missing_postconfig_script + restore_if_missing_bootup_script post run_postconfig_scripts tmp=$(${vyos_libexec_dir}/read-saved-value.py --path "protocols rpki cache") |
