Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fbe4332e authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Set HOME, LOGNAME, SHELL, and USER from adbd.

Previously we've set these from /system/etc/mkshrc, which caused a behavioral
difference between interactive and non-interactive shells.

Bug: http://b/19635681
Change-Id: I4608c42dd3de821046220fdb1770ab3216b5d5eb
parent 46776e74
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@

#include <errno.h>
#include <pty.h>
#include <pwd.h>
#include <sys/select.h>
#include <termios.h>

@@ -281,6 +282,15 @@ bool Subprocess::ForkAndExec() {
        parent_error_sfd.Reset();
        close_on_exec(child_error_sfd.fd());

        // TODO: $HOSTNAME? Normally bash automatically sets that, but mksh doesn't.
        passwd* pw = getpwuid(getuid());
        if (pw != nullptr) {
            setenv("HOME", pw->pw_dir, 1);
            setenv("LOGNAME", pw->pw_name, 1);
            setenv("SHELL", pw->pw_shell, 1);
            setenv("USER", pw->pw_name, 1);
        }

        if (is_interactive()) {
            execl(_PATH_BSHELL, _PATH_BSHELL, "-", nullptr);
        } else {