[systemd-devel] How to get systemd to leave a USB serial console session alone when hadware is pulled?

Kaz Kylheku kaz at kylheku.com
Tue May 21 21:12:09 PDT 2013


On Wed, 22 May 2013 06:55:56 +0400, Andrey Borzenkov
<arvidjaar at gmail.com> wrote:
> В Tue, 21 May 2013 15:17:23 -0700 Kaz Kylheku <kaz at kylheku.com> пишет:
>> The workaround is, at that point, to unplug the device
>> and plug it back in. This will trigger a udev event (with
>> the "reinserted"  attribute equal to "0": since no TTY session is
>> being recovered: nothing has the TTY open). The custom udev
>> rule fires, and systemd serves up an agetty.
>>
> 
> Do you use getty at .service template that is distributed with systemd? If
> not, could you show full service definition?

Yes, I just modified getty at .service. All I did to it is:

--- a/units/getty at .service.m4
+++ b/units/getty at .service.m4
@@ -37,10 +37,10 @@ Restart=always
 RestartSec=0
 UtmpIdentifier=%I
 TTYPath=/dev/%I
-TTYReset=yes
-TTYVHangup=yes
-TTYVTDisallocate=yes
-KillMode=process
+TTYReset=no
+TTYVHangup=no
+TTYVTDisallocate=no
+KillMode=none
 
 # Unset locale for the console getty since the console has problems
 # displaying some internationalized messages.

Basically systemd has to note that the device has been
re-inserted (track its state), but not take any action;
just know that the device is in and re-launch agetty when that
session dies.

Now if I add a line to the udev rules like:

SUBSYSTEM=="tty", KERNEL=="ttyUSB[0-9]", ATTRS{is_console}=="1",
ATTRS{reinserted}=="1", TAG+="systemd"

Without: ENV{SYSTEMD_WANTS}+="getty@%k.service"
(Note the ATTRS{reinserted)=="1" so that this fires in the
appropriate case, when a removal and reinsertion takes place
during an open TTY session).

What happens is that systemd launches a new agetty upon reinsertion,
which runs parallel with the shell session; they compete for input.
There is some default action for that device so that if you don't
specify a SYSTEMD_WANTS, it "wants" something anyway.

Maybe it is possible to set SYSTEMD_WANTS to some kind of noop, so
systemd
wants nothing. I will search/experiment in that vein.

Thanks again.







More information about the systemd-devel mailing list