Skip to contentSkip to conversation

agetty: Reprompt and reprint /etc/issue if we receive SIGUSR1

PATCH In review Stef Walter 2 participants 10 messages Jul 7, 2014 – Jul 16, 2014 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 agetty: Reprompt and reprint /etc/issue if we receive SIGUSR1

Several of the /etc/issue escape codes such as \4 and \S depend on variable data which can change after the agetty prompt is displayed. This can cause stale data to be displayed when a user looks at a VT, especially in cases of DHCP racing with system start up.

This commit allows agetty to react a SIGUSR1 signal by reprinting its prompt including the reprocessing of /etc/issue.

We never want this to occur once the user has started typing a user name. So we detect when the user starts typing, after which no further reprompting occurs even if SIGUSR1 is received.

---
 term-utils/agetty.8 |  9 +++++-
 term-utils/agetty.c | 86 +++++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 81 insertions(+), 14 deletions(-)
term-utils/agetty.8 +8 -1
index 27a0d1b..b11dd4b 100644
@@ -385,7 +385,14 @@ displays as:
 This is thingol.orcan.dk (Linux i386 1.1.9) 18:29:30
 .fi
 .RE
-
+.SH SIGNALS
+Upon receiving
+.BR SIGUSR1
+.BR agetty
+will reprint the
+.B /etc/issue
+(if so configured) and login prompt. It will do this unless the
+user has started typing a login name.
 .SH FILES
 .na
 .TP
term-utils/agetty.c +73 -13

143 lines not on this page · raw message

Signature · 1 line
1.9.3
maintainer
#1 lore raw
Quoted 11 lines · Stef Walter

Several of the /etc/issue escape codes such as \4 and \S depend on variable data which can change after the agetty prompt is displayed. This can cause stale data to be displayed when a user looks at a VT, especially in cases of DHCP racing with system start up.

This commit allows agetty to react a SIGUSR1 signal by reprinting its prompt including the reprocessing of /etc/issue.

We never want this to occur once the user has started typing a user name. So we detect when the user starts typing, after which no further reprompting occurs even if SIGUSR1 is received.

Good idea, interesting implementation, but it's too late for v2.25. I'm going to apply the patch to the git tree after v2.25 release.

Thanks.
Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#2 lore raw
Quoted 9 lines · Karel Zak
Quoted 8 lines · Stef Walter

Several of the /etc/issue escape codes such as \4 and \S depend on variable data which can change after the agetty prompt is displayed. This can cause stale data to be displayed when a user looks at a VT, especially in cases of DHCP racing with system start up.

This commit allows agetty to react a SIGUSR1 signal by reprinting its prompt including the reprocessing of /etc/issue.

Quoted 6 lines
Quoted 3 lines

We never want this to occur once the user has started typing a user name. So we detect when the user starts typing, after which no further reprompting occurs even if SIGUSR1 is received.

Good idea, interesting implementation, but it's too late for v2.25. I'm going to apply the patch to the git tree after v2.25 release.

Nice. Thanks.

Lennart discovered an issue with this ...

That the exec'ing the login process might race with the SIGUSR1 signal. The fix here would be to signal(SIGUSR1, SIG_IGN) before exec'ing, does that sound appropriate? I can post a new patch.

By the way, more information about this use case here:
https://bugzilla.redhat.com/show_bug.cgi?id=1110763

Also, on the use of SIGUSR1 ... often linux daemons like to use SIGHUP as a 'reload' signal. But obviously this signal already has specific meaning in the agetty case, hence the choice of SIGUSR1.

Cheers,

Stef

maintainer
#3 lore raw
Quoted 10 lines · Stef Walter
Quoted 9 lines · Karel Zak
Quoted 8 lines · Stef Walter

Several of the /etc/issue escape codes such as \4 and \S depend on variable data which can change after the agetty prompt is displayed. This can cause stale data to be displayed when a user looks at a VT, especially in cases of DHCP racing with system start up.

This commit allows agetty to react a SIGUSR1 signal by reprinting its prompt including the reprocessing of /etc/issue.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

We never want this to occur once the user has started typing a user name. So we detect when the user starts typing, after which no further reprompting occurs even if SIGUSR1 is received.

Good idea, interesting implementation, but it's too late for v2.25. I'm going to apply the patch to the git tree after v2.25 release.

Nice. Thanks.

I have never seen the idea with VMIN and TIOCSTI ioctl, that's interesting thing.

Quoted 8 lines

Lennart discovered an issue with this ...

That the exec'ing the login process might race with the SIGUSR1 signal. The fix here would be to signal(SIGUSR1, SIG_IGN) before exec'ing, does that sound appropriate? I can post a new patch.

By the way, more information about this use case here:
https://bugzilla.redhat.com/show_bug.cgi?id=1110763

Yes, I read it yesterday evening. Lennart is right about the race.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
maintainer
#4 lore raw
In reply to Stef Walter
Quoted 8 lines · Stef Walter

/* Get user name, establish parity, speed, erase, kill & eol. */
static char *get_logname(struct options *op, struct termios *tp, struct chardata *cp) {

term-utils/agetty.c +1 -0
@@ -1625,9 +1676,18 @@ static char *get_logname(struct options *op, struct termios *tp, struct chardata
 
 	while (*logname == '\0') {
 
+		reprompt_flag = 0;

term-utils/agetty.c static char *get_logname(struct options *op, struct termios *tp, struct chardata · line 1689

Quoted 10 lines
term-utils/agetty.c +7 -0
+
 		/* Write issue file and prompt */
 		do_prompt(op, tp);
 
+		/* If asked to reprompt *before* terminal input arrives, then do so */
+		if (!wait_for_term_input(STDIN_FILENO) && reprompt_flag != 0) {
+			if (op->flags & F_VCONSOLE)
+				termio_clear(STDOUT_FILENO);
+			continue;
+		}

Now when I think about it.. would be better to have this feature optional? I think it's overkill to have it enabled on all machines.

The another story is the signal usage (and possible race with login(1) as discussed at https://bugzilla.redhat.com/show_bug.cgi?id=1110763).

What about for example:

   agetty --reload-trigger <file>

and use inotify for the <file>. I guess this way also allows to avoid the ioctl() tty voodoo and you can use select() for the inotify and tty file descriptors.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#5 lore raw
Quoted 13 lines · Karel Zak
Quoted 12 lines · Stef Walter

/* Get user name, establish parity, speed, erase, kill & eol. */
static char *get_logname(struct options *op, struct termios *tp, struct chardata *cp) {

term-utils/agetty.c +2 -0
@@ -1625,9 +1676,18 @@ static char *get_logname(struct options *op, struct termios *tp, struct chardata
 
 	while (*logname == '\0') {
 
+		reprompt_flag = 0;
+
 		/* Write issue file and prompt */
 		do_prompt(op, tp);
 
Quoted 9 lines

term-utils/agetty.c static char *get_logname(struct options *op, struct termios *tp, struct chardata · line 1689

Quoted 6 lines
term-utils/agetty.c +6 -0
+		/* If asked to reprompt *before* terminal input arrives, then do so */
+		if (!wait_for_term_input(STDIN_FILENO) && reprompt_flag != 0) {
+			if (op->flags & F_VCONSOLE)
+				termio_clear(STDOUT_FILENO);
+			continue;
+		}

Now when I think about it.. would be better to have this feature optional? I think it's overkill to have it enabled on all machines.

Sure.

Quoted 6 lines

The another story is the signal usage (and possible race with login(1) as discussed at https://bugzilla.redhat.com/show_bug.cgi?id=1110763).

What about for example:

   agetty --reload-trigger <file>

As I said in the above bugzilla bug, I don't mind doing this ... but in my opinion unix signals are meant exactly for this use case, and are used by many (most?) other linx processes as a reload trigger.

Quoted 3 lines

and use inotify for the <file>. I guess this way also allows to avoid the ioctl() tty voodoo and you can use select() for the inotify and tty file descriptors.

Unfortunately that's not how it works. When in canonical mode, the tty file descriptor only becomes readable once a complete line has been entered. I've verified that select() does not return until <enter> is pressed.

Hence the switch to non-canonical mode, until the first character is pressed, and then back to canonical.

Cheers,

Stef

maintainer
#6 lore raw
Quoted 9 lines · Stef Walter
Quoted 2 lines · Karel Zak

Now when I think about it.. would be better to have this feature optional? I think it's overkill to have it enabled on all machines.

Sure.

Quoted 3 lines

The another story is the signal usage (and possible race with login(1) as discussed at https://bugzilla.redhat.com/show_bug.cgi?id=1110763).

Quoted 7 lines
Quoted 3 lines

What about for example:

   agetty --reload-trigger <file>

As I said in the above bugzilla bug, I don't mind doing this ... but in my opinion unix signals are meant exactly for this use case, and are used by many (most?) other linx processes as a reload trigger.

Yes, it's pretty common classic solution, but I think that in this case it is not too robust solution.

Quoted 8 lines
Quoted 3 lines

and use inotify for the <file>. I guess this way also allows to avoid the ioctl() tty voodoo and you can use select() for the inotify and tty file descriptors.

Unfortunately that's not how it works. When in canonical mode, the tty file descriptor only becomes readable once a complete line has been entered. I've verified that select() does not return until <enter> is pressed.

Ah.. good point, but with non-canonical mode it works as expected, right? So, we can use fd with VMIN=1 and inotify fd for the select().

Maybe the best would be to implement all within agetty, I mean add a special command

   agetty --reload [<tty>]

to reload another already running agetty process(es). So rather than "killall agetty" you have to use "agetty --reload".

Then all the implementation will be a private thing and only the "--reload" command line option will be a public API.

Note that we does not control code of all login(1) implementations and we have --login-program <path> to start arbitrary random thing from agetty, so our solution have to be generic rather than rely on any login(1) change.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#7 lore raw
Quoted 25 lines · Karel Zak
Quoted 9 lines · Stef Walter
Quoted 2 lines · Karel Zak

Now when I think about it.. would be better to have this feature optional? I think it's overkill to have it enabled on all machines.

Sure.

Quoted 3 lines

The another story is the signal usage (and possible race with login(1) as discussed at https://bugzilla.redhat.com/show_bug.cgi?id=1110763).

Quoted 7 lines
Quoted 3 lines

What about for example:

   agetty --reload-trigger <file>

As I said in the above bugzilla bug, I don't mind doing this ... but in my opinion unix signals are meant exactly for this use case, and are used by many (most?) other linx processes as a reload trigger.

Yes, it's pretty common classic solution, but I think that in this case it is not too robust solution.

Quoted 4 lines
Quoted 3 lines

and use inotify for the <file>. I guess this way also allows to avoid the ioctl() tty voodoo and you can use select() for the inotify and tty file descriptors.

Quoted 7 lines
Quoted 4 lines

Unfortunately that's not how it works. When in canonical mode, the tty file descriptor only becomes readable once a complete line has been entered. I've verified that select() does not return until <enter> is pressed.

Ah.. good point, but with non-canonical mode it works as expected, right? So, we can use fd with VMIN=1 and inotify fd for the select().

Yup.

Quoted 10 lines

Maybe the best would be to implement all within agetty, I mean add a special command

   agetty --reload [<tty>]

to reload another already running agetty process(es). So rather than "killall agetty" you have to use "agetty --reload".

Then all the implementation will be a private thing and only the "--reload" command line option will be a public API.

Okay. I'll work on this and keep you posted.

Quoted 4 lines

Note that we does not control code of all login(1) implementations and we have --login-program <path> to start arbitrary random thing from agetty, so our solution have to be generic rather than rely on any login(1) change.

Well you don't need to modify login(1) (or other --login-program's) at all. SIG_IGN is kept across an exec.

Stef

#8 lore raw
Quoted 6 lines · Stef Walter
Quoted 5 lines · Karel Zak

Maybe the best would be to implement all within agetty, I mean add a special command

   agetty --reload [<tty>]
Quoted 7 lines
Quoted 5 lines

to reload another already running agetty process(es). So rather than "killall agetty" you have to use "agetty --reload".

Then all the implementation will be a private thing and only the "--reload" command line option will be a public API.

Okay. I'll work on this and keep you posted.

Attached is the updated patch.

The current patch implements --reload. We use inotify on a path in /run to signal the process. We don't create the file initially until does a --reload.

Note that I didn't implement the [<tty>] option. It seems like it would need inotify track multiple files, and as such be prone to races, when trying to signal all agetty processes.

What do you think?

Stef

Quoted 1 line

From 33583bff1b4dfb3dcff582d1dec9f4005e8bdafd Mon Sep 17 00:00:00 2001

From: Stef Walter <[email protected]>
Date: Thu, 3 Jul 2014 17:44:41 +0200
Subject: [PATCH] agetty: Reprompt and reprint /etc/issue when asked

Add an 'agetty --reload' command which asks all running agetty commands to display their prompts again.

Several of the /etc/issue escape codes such as \4 and \S depend on variable data which can change after the agetty prompt is displayed. This can cause stale data to be displayed when a user looks at a VT, especially in cases of DHCP racing with system start up.

We never want this to occur once the user has started typing a user name. So we detect when the user starts typing, after which no further reprompting occurs after that point.

---
 term-utils/agetty.8 |   5 +++
 term-utils/agetty.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 119 insertions(+), 12 deletions(-)
term-utils/agetty.8 +5 -0
index 27a0d1b..c997129 100644
@@ -252,6 +252,11 @@ Sleep seconds before open tty.
 \-\-nice \fInumber\fP
 Run login with this priority.
 .TP
+\-\-reload
+Ask all running agetty instances to reload and update their displayed prompts,
+if the user has not yet commenced logging in. After doing so the command will
+exit.
+.TP
 \-\-version
 Display version information and exit.
 .TP
term-utils/agetty.c +114 -12

199 lines not on this page · raw message

Signature · 1 line
1.9.3
maintainer
#9 lore raw
In reply to Stef Walter
Quoted 8 lines · Stef Walter
Quoted 4 lines · Karel Zak

Note that we does not control code of all login(1) implementations and we have --login-program <path> to start arbitrary random thing from agetty, so our solution have to be generic rather than rely on any login(1) change.

Well you don't need to modify login(1) (or other --login-program's) at all. SIG_IGN is kept across an exec.

Sure, but it's little bit fragile way.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com