Ensure getty prompts for the username

As Eckehard Berns reported:

"On Slackware /bin/login times out after 60 seconds which will
clutter the vt after a couple of minutes with timeout messages and login
prompts. So it seems that getty should ask for the username first even
if login could do it as well."
This commit is contained in:
sin 2014-02-10 15:04:24 +00:00
parent a8e1ea1398
commit cb904446ec

29
getty.c
View File

@ -3,6 +3,7 @@
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
@ -23,7 +24,9 @@ main(int argc, char *argv[])
{ {
int fd; int fd;
struct sigaction sa; struct sigaction sa;
char term[128]; char term[128], logname[128], c;
int i = 0;
ssize_t n;
ARGBEGIN { ARGBEGIN {
default: default:
@ -76,5 +79,27 @@ main(int argc, char *argv[])
sigaction(SIGHUP, &sa, NULL); sigaction(SIGHUP, &sa, NULL);
putchar('\n'); putchar('\n');
return execvp("/bin/login", (char *[]){ "login", NULL }); printf("Login: ");
fflush(stdout);
/* Flush pending input */
ioctl(STDIN_FILENO, TCFLSH, (void *)0);
memset(logname, 0, sizeof(logname));
while (1) {
n = read(STDIN_FILENO, &c, 1);
if (n < 0)
eprintf("read:");
if (n == 0)
return EXIT_FAILURE;
if (i >= sizeof(logname) - 1)
eprintf("login name too long\n");
if (c == '\n' || c == '\r')
break;
logname[i++] = c;
}
if (logname[0] == '-')
eprintf("login name cannot start with '-'\n");
if (logname[0] == '\0')
return EXIT_FAILURE;
return execvp("/bin/login", (char *[]){ "login", logname, NULL });
} }