packages/systemd: fix double getty on console

When selecting "console" for the automatic getty, the buildroot logic
would collide with systemd's internal console detection logic, resulting
in two getty being started on the console.

This commit fixes that by doing nothing when "console" is selected and
letting systemd-getty-generator deal with starting the proper getty.

Note that if something other than the console is selected
* Things will work properly, even if the selected terminal is also the
  console
* A getty will still be started on the console.
  This is what systemd has been doing on buildroot since the beginning. it
  could be disabled but I left it for backward compatibility

Fixes: #12361
Signed-off-by: Jérémy Rosen <jeremy.rosen@smile.fr>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
This commit is contained in:
Jérémy Rosen 2020-05-22 18:59:29 +02:00 committed by Yann E. MORIN
parent 03fbb81b8b
commit 26c32d933e

View File

@ -497,37 +497,42 @@ define SYSTEMD_USERS
endef endef
ifneq ($(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)),) ifneq ($(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)),)
# systemd needs getty.service for VTs and serial-getty.service for serial ttys # systemd provides multiple units to autospawn getty as neede
# note that console-getty.service should be used on /dev/console as it should not have dependencies # * getty@.service to start a getty on normal TTY
# also patch the file to use the correct baud-rate, the default baudrate is 115200 so look for that # * sertial-getty@.service to start a getty on serial lines
# * console-getty.service for generic /dev/console
# * container-getty@.service for a getty on /dev/pts/*
# #
# systemd defaults to only have getty@tty.service enabled # the generator systemd-getty-generator will
# * DefaultInstance=tty1 in getty@service # * read the console= kernel command line parameter
# * no DefaultInstance in serial-getty@.service # * enable one of the above units depending on what it finds
# * WantedBy=getty.target in console-getty.service #
# * console-getty is not enabled because of 90-systemd.preset # Systemd defaults to enablinb getty@tty1.service
# We want "systemctl preset-all" to do the right thing, even when run on the target after boot #
# * remove the default instance of getty@.service via a drop-in in /usr/lib # What we want to do
# * set a new DefaultInstance for getty@.service instead, if needed # * Enable a getty on $BR2_TARGET_GENERIC_TTY_PATH
# * set a new DefaultInstance for serial-getty@.service, if needed # * Set the baudrate for all units according to BR2_TARGET_GENERIC_GETTY_BAUDRATE
# * override the systemd-provided preset for console-getty.service if needed # * Always enable a getty on the console using systemd-getty-generator
# (backward compatibility with previous releases of buildroot)
#
# What we do
# * disable getty@tty1 (enabled by upstream systemd)
# * enable getty@xxx if $BR2_TARGET_GENERIC_TTY_PATH is a tty
# * enable serial-getty@xxx for other $BR2_TARGET_GENERIC_TTY_PATH
# * rewrite baudrates if a baudrate is provided
define SYSTEMD_INSTALL_SERVICE_TTY define SYSTEMD_INSTALL_SERVICE_TTY
mkdir $(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d; \ mkdir $(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d; \
printf '[Install]\nDefaultInstance=\n' \ printf '[Install]\nDefaultInstance=\n' \
>$(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d/buildroot-console.conf; \ >$(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d/buildroot-console.conf; \
if [ $(BR2_TARGET_GENERIC_GETTY_PORT) = "console" ]; \ if [ $(BR2_TARGET_GENERIC_GETTY_PORT) = "console" ]; \
then \ then \
TARGET="console-getty.service"; \ : ; \
printf 'enable console-getty.service\n' \
>$(TARGET_DIR)/usr/lib/systemd/system-preset/81-buildroot-tty.preset; \
elif echo $(BR2_TARGET_GENERIC_GETTY_PORT) | egrep -q 'tty[0-9]*$$'; \ elif echo $(BR2_TARGET_GENERIC_GETTY_PORT) | egrep -q 'tty[0-9]*$$'; \
then \ then \
TARGET="getty@.service"; \
printf '[Install]\nDefaultInstance=%s\n' \ printf '[Install]\nDefaultInstance=%s\n' \
$(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)) \ $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)) \
>$(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d/buildroot-console.conf; \ >$(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d/buildroot-console.conf; \
else \ else \
TARGET="serial-getty@.service"; \
mkdir $(TARGET_DIR)/usr/lib/systemd/system/serial-getty@.service.d;\ mkdir $(TARGET_DIR)/usr/lib/systemd/system/serial-getty@.service.d;\
printf '[Install]\nDefaultInstance=%s\n' \ printf '[Install]\nDefaultInstance=%s\n' \
$(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)) \ $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)) \
@ -535,7 +540,10 @@ define SYSTEMD_INSTALL_SERVICE_TTY
fi; \ fi; \
if [ $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_BAUDRATE)) -gt 0 ] ; \ if [ $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_BAUDRATE)) -gt 0 ] ; \
then \ then \
$(SED) 's,115200,$(BR2_TARGET_GENERIC_GETTY_BAUDRATE),' $(TARGET_DIR)/lib/systemd/system/$${TARGET}; \ $(SED) 's/115200/$(BR2_TARGET_GENERIC_GETTY_BAUDRATE),115200/' $(TARGET_DIR)/lib/systemd/system/getty@.service; \
$(SED) 's/115200/$(BR2_TARGET_GENERIC_GETTY_BAUDRATE),115200/' $(TARGET_DIR)/lib/systemd/system/serial-getty@.service; \
$(SED) 's/115200/$(BR2_TARGET_GENERIC_GETTY_BAUDRATE),115200/' $(TARGET_DIR)/lib/systemd/system/console-getty@.service; \
$(SED) 's/115200/$(BR2_TARGET_GENERIC_GETTY_BAUDRATE),115200/' $(TARGET_DIR)/lib/systemd/system/container-getty@.service; \
fi fi
endef endef
endif endif