* Removed the shell process ID from ActiveProcessInfo and moved it to new class

ShellInfo, which also contains a flag whether the shell is the default shell.
* If the Terminal has been started with a custom shell, also replace "%p" in
  the title by its name, when active.
* Also show the on-close alert for the custom shell.

Fixes #6844.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39573 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2010-11-22 15:30:26 +00:00
parent 65b57677b5
commit ca598670fb
12 changed files with 122 additions and 36 deletions
+1 -4
View File
@@ -10,7 +10,6 @@
ActiveProcessInfo::ActiveProcessInfo() ActiveProcessInfo::ActiveProcessInfo()
: :
fID(-1), fID(-1),
fShellID(-1),
fName(), fName(),
fCurrentDirectory() fCurrentDirectory()
{ {
@@ -18,11 +17,10 @@ ActiveProcessInfo::ActiveProcessInfo()
void void
ActiveProcessInfo::SetTo(pid_t id, pid_t shellID, const BString& name, ActiveProcessInfo::SetTo(pid_t id, const BString& name,
const BString& currentDirectory) const BString& currentDirectory)
{ {
fID = id; fID = id;
fShellID = shellID;
fName = name; fName = name;
fCurrentDirectory = currentDirectory; fCurrentDirectory = currentDirectory;
} }
@@ -32,7 +30,6 @@ void
ActiveProcessInfo::Unset() ActiveProcessInfo::Unset()
{ {
fID = -1; fID = -1;
fShellID = -1;
fName = BString(); fName = BString();
fCurrentDirectory = BString(); fCurrentDirectory = BString();
} }
+1 -4
View File
@@ -14,15 +14,13 @@ class ActiveProcessInfo {
public: public:
ActiveProcessInfo(); ActiveProcessInfo();
void SetTo(pid_t id, pid_t shellID, void SetTo(pid_t id, const BString& name,
const BString& name,
const BString& currentDirectory); const BString& currentDirectory);
void Unset(); void Unset();
bool IsValid() const { return fID >= 0; } bool IsValid() const { return fID >= 0; }
pid_t ID() const { return fID; } pid_t ID() const { return fID; }
pid_t ShellProcessID() const { return fShellID; }
const BString& Name() const { return fName; } const BString& Name() const { return fName; }
const BString& CurrentDirectory() const const BString& CurrentDirectory() const
@@ -30,7 +28,6 @@ public:
private: private:
pid_t fID; pid_t fID;
pid_t fShellID;
BString fName; BString fName;
BString fCurrentDirectory; BString fCurrentDirectory;
}; };
+1
View File
@@ -22,6 +22,7 @@ Application Terminal :
PrefWindow.cpp PrefWindow.cpp
SetTitleDialog.cpp SetTitleDialog.cpp
Shell.cpp Shell.cpp
ShellInfo.cpp
ShellParameters.cpp ShellParameters.cpp
SmartTabView.cpp SmartTabView.cpp
TermApp.cpp TermApp.cpp
+13 -9
View File
@@ -126,7 +126,6 @@ typedef struct
Shell::Shell() Shell::Shell()
: :
fFd(-1), fFd(-1),
fProcessID(-1),
fTermParse(NULL), fTermParse(NULL),
fAttached(false) fAttached(false)
{ {
@@ -167,8 +166,8 @@ Shell::Close()
if (fFd >= 0) { if (fFd >= 0) {
close(fFd); close(fFd);
kill(-fProcessID, SIGHUP); kill(-fShellInfo.ProcessID(), SIGHUP);
fProcessID = -1; fShellInfo.SetProcessID(-1);
int status; int status;
wait(&status); wait(&status);
fFd = -1; fFd = -1;
@@ -244,7 +243,7 @@ bool
Shell::HasActiveProcesses() const Shell::HasActiveProcesses() const
{ {
pid_t running = tcgetpgrp(fFd); pid_t running = tcgetpgrp(fFd);
if (running == fProcessID || running == -1) if (running == fShellInfo.ProcessID() || running == -1)
return false; return false;
return true; return true;
@@ -284,7 +283,7 @@ Shell::GetActiveProcessInfo(ActiveProcessInfo& _info) const
return false; return false;
// set the result // set the result
_info.SetTo(process, fProcessID, name, cwdPath.Path()); _info.SetTo(process, name, cwdPath.Path());
return true; return true;
} }
@@ -391,6 +390,7 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters)
struct passwd passwdStruct; struct passwd passwdStruct;
struct passwd *passwdResult; struct passwd *passwdResult;
char stringBuffer[256]; char stringBuffer[256];
if (argv == NULL || argc == 0) { if (argv == NULL || argc == 0) {
if (!getpwuid_r(getuid(), &passwdStruct, stringBuffer, if (!getpwuid_r(getuid(), &passwdStruct, stringBuffer,
sizeof(stringBuffer), &passwdResult)) { sizeof(stringBuffer), &passwdResult)) {
@@ -399,7 +399,10 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters)
argv = defaultArgs; argv = defaultArgs;
argc = 2; argc = 2;
}
fShellInfo.SetDefaultShell(true);
} else
fShellInfo.SetDefaultShell(false);
signal(SIGTTOU, SIG_IGN); signal(SIGTTOU, SIG_IGN);
@@ -427,14 +430,15 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters)
thread_id terminalThread = find_thread(NULL); thread_id terminalThread = find_thread(NULL);
/* Fork a child process. */ /* Fork a child process. */
if ((fProcessID = fork()) < 0) { fShellInfo.SetProcessID(fork());
if (fShellInfo.ProcessID() < 0) {
close(master); close(master);
return B_ERROR; return B_ERROR;
} }
handshake_t handshake; handshake_t handshake;
if (fProcessID == 0) { if (fShellInfo.ProcessID() == 0) {
// Now in child process. // Now in child process.
// close the PTY master side // close the PTY master side
@@ -595,7 +599,7 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters)
handshake.row = row; handshake.row = row;
handshake.col = col; handshake.col = col;
handshake.status = PTY_WS; handshake.status = PTY_WS;
send_handshake_message(fProcessID, handshake); send_handshake_message(fShellInfo.ProcessID(), handshake);
break; break;
} }
} }
+6 -2
View File
@@ -14,7 +14,7 @@
#define _SHELL_H #define _SHELL_H
#include <SupportDefs.h> #include "ShellInfo.h"
class ActiveProcessInfo; class ActiveProcessInfo;
@@ -44,7 +44,10 @@ public:
status_t SetAttr(const struct termios& attr); status_t SetAttr(const struct termios& attr);
int FD() const; int FD() const;
pid_t ProcessID() const { return fProcessID; } pid_t ProcessID() const
{ return fShellInfo.ProcessID(); }
const ShellInfo& Info() const
{ return fShellInfo; }
bool HasActiveProcesses() const; bool HasActiveProcesses() const;
bool GetActiveProcessInfo( bool GetActiveProcessInfo(
@@ -58,6 +61,7 @@ private:
const ShellParameters& parameters); const ShellParameters& parameters);
private: private:
ShellInfo fShellInfo;
int fFd; int fFd;
pid_t fProcessID; pid_t fProcessID;
TermParse* fTermParse; TermParse* fTermParse;
+15
View File
@@ -0,0 +1,15 @@
/*
* Copyright 2010, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#include "ShellInfo.h"
ShellInfo::ShellInfo()
:
fProcessID(-1),
fIsDefaultShell(true)
{
}
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright 2010, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef SHELL_INFO_H
#define SHELL_INFO_H
#include <OS.h>
class ShellInfo {
public:
ShellInfo();
pid_t ProcessID() const
{ return fProcessID; }
void SetProcessID(pid_t processID)
{ fProcessID = processID; }
bool IsDefaultShell() const
{ return fIsDefaultShell; }
void SetDefaultShell(bool isDefault)
{ fIsDefaultShell = isDefault; }
private:
pid_t fProcessID;
bool fIsDefaultShell;
};
#endif // SHELL_INFO_H
+13
View File
@@ -661,6 +661,19 @@ TermView::GetActiveProcessInfo(ActiveProcessInfo& _info) const
} }
bool
TermView::GetShellInfo(ShellInfo& _info) const
{
if (fShell == NULL) {
_info = ShellInfo();
return false;
}
_info = fShell->Info();
return true;
}
/* static */ /* static */
BArchivable * BArchivable *
TermView::Instantiate(BMessage* data) TermView::Instantiate(BMessage* data)
+2
View File
@@ -31,6 +31,7 @@ class BStringView;
class BasicTerminalBuffer; class BasicTerminalBuffer;
class InlineInput; class InlineInput;
class ResizeWindow; class ResizeWindow;
class ShellInfo;
class ShellParameters; class ShellParameters;
class TermBuffer; class TermBuffer;
class TerminalBuffer; class TerminalBuffer;
@@ -58,6 +59,7 @@ public:
bool IsShellBusy() const; bool IsShellBusy() const;
bool GetActiveProcessInfo( bool GetActiveProcessInfo(
ActiveProcessInfo& _info) const; ActiveProcessInfo& _info) const;
bool GetShellInfo(ShellInfo& _info) const;
const char* TerminalName() const; const char* TerminalName() const;
+21 -8
View File
@@ -302,17 +302,25 @@ TermWindow::_CanClose(int32 index)
// all names, separated by "\n\t" // all names, separated by "\n\t"
if (index != -1) { if (index != -1) {
ShellInfo shellInfo;
ActiveProcessInfo info; ActiveProcessInfo info;
if (_TermViewAt(index)->GetActiveProcessInfo(info) TermView* termView = _TermViewAt(index);
&& info.ID() != info.ShellProcessID()) { if (termView->GetShellInfo(shellInfo)
&& termView->GetActiveProcessInfo(info)
&& (info.ID() != shellInfo.ProcessID()
|| !shellInfo.IsDefaultShell())) {
busyProcessCount++; busyProcessCount++;
busyProcessNames = info.Name(); busyProcessNames = info.Name();
} }
} else { } else {
for (int32 i = 0; i < fSessions.CountItems(); i++) { for (int32 i = 0; i < fSessions.CountItems(); i++) {
ShellInfo shellInfo;
ActiveProcessInfo info; ActiveProcessInfo info;
if (_TermViewAt(i)->GetActiveProcessInfo(info) TermView* termView = _TermViewAt(i);
&& info.ID() != info.ShellProcessID()) { if (termView->GetShellInfo(shellInfo)
&& termView->GetActiveProcessInfo(info)
&& (info.ID() != shellInfo.ProcessID()
|| !shellInfo.IsDefaultShell())) {
if (++busyProcessCount > 1) if (++busyProcessCount > 1)
busyProcessNames << "\n\t"; busyProcessNames << "\n\t";
busyProcessNames << info.Name(); busyProcessNames << info.Name();
@@ -1576,15 +1584,20 @@ TermWindow::_UpdateSessionTitle(int32 index)
if (session == NULL) if (session == NULL)
return; return;
// get the active process info // get the shell and active process infos
ShellInfo shellInfo;
ActiveProcessInfo activeProcessInfo; ActiveProcessInfo activeProcessInfo;
if (!_TermViewAt(index)->GetActiveProcessInfo(activeProcessInfo)) TermView* termView = _TermViewAt(index);
if (!termView->GetShellInfo(shellInfo)
|| !termView->GetActiveProcessInfo(activeProcessInfo)) {
return; return;
}
// evaluate the session title pattern // evaluate the session title pattern
BString sessionTitlePattern = session->title.patternUserDefined BString sessionTitlePattern = session->title.patternUserDefined
? session->title.pattern : fSessionTitlePattern; ? session->title.pattern : fSessionTitlePattern;
TabTitlePlaceholderMapper tabMapper(activeProcessInfo, session->index); TabTitlePlaceholderMapper tabMapper(shellInfo, activeProcessInfo,
session->index);
const BString& sessionTitle = PatternEvaluator::Evaluate( const BString& sessionTitle = PatternEvaluator::Evaluate(
sessionTitlePattern, tabMapper); sessionTitlePattern, tabMapper);
@@ -1602,7 +1615,7 @@ TermWindow::_UpdateSessionTitle(int32 index)
return; return;
// evaluate the window title pattern // evaluate the window title pattern
WindowTitlePlaceholderMapper windowMapper(activeProcessInfo, WindowTitlePlaceholderMapper windowMapper(shellInfo, activeProcessInfo,
fTerminalRoster.ID() + 1, sessionTitle); fTerminalRoster.ID() + 1, sessionTitle);
const BString& windowTitle = PatternEvaluator::Evaluate(fTitle.pattern, const BString& windowTitle = PatternEvaluator::Evaluate(fTitle.pattern,
windowMapper); windowMapper);
+12 -9
View File
@@ -10,9 +10,10 @@
// #pragma mark - TitlePlaceholderMapper // #pragma mark - TitlePlaceholderMapper
TitlePlaceholderMapper::TitlePlaceholderMapper( TitlePlaceholderMapper::TitlePlaceholderMapper(const ShellInfo& shellInfo,
const ActiveProcessInfo& processInfo) const ActiveProcessInfo& processInfo)
: :
fShellInfo(shellInfo),
fProcessInfo(processInfo) fProcessInfo(processInfo)
{ {
} }
@@ -46,10 +47,12 @@ TitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number,
} }
case 'p': case 'p':
// process name -- use "--", if the shell is active // process name -- use "--", if the shell is active and it is the
if (fProcessInfo.ID() == fProcessInfo.ShellProcessID()) // default shell
if (fProcessInfo.ID() == fShellInfo.ProcessID()
&& fShellInfo.IsDefaultShell()) {
_string = "--"; _string = "--";
else } else
_string = fProcessInfo.Name(); _string = fProcessInfo.Name();
return true; return true;
} }
@@ -62,10 +65,10 @@ TitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number,
WindowTitlePlaceholderMapper::WindowTitlePlaceholderMapper( WindowTitlePlaceholderMapper::WindowTitlePlaceholderMapper(
const ActiveProcessInfo& processInfo, int32 windowIndex, const ShellInfo& shellInfo, const ActiveProcessInfo& processInfo,
const BString& tabTitle) int32 windowIndex, const BString& tabTitle)
: :
TitlePlaceholderMapper(processInfo), TitlePlaceholderMapper(shellInfo, processInfo),
fWindowIndex(windowIndex), fWindowIndex(windowIndex),
fTabTitle(tabTitle) fTabTitle(tabTitle)
{ {
@@ -97,10 +100,10 @@ WindowTitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number,
// #pragma mark - TabTitlePlaceholderMapper // #pragma mark - TabTitlePlaceholderMapper
TabTitlePlaceholderMapper::TabTitlePlaceholderMapper( TabTitlePlaceholderMapper::TabTitlePlaceholderMapper(const ShellInfo& shellInfo,
const ActiveProcessInfo& processInfo, int32 tabIndex) const ActiveProcessInfo& processInfo, int32 tabIndex)
: :
TitlePlaceholderMapper(processInfo), TitlePlaceholderMapper(shellInfo, processInfo),
fTabIndex(tabIndex) fTabIndex(tabIndex)
{ {
} }
@@ -8,6 +8,7 @@
#include "ActiveProcessInfo.h" #include "ActiveProcessInfo.h"
#include "PatternEvaluator.h" #include "PatternEvaluator.h"
#include "ShellInfo.h"
/*! Class mapping the placeholders common for window and tab titles. /*! Class mapping the placeholders common for window and tab titles.
@@ -15,6 +16,7 @@
class TitlePlaceholderMapper : public PatternEvaluator::PlaceholderMapper { class TitlePlaceholderMapper : public PatternEvaluator::PlaceholderMapper {
public: public:
TitlePlaceholderMapper( TitlePlaceholderMapper(
const ShellInfo& shellInfo,
const ActiveProcessInfo& processInfo); const ActiveProcessInfo& processInfo);
virtual bool MapPlaceholder(char placeholder, virtual bool MapPlaceholder(char placeholder,
@@ -22,6 +24,7 @@ public:
BString& _string); BString& _string);
private: private:
ShellInfo fShellInfo;
ActiveProcessInfo fProcessInfo; ActiveProcessInfo fProcessInfo;
}; };
@@ -29,6 +32,7 @@ private:
class WindowTitlePlaceholderMapper : public TitlePlaceholderMapper { class WindowTitlePlaceholderMapper : public TitlePlaceholderMapper {
public: public:
WindowTitlePlaceholderMapper( WindowTitlePlaceholderMapper(
const ShellInfo& shellInfo,
const ActiveProcessInfo& processInfo, const ActiveProcessInfo& processInfo,
int32 windowIndex, const BString& tabTitle); int32 windowIndex, const BString& tabTitle);
@@ -45,6 +49,7 @@ private:
class TabTitlePlaceholderMapper : public TitlePlaceholderMapper { class TabTitlePlaceholderMapper : public TitlePlaceholderMapper {
public: public:
TabTitlePlaceholderMapper( TabTitlePlaceholderMapper(
const ShellInfo& shellInfo,
const ActiveProcessInfo& processInfo, const ActiveProcessInfo& processInfo,
int32 tabIndex); int32 tabIndex);