From 556925fe4e63719756ce32c904e887d89d81f5b9 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 21 Mar 2022 13:19:38 +0100 Subject: [PATCH] agetty: add support for LOGIN_PLAIN_PROMPT login(1) and agetty(8) are usually used together to log-in user. The initial login prompt is printed by agetty. login(1) can suppress hostname in the prompt by LOGIN_PLAIN_PROMPT=no (/etc/login.defs), but for agetty it's necessary to use --nohostname. It's pretty unfriendly for system admins. Let's share the same setting between all tools. Signed-off-by: Karel Zak --- term-utils/Makemodule.am | 6 +++++- term-utils/agetty.8.adoc | 11 ++++++++++- term-utils/agetty.c | 9 +++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/term-utils/Makemodule.am b/term-utils/Makemodule.am index 119324f5b0..07004d43ca 100644 --- a/term-utils/Makemodule.am +++ b/term-utils/Makemodule.am @@ -46,7 +46,8 @@ if BUILD_AGETTY sbin_PROGRAMS += agetty MANPAGES += term-utils/agetty.8 dist_noinst_DATA += term-utils/agetty.8.adoc -agetty_SOURCES = term-utils/agetty.c +agetty_SOURCES = term-utils/agetty.c \ + lib/logindefs.c if USE_PLYMOUTH_SUPPORT agetty_SOURCES += lib/plymouth-ctrl.c endif @@ -54,6 +55,9 @@ agetty_LDADD = $(LDADD) libcommon.la if BSD agetty_LDADD += -lutil endif +if HAVE_ECONF +agetty_LDADD += -leconf +endif endif # BUILD_AGETTY diff --git a/term-utils/agetty.8.adoc b/term-utils/agetty.8.adoc index 123134e097..7a298f723f 100644 --- a/term-utils/agetty.8.adoc +++ b/term-utils/agetty.8.adoc @@ -157,7 +157,7 @@ Wait for the user or the modem to send a carriage-return or a linefeed character Do not print hints about Num, Caps and Scroll Locks. *--nohostname*:: -By default the hostname will be printed. With this option enabled, no hostname at all will be shown. +By default the hostname will be printed. With this option enabled, no hostname at all will be shown. This seeting is also possible to able by LOGIN_PLAIN_PROMPT option in the _/etc/login.defs_ configuration file (see below for more details). *--long-hostname*:: By default the hostname is only printed until the first dot. With this option enabled, the fully qualified hostname by *gethostname*(3P) or (if not found) by *getaddrinfo*(3) is shown. @@ -182,6 +182,15 @@ Ask all running *agetty* instances to reload and update their displayed prompts, include::man-common/help-version.adoc[] +== CONFIG FILE ITEMS +*agetty* reads the _/etc/login.defs_ configuration file (see *login.defs*(5)). +Note that the configuration file could be distributed with another package (usually shadow-utils). +The following configuration items are relevant for *aggety*: + +*LOGIN_PLAIN_PROMPT* (boolean):: + +Tell *agetty* that printing the hostname should be suppressed in the login: prompt. This is an alternative to the *--nohostname* command line option. The default value is _no_. + == EXAMPLE This section shows examples for the process field of an entry in the _/etc/inittab_ file. You'll have to prepend appropriate values for the other fields. See *inittab*(5) for more details. diff --git a/term-utils/agetty.c b/term-utils/agetty.c index 5b673e638b..9b0812734e 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,8 @@ #include "color-names.h" #include "env.h" +#include "logindefs.h" + #ifdef USE_PLYMOUTH_SUPPORT # include "plymouth-ctrl.h" #endif @@ -495,7 +498,13 @@ int main(int argc, char **argv) if (options.flags & F_NOPROMPT) { /* --skip-login */ eval_issue_file(&issue, &options, &termios); print_issue_file(&issue, &options, &termios); + } else { /* regular (auto)login */ + if ((options.flags & F_NOHOSTNAME) == 0 && + getlogindefs_bool("LOGIN_PLAIN_PROMPT", 0) == 1) + /* /etc/login.defs enbles --nohostname too */ + options.flags |= F_NOHOSTNAME; + if (options.autolog) { /* Autologin prompt */ eval_issue_file(&issue, &options, &termios); -- 2.39.5