diff --git a/src/exec.c b/src/exec.c index 44a8b107..87fcbd6c 100644 --- a/src/exec.c +++ b/src/exec.c @@ -34,6 +34,7 @@ #include /* Not included by default in musl libc */ #include #include +#include #include "finit.h" #include "cgroup.h" @@ -240,7 +241,7 @@ int exec_runtask(char *cmd, char *args[]) static void prepare_tty(char *tty, speed_t speed, char *procname, struct rlimit rlimit[]) { char name[80]; - int fd; + int fd, dummy; fd = open(tty, O_RDWR); if (fd < 0) { @@ -251,12 +252,18 @@ static void prepare_tty(char *tty, speed_t speed, char *procname, struct rlimit dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); - close(fd); + + /* Set default TERM, run_getty() below allows override */ + if (ioctl(fd, VT_OPENQRY, &dummy) == -1) + setenv("TERM", "vt102", 1); /* likely a serial line */ + else + setenv("TERM", "linux", 1); /* * Reset to sane defaults in case of messup from prev. session */ - stty(STDIN_FILENO, speed); + stty(fd, speed); + close(fd); /* Set configured limits */ for (int i = 0; i < RLIMIT_NLIMITS; i++) { diff --git a/src/finit.c b/src/finit.c index 46c34368..c08ca4b6 100644 --- a/src/finit.c +++ b/src/finit.c @@ -525,6 +525,8 @@ int main(int argc, char *argv[]) */ setenv("PATH", _PATH_STDPATH, 1); setenv("SHELL", _PATH_BSHELL, 1); + setenv("LOGNAME", "root", 1); + setenv("USER", "root", 1); if (chdir("/")) _pe("Failed cd /");