mirror of
https://github.com/troglobit/finit.git
synced 2026-10-24 11:54:36 +00:00
TTY: Major overhaul, move to built-in getty
The TTY handling in Finit has always been a bit of a patch work. This commit is an attempt at a first cleanup and simplification. Included is a brand new built-in getty which should work fine on both virtual and serial consoles. It is however completely untested on the latter serial consoles. Still TODO: add support for /etc/securetty, add support for actually setting TERM when calling /bin/login. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
789354ab40
commit
d15633781b
8 files changed
+376
-126
No files matched your search
@@ -26,16 +26,8 @@
|
||||
|
||||
#include <ctype.h> /* isdigit() */
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <lite/lite.h>
|
||||
|
||||
@@ -220,67 +212,23 @@ int run_interactive(char *cmd, char *fmt, ...)
|
||||
return status;
|
||||
}
|
||||
|
||||
pid_t run_getty(char *cmd, char *args[], char *tty, int console)
|
||||
int getty(char *tty, char *baud, char *term);
|
||||
|
||||
pid_t run_getty(char *tty, char *speed, char *term, int console)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
|
||||
if (!pid) {
|
||||
int i, fd;
|
||||
char c;
|
||||
struct sigaction sa;
|
||||
|
||||
/* Reset signal handlers that were set by the parent process */
|
||||
for (i = 1; i < NSIG; i++)
|
||||
DFLSIG(sa, i, 0);
|
||||
|
||||
/* Detach from initial controlling TTY */
|
||||
vhangup();
|
||||
|
||||
close(STDERR_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
close(STDIN_FILENO);
|
||||
|
||||
/* Attach TTY to console */
|
||||
fd = open(tty, O_RDWR);
|
||||
if (fd != STDIN_FILENO)
|
||||
exit(1);
|
||||
|
||||
dup2(fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
sig_unblock();
|
||||
setsid();
|
||||
|
||||
if (console)
|
||||
prctl(PR_SET_NAME, "console", 0, 0, 0);
|
||||
else
|
||||
prctl(PR_SET_NAME, "finit-getty", 0, 0, 0);
|
||||
|
||||
sig_unblock();
|
||||
setsid();
|
||||
|
||||
if (ioctl(STDIN_FILENO, TIOCSCTTY, 1) < 0)
|
||||
_pe("Failed TIOCSCTTY");
|
||||
|
||||
while (!fexist(SYNC_SHUTDOWN)) {
|
||||
static const char msg[] = "\nPlease press Enter to activate this console.";
|
||||
|
||||
if (fexist(SYNC_STOPPED)) {
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
(void)write(STDERR_FILENO, msg, sizeof(msg));
|
||||
while (read(STDIN_FILENO, &c, 1) == 1 && c != '\n')
|
||||
continue;
|
||||
|
||||
if (fexist(SYNC_STOPPED))
|
||||
continue;
|
||||
|
||||
execv(cmd, args);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
vhangup();
|
||||
exit(0);
|
||||
_exit(getty(tty, speed, term));
|
||||
}
|
||||
|
||||
return pid;
|
||||
|
||||
Reference in new issue
Block a user