From e48901b90f4ea9dd3e9ab5b638febe6f5feb6c2b Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 8 Jul 2017 15:31:59 +0200 Subject: [PATCH] tty: Clear tty before login: prompt by default, add 'noclear' option Signed-off-by: Joachim Nilsson --- doc/config.md | 2 +- src/exec.c | 6 +++--- src/getty.c | 11 +++++------ src/helpers.h | 2 +- src/tty.c | 9 ++++++--- src/tty.h | 1 + 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/doc/config.md b/doc/config.md index c89dde67..8d02154e 100644 --- a/doc/config.md +++ b/doc/config.md @@ -136,7 +136,7 @@ Syntax: * `include ` Include another configuration file. Absolute path required. -* `tty [LVLS] [BAUD] [TERM]` +* `tty [LVLS] [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 diff --git a/src/exec.c b/src/exec.c index 1afdf6a0..06a3e2b2 100644 --- a/src/exec.c +++ b/src/exec.c @@ -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; diff --git a/src/getty.c b/src/getty.c index b448c43c..92fb6084 100644 --- a/src/getty.c +++ b/src/getty.c @@ -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); diff --git a/src/helpers.h b/src/helpers.h index f0bed281..4c762850 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -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) diff --git a/src/tty.c b/src/tty.c index 5170ae50..c0406b6c 100644 --- a/src/tty.c +++ b/src/tty.c @@ -44,11 +44,11 @@ static pid_t fallback = 0; static LIST_HEAD(, tty_node) tty_list = LIST_HEAD_INITIALIZER(); -/* tty [!1-9,S] [BAUD[,BAUD,...]] [TERM] */ +/* tty [!1-9,S] [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) diff --git a/src/tty.h b/src/tty.h index 91943ac9..825089a1 100644 --- a/src/tty.h +++ b/src/tty.h @@ -34,6 +34,7 @@ typedef struct { char *name; char *baud; char *term; + int noclear; int runlevels; int pid;