mirror of
https://github.com/troglobit/finit.git
synced 2026-10-17 10:49:34 +00:00
Add support for a fallback shell if no tty is setup
Try to do better by the user, by default, if no tty is specified in the finit.conf. This way the user will at least have a way to interact with the system and repair it. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
62287f8fcc
commit
f6f2895524
4 files changed
+30
-3
No files matched your search
@@ -243,11 +243,17 @@ static int parse_conf(char *file)
|
|||||||
|
|
||||||
int parse_finit_conf(char *file)
|
int parse_finit_conf(char *file)
|
||||||
{
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
username = strdup(DEFUSER);
|
username = strdup(DEFUSER);
|
||||||
hostname = strdup(DEFHOST);
|
hostname = strdup(DEFHOST);
|
||||||
rcsd = strdup(FINIT_RCSD);
|
rcsd = strdup(FINIT_RCSD);
|
||||||
|
|
||||||
return parse_conf(file);
|
result = parse_conf(file);
|
||||||
|
if (!tty_num())
|
||||||
|
tty_register(FALLBACK_SHELL);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <paths.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -35,7 +36,7 @@
|
|||||||
|
|
||||||
/* Distribution specific configuration */
|
/* Distribution specific configuration */
|
||||||
#if defined EMBEDDED_SYSTEM
|
#if defined EMBEDDED_SYSTEM
|
||||||
# define CONSOLE "/dev/console"
|
# define CONSOLE _PATH_CONSOLE
|
||||||
# define SETUP_DEVFS "/sbin/mdev -s"
|
# define SETUP_DEVFS "/sbin/mdev -s"
|
||||||
# define GETTY "/sbin/getty -L"
|
# define GETTY "/sbin/getty -L"
|
||||||
# define GETTY_BUSYBOX
|
# define GETTY_BUSYBOX
|
||||||
@@ -53,6 +54,10 @@
|
|||||||
# define HAVE_DBUS
|
# define HAVE_DBUS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef FALLBACK_SHELL
|
||||||
|
# define FALLBACK_SHELL _PATH_BSHELL
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef DEFUSER
|
#ifndef DEFUSER
|
||||||
# define DEFUSER "root"
|
# define DEFUSER "root"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -102,6 +102,17 @@ tty_node_t *tty_find(char *dev)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t tty_num(void)
|
||||||
|
{
|
||||||
|
size_t num = 0;
|
||||||
|
tty_node_t *entry;
|
||||||
|
|
||||||
|
LIST_FOREACH(entry, &tty_list, link)
|
||||||
|
num++;
|
||||||
|
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
tty_node_t *tty_find_by_pid(pid_t pid)
|
tty_node_t *tty_find_by_pid(pid_t pid)
|
||||||
{
|
{
|
||||||
tty_node_t *entry;
|
tty_node_t *entry;
|
||||||
@@ -127,13 +138,17 @@ void tty_start(finit_tty_t *tty)
|
|||||||
if (console && !strcmp(tty->name, console))
|
if (console && !strcmp(tty->name, console))
|
||||||
is_console = 1;
|
is_console = 1;
|
||||||
|
|
||||||
|
if (!strcmp(tty->name, _PATH_DEV)) {
|
||||||
#if defined(GETTY_AGETTY)
|
#if defined(GETTY_AGETTY)
|
||||||
snprintf(line, sizeof(line), "%s %s %d %s", GETTY, tty->name, tty->baud, tty->term ?: "");
|
snprintf(line, sizeof(line), "%s %s %d %s", GETTY, tty->name, tty->baud, tty->term ?: "");
|
||||||
#elif defined(GETTY_BUSYBOX)
|
#elif defined(GETTY_BUSYBOX)
|
||||||
snprintf(line, sizeof(line), "%s %d %s %s", GETTY, tty->baud, tty->name, tty->term ?: "");
|
snprintf(line, sizeof(line), "%s %d %s %s", GETTY, tty->baud, tty->name, tty->term ?: "");
|
||||||
#else
|
#else
|
||||||
#error No GETTY defined!
|
strlcpy(line, FALLBACK_CONSOLE, sizeof(line));
|
||||||
#endif
|
#endif
|
||||||
|
} else {
|
||||||
|
strlcpy(line, tty->name, sizeof(line));
|
||||||
|
}
|
||||||
cmd = strtok(line, " ");
|
cmd = strtok(line, " ");
|
||||||
args[i++] = basename(cmd);
|
args[i++] = basename(cmd);
|
||||||
while ((arg = strtok(NULL, " ")))
|
while ((arg = strtok(NULL, " ")))
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ typedef struct tty_node {
|
|||||||
|
|
||||||
int tty_register (char *line);
|
int tty_register (char *line);
|
||||||
tty_node_t *tty_find (char *dev);
|
tty_node_t *tty_find (char *dev);
|
||||||
|
size_t tty_num (void);
|
||||||
tty_node_t *tty_find_by_pid (pid_t pid);
|
tty_node_t *tty_find_by_pid (pid_t pid);
|
||||||
void tty_start (finit_tty_t *tty);
|
void tty_start (finit_tty_t *tty);
|
||||||
void tty_stop (finit_tty_t *tty);
|
void tty_stop (finit_tty_t *tty);
|
||||||
|
|||||||
Reference in new issue
Block a user