From 397f67d03a8f81b46544d1cf585922cbe625ed0f Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 6 Jan 2020 19:37:00 +0100 Subject: [PATCH] Clear current line before starting built-in getty When logging out from the shell, e.g. with Ctrl-D, artifacts from that session may remain on the current line. This patch makes sure to clear up that line before issuing a newline and starting the built-in getty. Signed-off-by: Joachim Nilsson --- src/getty.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/getty.c b/src/getty.c index 240a7e45..de59abbe 100644 --- a/src/getty.c +++ b/src/getty.c @@ -211,8 +211,9 @@ static int do_login(char *name) int getty(char *tty, speed_t speed, char *term, char *user) { - int fd; + const char cln[] = "\r\e[2K\n"; char name[30]; + int fd; /* Detach from initial controlling TTY */ vhangup(); @@ -231,7 +232,7 @@ int getty(char *tty, speed_t speed, char *term, char *user) /* Set up TTY, re-enabling ISIG et al. */ stty(STDIN_FILENO, speed); - (void)write(STDOUT_FILENO, "\n", 1); + (void)write(STDOUT_FILENO, cln, strlen(cln)); /* The getty process is responsible for the UTMP login record */ utmp_set_login(tty, NULL);