tty: Clear tty before login: prompt by default, add 'noclear' option

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2017-07-08 15:31:59 +02:00
parent 60f73dc952
commit e48901b90f
6 changed files with 17 additions and 14 deletions
+1 -1
View File
@@ -136,7 +136,7 @@ Syntax:
* `include <CONF>`
Include another configuration file. Absolute path required.
* `tty [LVLS] <DEV> [BAUD] [TERM]`
* `tty [LVLS] <DEV> [BAUD] [TERM] [noclear]`
Start a getty on the given TTY device DEV, in the given runlevels. If
no tty setting is given in `finit.conf` no login is possible. Use the
`service` stanza to start a stand-alone shell for really bare bones
+3 -3
View File
@@ -38,7 +38,7 @@
#define NUM_ARGS 16
int getty(char *tty, char *baud, char *term, char *user);
int getty(char *tty, char *baud, char *term, int noclear, char *user);
/* Wait for process completion, returns status of waitpid(2) syscall */
@@ -212,7 +212,7 @@ int run_interactive(char *cmd, char *fmt, ...)
return status;
}
pid_t run_getty(char *tty, char *speed, char *term, int console)
pid_t run_getty(char *tty, char *speed, char *term, int noclear, int console)
{
pid_t pid;
@@ -230,7 +230,7 @@ pid_t run_getty(char *tty, char *speed, char *term, int console)
else
prctl(PR_SET_NAME, "finit-getty", 0, 0, 0);
_exit(getty(tty, speed, term, NULL));
_exit(getty(tty, speed, term, noclear, NULL));
}
return pid;
+5 -6
View File
@@ -63,7 +63,7 @@ static int readch(char *tty)
return ch1 & 0xFF;
}
static void stty(int fd, speed_t speed)
static void stty(int fd, speed_t speed, int noclear)
{
struct termios term;
@@ -98,9 +98,8 @@ static void stty(int fd, speed_t speed)
term.c_cc[VERASE] = CERASE;
tcsetattr(fd, TCSANOW, &term);
/* Clear screen in silent mode */
if (log_is_silent())
print("\033[r\033[H\033[J");
if (!noclear)
print("\e[r\e[H\e[J");
}
/*
@@ -291,7 +290,7 @@ static speed_t do_parse_speed(char *baud)
return B0;
}
int getty(char *tty, char *baud, char *term, char *user)
int getty(char *tty, char *baud, char *term, int noclear, char *user)
{
int fd;
char name[30];
@@ -328,7 +327,7 @@ int getty(char *tty, char *baud, char *term, char *user)
sa.sa_handler = _exit;
sigaction(SIGQUIT, &sa, NULL);
stty(fd, speed);
stty(fd, speed, noclear);
close(fd);
utmp_set_login(tty, NULL);
+1 -1
View File
@@ -63,7 +63,7 @@ void set_hostname (char **hostname);
int complete (char *cmd, int pid);
int run (char *cmd);
int run_interactive (char *cmd, char *fmt, ...);
pid_t run_getty (char *tty, char *speed, char *term, int console);
pid_t run_getty (char *tty, char *speed, char *term, int noclear, int console);
int run_parts (char *dir, char *cmd);
static inline void create(char *path, mode_t mode, uid_t uid, gid_t gid)
+6 -3
View File
@@ -44,11 +44,11 @@ static pid_t fallback = 0;
static LIST_HEAD(, tty_node) tty_list = LIST_HEAD_INITIALIZER();
/* tty [!1-9,S] <DEV> [BAUD[,BAUD,...]] [TERM] */
/* tty [!1-9,S] <DEV> [BAUD[,BAUD,...]] [TERM] [noclear] */
int tty_register(char *line)
{
tty_node_t *entry;
int insert = 0;
int insert = 0, noclear = 0;
char *tok, *dev = NULL, *baud = NULL;
char *runlevels = NULL, *term = NULL;
@@ -65,6 +65,8 @@ int tty_register(char *line)
dev = tok;
else if (isdigit(tok[0]))
baud = tok;
else if (!strcmp(tok, "noclear"))
noclear = 1;
else
term = tok;
@@ -87,6 +89,7 @@ int tty_register(char *line)
entry->data.name = strdup(dev);
entry->data.baud = baud ? strdup(baud) : NULL;
entry->data.term = term ? strdup(term) : NULL;
entry->data.noclear = noclear;
entry->data.runlevels = conf_parse_runlevels(runlevels);
_d("Registering tty %s at %s baud with term=%s on runlevels %s",
dev, baud ?: "NULL", term ?: "N/A", runlevels ?: "[2-5]");
@@ -212,7 +215,7 @@ void tty_start(finit_tty_t *tty)
return;
}
tty->pid = run_getty(dev, tty->baud, tty->term, is_console);
tty->pid = run_getty(dev, tty->baud, tty->term, tty->noclear, is_console);
}
void tty_stop(finit_tty_t *tty)
+1
View File
@@ -34,6 +34,7 @@ typedef struct {
char *name;
char *baud;
char *term;
int noclear;
int runlevels;
int pid;