Fallback rescue mode handling

Before 4e5d06b the only way to go into rescue mode was to skip certain
steps and then attempt to load /lib/finit/rescue.conf.  After 4e5d06b
we keep the old handling as a fallback in case early sulogin fails.

The new tty option 'rescue' is added, which recue.conf is updated with.
This option implies notty mode and will try sulogin (again) before it
falls back to start /bin/sh as a login shell.

The reason we keep this is to be able to handle all possible use-cases
and also allow sysadmins to set up the behavior that fits their needs.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2021-04-25 22:10:42 +02:00
parent 666cae6f49
commit 679b4df881
6 changed files with 22 additions and 11 deletions
+1 -1
View File
@@ -672,7 +672,7 @@ int conf_reload(void)
if (rescue) {
int rc;
char line[80] = "tty [12345] @console noclear nologin";
char line[80] = "tty [12345] rescue";
/* If rescue.conf is missing, fall back to a root shell */
rc = parse_conf(RESCUE_CONF, 0);
+1 -2
View File
@@ -1,3 +1,2 @@
runlevel 1
hostname rescue
tty [12345] @console noclear nologin
tty [12345] rescue
+1
View File
@@ -1301,6 +1301,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
svc->nowait = tty.nowait;
svc->nologin = tty.nologin;
svc->notty = tty.notty;
svc->rescue = tty.rescue;
/* TTYs cannot be redirected */
log = NULL;
+1
View File
@@ -149,6 +149,7 @@ typedef struct svc {
char nowait;
char nologin;
char notty;
char rescue;
};
};
+17 -8
View File
@@ -158,7 +158,9 @@ int tty_parse_args(char *cmd, struct tty *tty)
else if (!strcmp(cmd, "nologin"))
tty->nologin = 1;
else if (!strcmp(cmd, "notty"))
tty->notty = 1; /* for rescue shells */
tty->notty = 1; /* for board bringup */
else if (!strcmp(cmd, "rescue"))
tty->rescue = 1; /* for rescue shells */
else if (!access(cmd, X_OK))
tty->cmd = cmd;
else
@@ -167,6 +169,10 @@ int tty_parse_args(char *cmd, struct tty *tty)
cmd = strtok(NULL, " \t");
} while (cmd && tty->num < NELEMS(tty->args));
/* rescue shells are always notty */
if (tty->rescue)
tty->notty = 1;
/* skip /dev probe, we just want a bríngup shell */
if (tty->notty)
return 0;
@@ -242,12 +248,15 @@ int tty_exec(svc_t *svc)
/* try to protect system with sulogin, fall back to root shell */
if (svc->notty) {
/* util-linux or busybox, no args for compat */
if (whichp("sulogin"))
return execlp("sulogin", "sulogin", NULL);
/* check if bundled one is available */
if (whichp(_PATH_SULOGIN) && !systemf(_PATH_SULOGIN))
_exit(0);
if (svc->rescue) {
/* check if bundled one is available */
if (whichp(_PATH_SULOGIN))
return execl(_PATH_SULOGIN, _PATH_SULOGIN, NULL);
/* util-linux or busybox, no args for compat */
if (whichp("sulogin"))
return execlp("sulogin", "sulogin", NULL);
}
/*
* Become session leader and set controlling TTY
@@ -257,7 +266,7 @@ int tty_exec(svc_t *svc)
ioctl(STDIN_FILENO, TIOCSCTTY, 1);
prctl(PR_SET_NAME, "finitsh", 0, 0, 0);
return execl(_PATH_BSHELL, _PATH_BSHELL, NULL);
return execl(_PATH_BSHELL, "-sh", NULL);
}
dev = tty_canonicalize(svc->dev);
+1
View File
@@ -40,6 +40,7 @@ struct tty {
char nowait;
char nologin;
char notty;
char rescue;
};
char *tty_canonicalize (char *dev);