mirror of
https://github.com/troglobit/finit.git
synced 2026-11-27 20:48:24 +00:00
Fix #79: Add 'nowait' option to tty setting, external getty
This patch makes it possible to disable the "Please press Enter" prompt when using an external getty. Simply append `nowait` to the .conf entry and Finit will spawn the getty immediately. A future patch will add support for `noclear` as well to external getty, as well as a change in default (=> `wait`) for the built-in getty. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
2fe257b7af
commit
f273ecc135
4 files changed
+56
-35
No files matched your search
+29
-18
@@ -240,7 +240,34 @@ pid_t run_getty(char *tty, char *speed, char *term, int noclear, int console)
|
|||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t run_getty2(char *tty, char *cmd, char *args[], int console)
|
static int activate_console(int nowait)
|
||||||
|
{
|
||||||
|
if (nowait)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
while (!fexist(SYNC_SHUTDOWN)) {
|
||||||
|
char c;
|
||||||
|
static const char msg[] = "\nPlease press Enter to activate this console.";
|
||||||
|
|
||||||
|
if (fexist(SYNC_STOPPED)) {
|
||||||
|
sleep(5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)write(STDERR_FILENO, msg, sizeof(msg));
|
||||||
|
while (read(STDIN_FILENO, &c, 1) == 1 && c != '\n')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (fexist(SYNC_STOPPED))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_t run_getty2(char *tty, char *cmd, char *args[], int nowait, int console)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
@@ -274,24 +301,8 @@ pid_t run_getty2(char *tty, char *cmd, char *args[], int console)
|
|||||||
if (ioctl(STDIN_FILENO, TIOCSCTTY, 1) < 0)
|
if (ioctl(STDIN_FILENO, TIOCSCTTY, 1) < 0)
|
||||||
_pe("Failed TIOCSCTTY");
|
_pe("Failed TIOCSCTTY");
|
||||||
|
|
||||||
while (!fexist(SYNC_SHUTDOWN)) {
|
if (activate_console(nowait))
|
||||||
char c;
|
|
||||||
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;
|
|
||||||
|
|
||||||
_exit(execv(cmd, args));
|
_exit(execv(cmd, args));
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
vhangup();
|
vhangup();
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ int complete (char *cmd, int pid);
|
|||||||
int run (char *cmd);
|
int run (char *cmd);
|
||||||
int run_interactive (char *cmd, char *fmt, ...);
|
int run_interactive (char *cmd, char *fmt, ...);
|
||||||
pid_t run_getty (char *tty, char *speed, char *term, int noclear, int console);
|
pid_t run_getty (char *tty, char *speed, char *term, int noclear, int console);
|
||||||
pid_t run_getty2 (char *tty, char *cmd, char *args[], int console);
|
pid_t run_getty2 (char *tty, char *cmd, char *args[], int nowait, int console);
|
||||||
int run_parts (char *dir, char *cmd);
|
int run_parts (char *dir, char *cmd);
|
||||||
|
|
||||||
static inline void create(char *path, mode_t mode, uid_t uid, gid_t gid)
|
static inline void create(char *path, mode_t mode, uid_t uid, gid_t gid)
|
||||||
|
|||||||
@@ -115,12 +115,12 @@ void tty_sweep(void)
|
|||||||
* a leading '/dev' is encountered the remaining options must be in
|
* a leading '/dev' is encountered the remaining options must be in
|
||||||
* the following sequence:
|
* the following sequence:
|
||||||
*
|
*
|
||||||
* tty [!1-9,S] <DEV> [BAUD[,BAUD,...]] [TERM] [noclear]
|
* tty [!1-9,S] <DEV> [BAUD[,BAUD,...]] [TERM] [noclear] [nowait]
|
||||||
*
|
*
|
||||||
* Otherwise the leading prefix must be the full path to an existing
|
* Otherwise the leading prefix must be the full path to an existing
|
||||||
* getty implementation, with it's arguments following:
|
* getty implementation, with it's arguments following:
|
||||||
*
|
*
|
||||||
* tty [!1-9,S] </path/to/getty> [ARGS]
|
* tty [!1-9,S] </path/to/getty> [ARGS] [noclear] [nowait]
|
||||||
*
|
*
|
||||||
* Different getty implementations prefer the TTY device argument in
|
* Different getty implementations prefer the TTY device argument in
|
||||||
* different order, so take care to investigate this first.
|
* different order, so take care to investigate this first.
|
||||||
@@ -128,7 +128,7 @@ void tty_sweep(void)
|
|||||||
int tty_register(char *line, struct timeval *mtime)
|
int tty_register(char *line, struct timeval *mtime)
|
||||||
{
|
{
|
||||||
tty_node_t *entry;
|
tty_node_t *entry;
|
||||||
int insert = 0, noclear = 0;
|
int insert = 0, noclear = 0, nowait = 0;
|
||||||
size_t i, num = 0;
|
size_t i, num = 0;
|
||||||
char *tok, *cmd = NULL, *args[TTY_MAX_ARGS];
|
char *tok, *cmd = NULL, *args[TTY_MAX_ARGS];
|
||||||
char *dev = NULL, *baud = NULL;
|
char *dev = NULL, *baud = NULL;
|
||||||
@@ -146,12 +146,19 @@ int tty_register(char *line, struct timeval *mtime)
|
|||||||
*/
|
*/
|
||||||
tok = strtok(line, " \t");
|
tok = strtok(line, " \t");
|
||||||
while (tok && num < NELEMS(args)) {
|
while (tok && num < NELEMS(args)) {
|
||||||
args[num++] = tok;
|
if (!strcmp(tok, "noclear"))
|
||||||
|
noclear = 1;
|
||||||
|
else if (!strcmp(tok, "nowait"))
|
||||||
|
nowait = 1;
|
||||||
|
else
|
||||||
|
args[num++] = tok;
|
||||||
|
|
||||||
tok = strtok(NULL, " \t");
|
tok = strtok(NULL, " \t");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Iterate over all args, figure out if built-in or external */
|
/* Iterate over all args */
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
|
/* First, figure out if built-in or external */
|
||||||
if (!dev && !cmd) {
|
if (!dev && !cmd) {
|
||||||
if (args[i][0] == '[')
|
if (args[i][0] == '[')
|
||||||
runlevels = line;
|
runlevels = line;
|
||||||
@@ -168,25 +175,26 @@ int tty_register(char *line, struct timeval *mtime)
|
|||||||
|
|
||||||
/* Built-in getty args */
|
/* Built-in getty args */
|
||||||
if (dev) {
|
if (dev) {
|
||||||
if (isdigit(args[i][0]))
|
if (isdigit(args[i][0])) {
|
||||||
baud = tok;
|
baud = tok;
|
||||||
else if (!strcmp(args[i], "noclear"))
|
continue;
|
||||||
noclear = 1;
|
}
|
||||||
else
|
|
||||||
|
/*
|
||||||
|
* Last arg, if not anything else, is the value
|
||||||
|
* to be used for the TERM environment variable.
|
||||||
|
*/
|
||||||
|
if (i + 1 == num)
|
||||||
term = tok;
|
term = tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* External getty, figure out the device */
|
/* External getty, figure out the device */
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
if (!strncmp(args[i], "/dev", 4)) {
|
if (!strncmp(args[i], "/dev", 4))
|
||||||
dev = args[i];
|
dev = args[i];
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strncmp(args[i], "tty", 3)) {
|
if (!strncmp(args[i], "tty", 3))
|
||||||
dev = args[i];
|
dev = args[i];
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,6 +227,7 @@ int tty_register(char *line, struct timeval *mtime)
|
|||||||
entry->data.baud = baud ? strdup(baud) : NULL;
|
entry->data.baud = baud ? strdup(baud) : NULL;
|
||||||
entry->data.term = term ? strdup(term) : NULL;
|
entry->data.term = term ? strdup(term) : NULL;
|
||||||
entry->data.noclear = noclear;
|
entry->data.noclear = noclear;
|
||||||
|
entry->data.nowait = nowait;
|
||||||
entry->data.runlevels = conf_parse_runlevels(runlevels);
|
entry->data.runlevels = conf_parse_runlevels(runlevels);
|
||||||
|
|
||||||
/* External getty */
|
/* External getty */
|
||||||
@@ -374,7 +383,7 @@ void tty_start(finit_tty_t *tty)
|
|||||||
if (!tty->cmd)
|
if (!tty->cmd)
|
||||||
tty->pid = run_getty(dev, tty->baud, tty->term, tty->noclear, is_console);
|
tty->pid = run_getty(dev, tty->baud, tty->term, tty->noclear, is_console);
|
||||||
else
|
else
|
||||||
tty->pid = run_getty2(dev, tty->cmd, tty->args, is_console);
|
tty->pid = run_getty2(dev, tty->cmd, tty->args, tty->nowait, is_console);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tty_stop(finit_tty_t *tty)
|
void tty_stop(finit_tty_t *tty)
|
||||||
|
|||||||
Reference in new issue
Block a user