From 0975f16f7ca94b654cb6a55b3316daae89843abb Mon Sep 17 00:00:00 2001 From: Jessica Hamilton Date: Wed, 10 Jun 2015 15:54:59 +1200 Subject: [PATCH] setarch: use a login shell; fixes #12066. * This also updates /etc/profile to detect whether our parent process is a shell, and changes the banner message accordingly. * Also, pipe errors to /dev/null, in case grep is not installed; this allows us to not require grep as a dependency, and let the banner message do the right thing. --- data/etc/profile | 7 ++++++- src/bin/setarch.cpp | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/data/etc/profile b/data/etc/profile index 865d360e0c..74b22693a7 100644 --- a/data/etc/profile +++ b/data/etc/profile @@ -3,7 +3,12 @@ # Place user customizations in /.profile # -echo -e "\nWelcome to the Haiku shell.\n" +ps |& grep -e $PPID |& grep -e $SHELL |& grep -q -e $PPID > /dev/null 2>&1 +if [ $? -eq 1 ] ; then + echo -e "\nWelcome to the Haiku shell.\n" +else + echo -e "\nSwitching to architecture `getarch`\n" +fi export USER=`id -un` export GROUP=`id -gn` diff --git a/src/bin/setarch.cpp b/src/bin/setarch.cpp index 567e7541f4..5f476347d3 100644 --- a/src/bin/setarch.cpp +++ b/src/bin/setarch.cpp @@ -237,13 +237,14 @@ main(int argc, const char* const* argv) } // if no command is given, get the user's shell - const char* shellCommand[2]; + const char* shellCommand[3]; if (commandArgs == NULL) { struct passwd* pwd = getpwuid(geteuid()); shellCommand[0] = pwd != NULL ? pwd->pw_shell : "/bin/sh"; - shellCommand[1] = NULL; + shellCommand[1] = "-l"; + shellCommand[2] = NULL; commandArgs = shellCommand; - commandArgCount = 1; + commandArgCount = 2; } // exec the command