diff mbox series

[v5,03/13] package/systemd: fix tty handling

Message ID 20191216103052.35220-4-jeremy.rosen@smile.fr
State Accepted
Headers show
Series use host-systemd to enable units | expand

Commit Message

Jérémy ROSEN Dec. 16, 2019, 10:30 a.m. UTC
Handling of tty is a bit tricky, we need to aggressively disable what
systemd does with tty1 then update for what buildroot wants to do

Rework the whole tty generation to work with presets

Signed-off-by: Jérémy Rosen <jeremy.rosen@smile.fr>
---
 package/systemd/80-buildroot.preset |  5 ++---
 package/systemd/systemd.mk          | 25 +++++++++++++++++--------
 2 files changed, 19 insertions(+), 11 deletions(-)

Comments

Thomas Petazzoni May 16, 2020, 2:28 p.m. UTC | #1
Hello Jérémy,

On Mon, 16 Dec 2019 11:30:42 +0100
Jérémy Rosen <jeremy.rosen@smile.fr> wrote:

> +# systemd defaults to only have getty@tty.service enabled
> +# * DefaultInstance=tty1 in getty@service
> +# * no DefaultInstance in serial-getty@.service
> +# * WantedBy=getty.target in console-getty.service
> +# * console-getty is not enabled because of 90-systemd.preset
> +# 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
> +# * set a new DefaultInstance for getty@.service instead, if needed
> +# * set a new DefaultInstance for serial-getty@.service, if needed
> +# * override the systemd-provided preset for console-getty.service if needed
>  define SYSTEMD_INSTALL_SERVICE_TTY
> +	mkdir $(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d;\
> +	printf '[Install]\nDefaultInstance=\n' > $(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d/buildroot-console.conf;\
>  	if [ $(BR2_TARGET_GENERIC_GETTY_PORT) = "console" ]; \
>  	then \
>  		TARGET="console-getty.service"; \
> -		LINK_NAME="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]*$$'; \
>  	then \
>  		TARGET="getty@.service"; \
> -		LINK_NAME="getty@$(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)).service"; \
> +		printf '[Install]\nDefaultInstance=%s\n' $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)) > $(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d/buildroot-console.conf;\
>  	else \
>  		TARGET="serial-getty@.service"; \
> -		LINK_NAME="serial-getty@$(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)).service"; \
> +		mkdir $(TARGET_DIR)/usr/lib/systemd/system/serial-getty@.service.d;\
> +		printf '[Install]\nDefaultInstance=%s\n' $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)) > $(TARGET_DIR)/usr/lib/systemd/system/serial-getty@.service.d/buildroot-console.conf;\
>  	fi; \
> -	mkdir -p $(TARGET_DIR)/etc/systemd/system/getty.target.wants/; \
> -	ln -fs ../../../../lib/systemd/system/$${TARGET} \
> -		$(TARGET_DIR)/etc/systemd/system/getty.target.wants/$${LINK_NAME}; \

I am not sure exactly if it is this change causing the issue, but there
is an issue in this code. See the bug report at:

  https://bugs.busybox.net/show_bug.cgi?id=12786

I must say now that I read the comment on top of this code, I don't
understand at all what is being explained. Could you give a bit more
details about what we are trying to do here, and hopefully help resolve
bug 12786 ?

Thanks!

Thomas
Jérémy ROSEN May 18, 2020, 7:12 a.m. UTC | #2
Hey Thomas
This seems definitely related to my patch, I'll try to have a look at it
ASAP, but I can't really promise when ASAP will be...

Sorry about that
Jeremy


Le sam. 16 mai 2020 à 16:28, Thomas Petazzoni <thomas.petazzoni@bootlin.com>
a écrit :

> Hello Jérémy,
>
> On Mon, 16 Dec 2019 11:30:42 +0100
> Jérémy Rosen <jeremy.rosen@smile.fr> wrote:
>
> > +# systemd defaults to only have getty@tty.service enabled
> > +# * DefaultInstance=tty1 in getty@service
> > +# * no DefaultInstance in serial-getty@.service
> > +# * WantedBy=getty.target in console-getty.service
> > +# * console-getty is not enabled because of 90-systemd.preset
> > +# 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
> > +# * set a new DefaultInstance for getty@.service instead, if needed
> > +# * set a new DefaultInstance for serial-getty@.service, if needed
> > +# * override the systemd-provided preset for console-getty.service if
> needed
> >  define SYSTEMD_INSTALL_SERVICE_TTY
> > +     mkdir $(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d;\
> > +     printf '[Install]\nDefaultInstance=\n' >
> $(TARGET_DIR)/usr/lib/systemd/system/getty@
> .service.d/buildroot-console.conf;\
> >       if [ $(BR2_TARGET_GENERIC_GETTY_PORT) = "console" ]; \
> >       then \
> >               TARGET="console-getty.service"; \
> > -             LINK_NAME="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]*$$'; \
> >       then \
> >               TARGET="getty@.service"; \
> > -             LINK_NAME="getty@$(call
> qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)).service"; \
> > +             printf '[Install]\nDefaultInstance=%s\n' $(call
> qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)) >
> $(TARGET_DIR)/usr/lib/systemd/system/getty@
> .service.d/buildroot-console.conf;\
> >       else \
> >               TARGET="serial-getty@.service"; \
> > -             LINK_NAME="serial-getty@$(call
> qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)).service"; \
> > +             mkdir $(TARGET_DIR)/usr/lib/systemd/system/serial-getty@
> .service.d;\
> > +             printf '[Install]\nDefaultInstance=%s\n' $(call
> qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)) >
> $(TARGET_DIR)/usr/lib/systemd/system/serial-getty@
> .service.d/buildroot-console.conf;\
> >       fi; \
> > -     mkdir -p $(TARGET_DIR)/etc/systemd/system/getty.target.wants/; \
> > -     ln -fs ../../../../lib/systemd/system/$${TARGET} \
> > -
>  $(TARGET_DIR)/etc/systemd/system/getty.target.wants/$${LINK_NAME}; \
>
> I am not sure exactly if it is this change causing the issue, but there
> is an issue in this code. See the bug report at:
>
>   https://bugs.busybox.net/show_bug.cgi?id=12786
>
> I must say now that I read the comment on top of this code, I don't
> understand at all what is being explained. Could you give a bit more
> details about what we are trying to do here, and hopefully help resolve
> bug 12786 ?
>
> Thanks!
>
> Thomas
> --
> Thomas Petazzoni, CTO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
Jérémy ROSEN May 22, 2020, 5 p.m. UTC | #3
Ok, I found the cause and sent a patch (separate email thread)

I tried to clarify the comment too, while I was at it

Regards
Jérémy

Le lun. 18 mai 2020 à 09:12, Jérémy ROSEN <jeremy.rosen@smile.fr> a écrit :

> Hey Thomas
> This seems definitely related to my patch, I'll try to have a look at it
> ASAP, but I can't really promise when ASAP will be...
>
> Sorry about that
> Jeremy
>
>
> Le sam. 16 mai 2020 à 16:28, Thomas Petazzoni <
> thomas.petazzoni@bootlin.com> a écrit :
>
>> Hello Jérémy,
>>
>> On Mon, 16 Dec 2019 11:30:42 +0100
>> Jérémy Rosen <jeremy.rosen@smile.fr> wrote:
>>
>> > +# systemd defaults to only have getty@tty.service enabled
>> > +# * DefaultInstance=tty1 in getty@service
>> > +# * no DefaultInstance in serial-getty@.service
>> > +# * WantedBy=getty.target in console-getty.service
>> > +# * console-getty is not enabled because of 90-systemd.preset
>> > +# 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
>> > +# * set a new DefaultInstance for getty@.service instead, if needed
>> > +# * set a new DefaultInstance for serial-getty@.service, if needed
>> > +# * override the systemd-provided preset for console-getty.service if
>> needed
>> >  define SYSTEMD_INSTALL_SERVICE_TTY
>> > +     mkdir $(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d;\
>> > +     printf '[Install]\nDefaultInstance=\n' >
>> $(TARGET_DIR)/usr/lib/systemd/system/getty@
>> .service.d/buildroot-console.conf;\
>> >       if [ $(BR2_TARGET_GENERIC_GETTY_PORT) = "console" ]; \
>> >       then \
>> >               TARGET="console-getty.service"; \
>> > -             LINK_NAME="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]*$$'; \
>> >       then \
>> >               TARGET="getty@.service"; \
>> > -             LINK_NAME="getty@$(call
>> qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)).service"; \
>> > +             printf '[Install]\nDefaultInstance=%s\n' $(call
>> qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)) >
>> $(TARGET_DIR)/usr/lib/systemd/system/getty@
>> .service.d/buildroot-console.conf;\
>> >       else \
>> >               TARGET="serial-getty@.service"; \
>> > -             LINK_NAME="serial-getty@$(call
>> qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)).service"; \
>> > +             mkdir $(TARGET_DIR)/usr/lib/systemd/system/serial-getty@
>> .service.d;\
>> > +             printf '[Install]\nDefaultInstance=%s\n' $(call
>> qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)) >
>> $(TARGET_DIR)/usr/lib/systemd/system/serial-getty@
>> .service.d/buildroot-console.conf;\
>> >       fi; \
>> > -     mkdir -p $(TARGET_DIR)/etc/systemd/system/getty.target.wants/; \
>> > -     ln -fs ../../../../lib/systemd/system/$${TARGET} \
>> > -
>>  $(TARGET_DIR)/etc/systemd/system/getty.target.wants/$${LINK_NAME}; \
>>
>> I am not sure exactly if it is this change causing the issue, but there
>> is an issue in this code. See the bug report at:
>>
>>   https://bugs.busybox.net/show_bug.cgi?id=12786
>>
>> I must say now that I read the comment on top of this code, I don't
>> understand at all what is being explained. Could you give a bit more
>> details about what we are trying to do here, and hopefully help resolve
>> bug 12786 ?
>>
>> Thanks!
>>
>> Thomas
>> --
>> Thomas Petazzoni, CTO, Bootlin
>> Embedded Linux and Kernel engineering
>> https://bootlin.com
>>
>
>
> --
> [image: SMILE]  <http://www.smile.eu/>
>
> 20 rue des Jardins
> 92600 Asnières-sur-Seine
> *Jérémy ROSEN*
> Architecte technique
>
> [image: email] jeremy.rosen@smile.fr
> [image: phone]  +33 6 88 25 87 42
> [image: url] http://www.smile.eu
>
> [image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
> <https://www.facebook.com/smileopensource> [image: LinkedIn]
> <https://www.linkedin.com/company/smile> [image: Github]
> <https://github.com/Smile-SA>
>
> [image: Découvrez l’univers Smile, rendez-vous sur smile.eu]
> <https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
>
diff mbox series

Patch

diff --git a/package/systemd/80-buildroot.preset b/package/systemd/80-buildroot.preset
index 4074901cbd..5dbae39173 100644
--- a/package/systemd/80-buildroot.preset
+++ b/package/systemd/80-buildroot.preset
@@ -1,5 +1,4 @@ 
 # Higher priority than systemd presets
 
-# by default systemd enables a getty on tty1
-# we don't want that because tty1 may not exist
-disable getty@.service
+# This file is currently empty, but is available for demonstration and future use
+
diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk
index 057a4eb9e5..6adf3adca4 100644
--- a/package/systemd/systemd.mk
+++ b/package/systemd/systemd.mk
@@ -433,22 +433,33 @@  ifneq ($(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)),)
 # systemd needs getty.service for VTs and serial-getty.service for serial ttys
 # note that console-getty.service should be used on /dev/console as it should not have dependencies
 # also patch the file to use the correct baud-rate, the default baudrate is 115200 so look for that
+#
+# systemd defaults to only have getty@tty.service enabled
+# * DefaultInstance=tty1 in getty@service
+# * no DefaultInstance in serial-getty@.service
+# * WantedBy=getty.target in console-getty.service
+# * console-getty is not enabled because of 90-systemd.preset
+# 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
+# * set a new DefaultInstance for getty@.service instead, if needed
+# * set a new DefaultInstance for serial-getty@.service, if needed
+# * override the systemd-provided preset for console-getty.service if needed
 define SYSTEMD_INSTALL_SERVICE_TTY
+	mkdir $(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d;\
+	printf '[Install]\nDefaultInstance=\n' > $(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d/buildroot-console.conf;\
 	if [ $(BR2_TARGET_GENERIC_GETTY_PORT) = "console" ]; \
 	then \
 		TARGET="console-getty.service"; \
-		LINK_NAME="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]*$$'; \
 	then \
 		TARGET="getty@.service"; \
-		LINK_NAME="getty@$(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)).service"; \
+		printf '[Install]\nDefaultInstance=%s\n' $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)) > $(TARGET_DIR)/usr/lib/systemd/system/getty@.service.d/buildroot-console.conf;\
 	else \
 		TARGET="serial-getty@.service"; \
-		LINK_NAME="serial-getty@$(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)).service"; \
+		mkdir $(TARGET_DIR)/usr/lib/systemd/system/serial-getty@.service.d;\
+		printf '[Install]\nDefaultInstance=%s\n' $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)) > $(TARGET_DIR)/usr/lib/systemd/system/serial-getty@.service.d/buildroot-console.conf;\
 	fi; \
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/getty.target.wants/; \
-	ln -fs ../../../../lib/systemd/system/$${TARGET} \
-		$(TARGET_DIR)/etc/systemd/system/getty.target.wants/$${LINK_NAME}; \
 	if [ $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_BAUDRATE)) -gt 0 ] ; \
 	then \
 		$(SED) 's,115200,$(BR2_TARGET_GENERIC_GETTY_BAUDRATE),' $(TARGET_DIR)/lib/systemd/system/$${TARGET}; \
@@ -456,7 +467,6 @@  define SYSTEMD_INSTALL_SERVICE_TTY
 endef
 endif
 
-
 define SYSTEMD_INSTALL_PRESET
 	$(INSTALL) -D -m 644 $(SYSTEMD_PKGDIR)/80-buildroot.preset $(TARGET_DIR)/usr/lib/systemd/system-preset/80-buildroot.preset
 endef
@@ -472,7 +482,6 @@  define SYSTEMD_PRESET_ALL
 endef
 SYSTEMD_TARGET_FINALIZE_HOOKS += SYSTEMD_PRESET_ALL
 
-
 SYSTEMD_CONF_ENV = $(HOST_UTF8_LOCALE_ENV)
 SYSTEMD_NINJA_ENV = $(HOST_UTF8_LOCALE_ENV)