From dc6905b7f7baf5c006c66deb8c86707b19d943cc Mon Sep 17 00:00:00 2001 From: mhio <37205532+mhio@users.noreply.github.com> Date: Sun, 26 Nov 2023 02:52:15 +0000 Subject: [PATCH] pkg/cidata: Terminate user only when the environment changes for #1941 --- pkg/cidata/cidata.TEMPLATE.d/boot/07-etc-environment.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/cidata/cidata.TEMPLATE.d/boot/07-etc-environment.sh b/pkg/cidata/cidata.TEMPLATE.d/boot/07-etc-environment.sh index 4cd8b07cbe50..406e3cb4aed4 100644 --- a/pkg/cidata/cidata.TEMPLATE.d/boot/07-etc-environment.sh +++ b/pkg/cidata/cidata.TEMPLATE.d/boot/07-etc-environment.sh @@ -4,16 +4,19 @@ set -eux # /etc/environment must be written after 04-persistent-data-volume.sh has run to # make sure the changes on a restart are applied to the persisted version. +etc_environment_checksum_pre="nofile" if [ -e /etc/environment ]; then + etc_environment_checksum_pre="$(md5sum /etc/environment||printf 'forcepre')" sed -i '/#LIMA-START/,/#LIMA-END/d' /etc/environment fi cat "${LIMA_CIDATA_MNT}/etc_environment" >>/etc/environment +etc_environment_checksum_post="$(md5sum /etc/environment||printf 'forcepost')" # It is possible that a requirements script has started an ssh session before # /etc/environment was updated, so we need to kill it to make sure it will # restart with the updated environment before "linger" is being enabled. -if command -v loginctl >/dev/null 2>&1; then +if command -v loginctl >/dev/null 2>&1 && [ "${etc_environment_checksum_pre}" != "${etc_environment_checksum_post}" ]; then loginctl terminate-user "${LIMA_CIDATA_USER}" || true fi