Refactor default shell handling so it is done in a single place for a new windows and a new tab.

Use "/bin/sh -l" as the default command, and always pass -l ('login shell') to the user selected shell.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38173 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues 2010-08-17 07:53:58 +00:00
parent e71b4c11de
commit 6709e6bcb8
2 changed files with 18 additions and 19 deletions

View File

@ -15,6 +15,7 @@
#include <errno.h>
#include <fcntl.h>
#include <new>
#include <pwd.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
@ -58,6 +59,7 @@
#define CSWTCH 0
#endif
const char *kDefaultShell = "/bin/sh";
/*
* Set environment variable.
@ -335,10 +337,20 @@ initialize_termios(struct termios &tio)
status_t
Shell::_Spawn(int row, int col, const char *encoding, int argc, const char **argv)
{
const char *kDefaultShellCommand[] = { "/bin/bash", "--login", NULL };
if (argv == NULL || argc == 0) {
argv = kDefaultShellCommand;
const char *defaultArgs[2];
defaultArgs[0] = kDefaultShell;
defaultArgs[1] = "-l";
struct passwd passwdStruct;
struct passwd *passwdResult;
char stringBuffer[256];
if (!getpwuid_r(getuid(), &passwdStruct, stringBuffer,
sizeof(stringBuffer), &passwdResult)) {
defaultArgs[0] = passwdStruct.pw_shell;
}
argv = defaultArgs;
argc = 2;
}
@ -538,8 +550,8 @@ Shell::_Spawn(int row, int col, const char *encoding, int argc, const char **arg
int returnValue = system(alertCommand.String());
if (returnValue == 0) {
execl(kDefaultShellCommand[0], kDefaultShellCommand[0],
kDefaultShellCommand[1], NULL);
execl(kDefaultShell, kDefaultShell,
"-l", NULL);
}
exit(1);

View File

@ -10,7 +10,6 @@
#include "TermApp.h"
#include <errno.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@ -39,7 +38,6 @@
static bool sUsageRequested = false;
//static bool sGeometryRequested = false;
const char *kDefaultShell = "/bin/bash";
const ulong MSG_ACTIVATE_TERM = 'msat';
const ulong MSG_TERM_WINDOW_INFO = 'mtwi';
@ -63,19 +61,8 @@ TermApp::TermApp()
fTermWindow(NULL),
fArgs(NULL)
{
const char *defaultArgs[2];
defaultArgs[0] = kDefaultShell;
defaultArgs[1] = "--login";
struct passwd passwdStruct;
struct passwd *passwdResult;
char stringBuffer[256];
if (!getpwuid_r(getuid(), &passwdStruct, stringBuffer,
sizeof(stringBuffer), &passwdResult)) {
defaultArgs[0] = passwdStruct.pw_shell;
}
fArgs = new Arguments(2, defaultArgs);
fArgs = new Arguments(0, NULL);
fWindowTitle = B_TRANSLATE("Terminal");
_RegisterTerminal();