mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07:00
tty: add support for 'passenv' flag to /bin/login
This change makes it possible tell the bundled/built-in getty to call /bin/login with the '-p' flag, to preserve any environment set in the Finit .conf files. Issue #286 Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+9
-2
@@ -49,6 +49,7 @@
|
||||
#endif
|
||||
|
||||
static long logname_len = 32; /* useradd(1) limit at 32 chars */
|
||||
static int passenv = 0; /* Set /bin/login -p or not */
|
||||
|
||||
/*
|
||||
* Read one character from stdin.
|
||||
@@ -185,7 +186,10 @@ static int do_login(char *name)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
execl(_PATH_LOGIN, _PATH_LOGIN, name, NULL);
|
||||
if (passenv)
|
||||
execl(_PATH_LOGIN, _PATH_LOGIN, "-p", name, NULL);
|
||||
else
|
||||
execl(_PATH_LOGIN, _PATH_LOGIN, name, NULL);
|
||||
|
||||
/*
|
||||
* Failed to exec login, should not happen on normal systems.
|
||||
@@ -252,11 +256,14 @@ int main(int argc, char *argv[])
|
||||
char *tty, *speed = "0", *term = NULL;
|
||||
int c;
|
||||
|
||||
while ((c = getopt(argc, argv, "h?")) != EOF) {
|
||||
while ((c = getopt(argc, argv, "h?p")) != EOF) {
|
||||
switch(c) {
|
||||
case 'h':
|
||||
case '?':
|
||||
return usage(0);
|
||||
case 'p':
|
||||
passenv = 1;
|
||||
break;
|
||||
default:
|
||||
return usage(1);
|
||||
}
|
||||
|
||||
@@ -154,6 +154,7 @@ char *tty_atcon(void)
|
||||
int tty_parse_args(char *cmd, struct tty *tty)
|
||||
{
|
||||
char *dev = NULL;
|
||||
int passenv = 0;
|
||||
size_t i;
|
||||
|
||||
do {
|
||||
@@ -165,6 +166,8 @@ int tty_parse_args(char *cmd, struct tty *tty)
|
||||
tty->nologin = 1;
|
||||
else if (!strcmp(cmd, "notty"))
|
||||
tty->notty = 1; /* for board bringup */
|
||||
else if (!strcmp(cmd, "passenv"))
|
||||
passenv = 1;
|
||||
else if (!strcmp(cmd, "rescue"))
|
||||
tty->rescue = 1; /* for rescue shells */
|
||||
else if (whichp(cmd)) /* in $PATH? */
|
||||
@@ -228,8 +231,15 @@ int tty_parse_args(char *cmd, struct tty *tty)
|
||||
tty->dev, tty->baud ?: "0", tty->term ?: "N/A");
|
||||
|
||||
/* Built-in getty now comes as standalone program */
|
||||
if (!tty->cmd)
|
||||
if (!tty->cmd) {
|
||||
if (passenv && tty->num < NELEMS(tty->args)) {
|
||||
for (i = tty->num; i > 0; i--)
|
||||
tty->args[i] = tty->args[i - 1];
|
||||
tty->args[0] = "-p";
|
||||
tty->num++;
|
||||
}
|
||||
tty->cmd = _PATH_GETTY;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user