Skip to content

Commit

Permalink
Fix switching back from console-conf to getty
Browse files Browse the repository at this point in the history
When a password for a user is set, then we should use getty rather
than console-conf. Unit conditions did not work along conflicts,
because conflicts are resolved during loading of systemd, and
conditions are resolved right before executing the unit.

Instead we always use console-conf. If we find that we should have
switched to getty, then we return a special value that is marked as
not restarting (we always restart otherwise). An ExecStopPost also
matches that exit status to start getty (the default job mode is
"replace", which means the conflict will also kick console-conf out).
  • Loading branch information
valentindavid committed Nov 12, 2024
1 parent 639b5ec commit 8e351db
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 13 deletions.
7 changes: 7 additions & 0 deletions bin/console-conf-check-error
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -eu

if [ "${SERVICE_RESULT}" == "exit-code" ] && [ "${EXIT_STATUS}" -eq 22 ]; then
systemctl start --no-block "${1}"
fi
8 changes: 5 additions & 3 deletions bin/console-conf-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ if [ -e /run/snapd-recovery-chooser-triggered ]; then
# when recovery chooser is invoked it takes over the terminal
exec /usr/lib/snapd/snap-recovery-chooser
fi
if [ -e /var/lib/console-conf/complete ]; then
exit 0
fi
fi

if [ -e /var/lib/console-conf/complete ]; then
exit 22
fi

# always prefer to use modeevn if it is available
Expand Down Expand Up @@ -80,6 +81,7 @@ if [ "$(snap managed)" = "true" ]; then
done
else
touch /var/lib/console-conf/complete
exit 22
fi
exit 0
fi
Expand Down
2 changes: 0 additions & 2 deletions debian/console-conf-serial.conf

This file was deleted.

3 changes: 0 additions & 3 deletions debian/console-conf.conf

This file was deleted.

3 changes: 3 additions & 0 deletions debian/console-conf.console-conf@.service
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ Conflicts=getty@%i.service
[Service]
Environment=PYTHONPATH=/usr/share/subiquity
ExecStart=/sbin/agetty -i -n --noclear -l /usr/share/subiquity/console-conf-wrapper %I $TERM
RestartPreventExitStatus=22
ExecStopPost=/usr/share/subiquity/console-conf-check-error getty@%i.service
Type=idle
OnFailure=getty@%i.service
Restart=always
RestartSec=0
UtmpIdentifier=%I
Expand Down
1 change: 1 addition & 0 deletions debian/console-conf.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
debian/tmp/usr/bin/console-conf-check-error usr/share/subiquity
debian/tmp/usr/bin/console-conf-tui usr/share/subiquity
debian/tmp/usr/bin/console-conf-wait usr/share/subiquity
debian/tmp/usr/bin/console-conf-wrapper usr/share/subiquity
Expand Down
3 changes: 2 additions & 1 deletion debian/console-conf.serial-console-conf@.service
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ After=core18.start-snapd.service core.start-snapd.service
# on core20 the user may invoke a recovery chooser, make sure the detection
# service runs before
After=snapd.recovery-chooser-trigger.service
ConditionPathExists=!/var/lib/console-conf/complete
StartLimitInterval=0
Conflicts=serial-getty@%i.service

[Service]
Environment=PYTHONPATH=/usr/share/subiquity
ExecStart=/sbin/agetty -i -n --keep-baud -l /usr/share/subiquity/console-conf-wrapper --login-options "--serial" 115200,38400,9600 %I $TERM
RestartPreventExitStatus=22
ExecStopPost=/usr/share/subiquity/console-conf-check-error serial-getty@%i.service
Type=idle
Restart=always
RestartSec=0
Expand Down
4 changes: 0 additions & 4 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ override_dh_python3:
override_dh_installinit:
dh_installsystemd --no-start --name=console-conf@
dh_installsystemd --no-start --name=serial-console-conf@
mkdir $(CURDIR)/debian/console-conf/lib/systemd/system/getty@.service.d/
install -m 0644 $(CURDIR)/debian/console-conf.conf $(CURDIR)/debian/console-conf/lib/systemd/system/getty@.service.d/
mkdir $(CURDIR)/debian/console-conf/lib/systemd/system/serial-getty@.service.d/
install -m 0644 $(CURDIR)/debian/console-conf-serial.conf $(CURDIR)/debian/console-conf/lib/systemd/system/serial-getty@.service.d/
install -D -m 0755 -t $(CURDIR)/debian/console-conf/lib/systemd/system-generators $(CURDIR)/debian/serial-console-generator

override_dh_auto_test:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class build(distutils.command.build.build):
license="AGPLv3+",
packages=find_packages(exclude=["tests"]),
scripts=[
'bin/console-conf-check-error',
'bin/console-conf-wait',
'bin/console-conf-wrapper',
'bin/subiquity-debug',
Expand Down

0 comments on commit 8e351db

Please sign in to comment.