mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07: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:
@@ -243,11 +243,17 @@ static int parse_conf(char *file)
|
||||
|
||||
int parse_finit_conf(char *file)
|
||||
{
|
||||
int result;
|
||||
|
||||
username = strdup(DEFUSER);
|
||||
hostname = strdup(DEFHOST);
|
||||
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 <fcntl.h>
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
@@ -35,41 +36,45 @@
|
||||
|
||||
/* Distribution specific configuration */
|
||||
#if defined EMBEDDED_SYSTEM
|
||||
# define CONSOLE "/dev/console"
|
||||
# define SETUP_DEVFS "/sbin/mdev -s"
|
||||
# define GETTY "/sbin/getty -L"
|
||||
# define CONSOLE _PATH_CONSOLE
|
||||
# define SETUP_DEVFS "/sbin/mdev -s"
|
||||
# define GETTY "/sbin/getty -L"
|
||||
# define GETTY_BUSYBOX
|
||||
# define BAUDRATE 115200
|
||||
# define RUNLEVEL 2
|
||||
# define BAUDRATE 115200
|
||||
# define RUNLEVEL 2
|
||||
#else /* Debian/Ubuntu based distributions */
|
||||
# define CONSOLE "/dev/tty1"
|
||||
# define SETUP_DEVFS "/sbin/udevd --daemon"
|
||||
# define GETTY "/sbin/getty -8"
|
||||
# define CONSOLE "/dev/tty1"
|
||||
# define SETUP_DEVFS "/sbin/udevd --daemon"
|
||||
# define GETTY "/sbin/getty -8"
|
||||
# define GETTY_AGETTY
|
||||
# define BAUDRATE 38400
|
||||
# define RUNLEVEL 2
|
||||
# define RANDOMSEED "/var/lib/urandom/random-seed"
|
||||
# define BAUDRATE 38400
|
||||
# define RUNLEVEL 2
|
||||
# define RANDOMSEED "/var/lib/urandom/random-seed"
|
||||
# define REMOUNT_ROOTFS_RW
|
||||
# define HAVE_DBUS
|
||||
#endif
|
||||
|
||||
#ifndef FALLBACK_SHELL
|
||||
# define FALLBACK_SHELL _PATH_BSHELL
|
||||
#endif
|
||||
|
||||
#ifndef DEFUSER
|
||||
# define DEFUSER "root"
|
||||
# define DEFUSER "root"
|
||||
#endif
|
||||
#ifndef DEFHOST
|
||||
# define DEFHOST "noname"
|
||||
# define DEFHOST "noname"
|
||||
#endif
|
||||
|
||||
/* Delay start of GETTY at boot. Must be > 0 */
|
||||
#define DELAY_TTY 2
|
||||
#define DELAY_TTY 2
|
||||
|
||||
#define CMD_SIZE 256
|
||||
#define LINE_SIZE 1024
|
||||
#define BUF_SIZE 4096
|
||||
#define CMD_SIZE 256
|
||||
#define LINE_SIZE 1024
|
||||
#define BUF_SIZE 4096
|
||||
|
||||
#define INIT_MAGIC 0x03091969
|
||||
#define INIT_CMD_RUNLVL 1
|
||||
#define INIT_CMD_DEBUG 2
|
||||
#define INIT_MAGIC 0x03091969
|
||||
#define INIT_CMD_RUNLVL 1
|
||||
#define INIT_CMD_DEBUG 2
|
||||
|
||||
struct init_request {
|
||||
int magic; /* Magic number */
|
||||
|
||||
@@ -58,21 +58,21 @@ typedef struct svc {
|
||||
pid_t pid;
|
||||
svc_type_t type;
|
||||
int reload;
|
||||
int runlevels;
|
||||
int runlevels;
|
||||
unsigned int restart_counter; /* Incremented for each restart by service monitor. */
|
||||
char cmd[MAX_ARG_LEN];
|
||||
char args[MAX_NUM_SVC_ARGS][MAX_ARG_LEN];
|
||||
char desc[MAX_STR_LEN];
|
||||
char username[MAX_USER_LEN];
|
||||
char username[MAX_USER_LEN];
|
||||
|
||||
/* For external plugins. If @cb is set a plugin is loaded.
|
||||
* @dynamic: Set by plugins that want dynamic events.
|
||||
* @dynamic: Set by plugins that want dynamic events.
|
||||
* @dynamic_stop: Set by plugins that allow dyn. events to stop it as well.
|
||||
* @private: Can be used freely by plugin, e.g., to store "states".
|
||||
* @private: Can be used freely by plugin, e.g., to store "states".
|
||||
*/
|
||||
int dynamic;
|
||||
int dynamic_stop;
|
||||
int private;
|
||||
int dynamic;
|
||||
int dynamic_stop;
|
||||
int private;
|
||||
svc_cmd_t (*cb)(struct svc *svc, int event, void *event_arg);
|
||||
} svc_t;
|
||||
|
||||
@@ -93,18 +93,18 @@ static inline svc_t *finit_svc_connect(void)
|
||||
return (svc_t *)ptr;
|
||||
}
|
||||
|
||||
svc_t *svc_new (void);
|
||||
svc_t *svc_find (char *name);
|
||||
svc_t *svc_iterator (int restart);
|
||||
void svc_runlevel (int newlevel);
|
||||
svc_t *svc_new (void);
|
||||
svc_t *svc_find (char *name);
|
||||
svc_t *svc_iterator (int restart);
|
||||
void svc_runlevel (int newlevel);
|
||||
|
||||
int svc_register (int type, char *line, char *username);
|
||||
int svc_id_by_name (char *name);
|
||||
int svc_register (int type, char *line, char *username);
|
||||
int svc_id_by_name (char *name);
|
||||
svc_cmd_t svc_enabled (svc_t *svc, int event, void *arg);
|
||||
int svc_start (svc_t *svc);
|
||||
int svc_start_by_name (char *name);
|
||||
int svc_stop (svc_t *svc);
|
||||
int svc_reload (svc_t *svc);
|
||||
int svc_start (svc_t *svc);
|
||||
int svc_start_by_name (char *name);
|
||||
int svc_stop (svc_t *svc);
|
||||
int svc_reload (svc_t *svc);
|
||||
|
||||
#endif /* FINIT_SVC_H_ */
|
||||
|
||||
|
||||
@@ -102,6 +102,17 @@ tty_node_t *tty_find(char *dev)
|
||||
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 *entry;
|
||||
@@ -127,13 +138,17 @@ void tty_start(finit_tty_t *tty)
|
||||
if (console && !strcmp(tty->name, console))
|
||||
is_console = 1;
|
||||
|
||||
if (!strcmp(tty->name, _PATH_DEV)) {
|
||||
#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)
|
||||
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
|
||||
#error No GETTY defined!
|
||||
strlcpy(line, FALLBACK_CONSOLE, sizeof(line));
|
||||
#endif
|
||||
} else {
|
||||
strlcpy(line, tty->name, sizeof(line));
|
||||
}
|
||||
cmd = strtok(line, " ");
|
||||
args[i++] = basename(cmd);
|
||||
while ((arg = strtok(NULL, " ")))
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
typedef struct {
|
||||
char *name;
|
||||
int baud;
|
||||
char *term;
|
||||
char *term;
|
||||
int runlevels;
|
||||
|
||||
int pid;
|
||||
@@ -45,14 +45,15 @@ typedef struct tty_node {
|
||||
|
||||
//extern LIST_HEAD(, tty_node) tty_list;
|
||||
|
||||
int tty_register (char *line);
|
||||
tty_node_t *tty_find (char *dev);
|
||||
int tty_register (char *line);
|
||||
tty_node_t *tty_find (char *dev);
|
||||
size_t tty_num (void);
|
||||
tty_node_t *tty_find_by_pid (pid_t pid);
|
||||
void tty_start (finit_tty_t *tty);
|
||||
void tty_stop (finit_tty_t *tty);
|
||||
int tty_enabled (finit_tty_t *tty, int runlevel);
|
||||
int tty_respawn (pid_t pid);
|
||||
void tty_runlevel (int runlevel);
|
||||
void tty_start (finit_tty_t *tty);
|
||||
void tty_stop (finit_tty_t *tty);
|
||||
int tty_enabled (finit_tty_t *tty, int runlevel);
|
||||
int tty_respawn (pid_t pid);
|
||||
void tty_runlevel (int runlevel);
|
||||
|
||||
#endif /* FINIT_TTY_H_ */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user