mirror of
https://github.com/KDE/konsole.git
synced 2026-06-11 07:26:10 -04:00
Only readUserName if tab title format has %u
readUserName() reads /etc/passwd every few seconds. Change it to only do this if we need to replace %u with the user name in the tab title. A temporary helper as this doesn't really fix the underlining issue. ProcessInfo really needs re-worked. CCBUG: 325442
This commit is contained in:
@@ -80,6 +80,7 @@ ProcessInfo::ProcessInfo(int aPid , bool enableEnvironmentRead)
|
||||
, _lastError(NoError)
|
||||
, _userName(QString())
|
||||
, _userHomeDir(QString())
|
||||
, _userNameRequired(true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -106,7 +107,8 @@ QString ProcessInfo::validCurrentDir() const
|
||||
int currentPid = parentPid(&ok);
|
||||
QString dir = currentDir(&ok);
|
||||
while (!ok && currentPid != 0) {
|
||||
ProcessInfo* current = ProcessInfo::newInstance(currentPid);
|
||||
QString tmp = QString("");
|
||||
ProcessInfo* current = ProcessInfo::newInstance(currentPid, tmp);
|
||||
current->update();
|
||||
currentPid = current->parentPid(&ok);
|
||||
dir = current->currentDir(&ok);
|
||||
@@ -296,6 +298,16 @@ void ProcessInfo::setForegroundPid(int aPid)
|
||||
_fields |= FOREGROUND_PID;
|
||||
}
|
||||
|
||||
void ProcessInfo::setUserNameRequired(bool need)
|
||||
{
|
||||
_userNameRequired = need;
|
||||
}
|
||||
|
||||
bool ProcessInfo::userNameRequired() const
|
||||
{
|
||||
return _userNameRequired;
|
||||
}
|
||||
|
||||
QString ProcessInfo::currentDir(bool* ok) const
|
||||
{
|
||||
if (ok)
|
||||
@@ -348,7 +360,7 @@ void ProcessInfo::setFileError(QFile::FileError error)
|
||||
// implementations of the UnixProcessInfo abstract class.
|
||||
//
|
||||
|
||||
NullProcessInfo::NullProcessInfo(int aPid, bool enableEnvironmentRead)
|
||||
NullProcessInfo::NullProcessInfo(int aPid, const QString& /*titleFormat*/, bool enableEnvironmentRead)
|
||||
: ProcessInfo(aPid, enableEnvironmentRead)
|
||||
{
|
||||
}
|
||||
@@ -363,9 +375,10 @@ void NullProcessInfo::readUserName()
|
||||
}
|
||||
|
||||
#if !defined(Q_OS_WIN)
|
||||
UnixProcessInfo::UnixProcessInfo(int aPid, bool enableEnvironmentRead)
|
||||
UnixProcessInfo::UnixProcessInfo(int aPid, const QString& titleFormat, bool enableEnvironmentRead)
|
||||
: ProcessInfo(aPid, enableEnvironmentRead)
|
||||
{
|
||||
setUserNameRequired(titleFormat.contains(QLatin1String("%u")));
|
||||
}
|
||||
|
||||
bool UnixProcessInfo::readProcessInfo(int aPid , bool enableEnvironmentRead)
|
||||
@@ -419,8 +432,8 @@ void UnixProcessInfo::readUserName()
|
||||
class LinuxProcessInfo : public UnixProcessInfo
|
||||
{
|
||||
public:
|
||||
LinuxProcessInfo(int aPid, bool env) :
|
||||
UnixProcessInfo(aPid, env) {
|
||||
LinuxProcessInfo(int aPid, const QString& titleFormat, bool env) :
|
||||
UnixProcessInfo(aPid, titleFormat, env) {
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -462,7 +475,10 @@ private:
|
||||
const int uid = uidString.toInt(&ok);
|
||||
if (ok)
|
||||
setUserId(uid);
|
||||
readUserName();
|
||||
// This will cause constant opening of /etc/passwd
|
||||
if (userNameRequired()) {
|
||||
readUserName();
|
||||
}
|
||||
} else {
|
||||
setFileError(statusInfo.error());
|
||||
return false;
|
||||
@@ -611,8 +627,8 @@ private:
|
||||
class FreeBSDProcessInfo : public UnixProcessInfo
|
||||
{
|
||||
public:
|
||||
FreeBSDProcessInfo(int aPid, bool readEnvironment) :
|
||||
UnixProcessInfo(aPid, readEnvironment) {
|
||||
FreeBSDProcessInfo(int aPid, const QString& titleFormat, bool readEnvironment) :
|
||||
UnixProcessInfo(aPid, titleFormat, readEnvironment) {
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -731,8 +747,8 @@ private:
|
||||
class OpenBSDProcessInfo : public UnixProcessInfo
|
||||
{
|
||||
public:
|
||||
OpenBSDProcessInfo(int aPid, bool readEnvironment) :
|
||||
UnixProcessInfo(aPid, readEnvironment) {
|
||||
OpenBSDProcessInfo(int aPid, const QString& titleFormat, bool readEnvironment) :
|
||||
UnixProcessInfo(aPid, titleFormat, readEnvironment) {
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -865,8 +881,8 @@ private:
|
||||
class MacProcessInfo : public UnixProcessInfo
|
||||
{
|
||||
public:
|
||||
MacProcessInfo(int aPid, bool env) :
|
||||
UnixProcessInfo(aPid, env) {
|
||||
MacProcessInfo(int aPid, const QString& titleFormat, bool env) :
|
||||
UnixProcessInfo(aPid, titleFormat, env) {
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -961,8 +977,8 @@ private:
|
||||
class SolarisProcessInfo : public UnixProcessInfo
|
||||
{
|
||||
public:
|
||||
SolarisProcessInfo(int aPid, bool readEnvironment)
|
||||
: UnixProcessInfo(aPid, readEnvironment) {
|
||||
SolarisProcessInfo(int aPid, const QString& titleFormat, bool readEnvironment)
|
||||
: UnixProcessInfo(aPid, titleFormat, readEnvironment) {
|
||||
}
|
||||
private:
|
||||
virtual bool readProcInfo(int aPid) {
|
||||
@@ -1164,20 +1180,20 @@ QString SSHProcessInfo::format(const QString& input) const
|
||||
return output;
|
||||
}
|
||||
|
||||
ProcessInfo* ProcessInfo::newInstance(int aPid, bool enableEnvironmentRead)
|
||||
ProcessInfo* ProcessInfo::newInstance(int aPid, const QString& titleFormat, bool enableEnvironmentRead)
|
||||
{
|
||||
#if defined(Q_OS_LINUX)
|
||||
return new LinuxProcessInfo(aPid, enableEnvironmentRead);
|
||||
return new LinuxProcessInfo(aPid, titleFormat, enableEnvironmentRead);
|
||||
#elif defined(Q_OS_SOLARIS)
|
||||
return new SolarisProcessInfo(aPid, enableEnvironmentRead);
|
||||
return new SolarisProcessInfo(aPid, titleFormat, enableEnvironmentRead);
|
||||
#elif defined(Q_OS_MAC)
|
||||
return new MacProcessInfo(aPid, enableEnvironmentRead);
|
||||
return new MacProcessInfo(aPid, titleFormat, enableEnvironmentRead);
|
||||
#elif defined(Q_OS_FREEBSD)
|
||||
return new FreeBSDProcessInfo(aPid, enableEnvironmentRead);
|
||||
return new FreeBSDProcessInfo(aPid, titleFormat, enableEnvironmentRead);
|
||||
#elif defined(Q_OS_OPENBSD)
|
||||
return new OpenBSDProcessInfo(aPid, enableEnvironmentRead);
|
||||
return new OpenBSDProcessInfo(aPid, titleFormat, enableEnvironmentRead);
|
||||
#else
|
||||
return new NullProcessInfo(aPid, enableEnvironmentRead);
|
||||
return new NullProcessInfo(aPid, titleFormat, enableEnvironmentRead);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
* of reading the (potentially large) environment data when it
|
||||
* is not required.
|
||||
*/
|
||||
static ProcessInfo* newInstance(int pid, bool readEnvironment = false);
|
||||
static ProcessInfo* newInstance(int pid, const QString& titleFormat, bool readEnvironment = false);
|
||||
|
||||
virtual ~ProcessInfo() {}
|
||||
|
||||
@@ -294,6 +294,9 @@ protected:
|
||||
*/
|
||||
void addEnvironmentBinding(const QString& name , const QString& value);
|
||||
|
||||
void setUserNameRequired(bool need);
|
||||
bool userNameRequired() const;
|
||||
|
||||
private:
|
||||
// takes a full directory path and returns a
|
||||
// shortened version suitable for display in
|
||||
@@ -316,6 +319,8 @@ private:
|
||||
QString _userHomeDir;
|
||||
QString _currentDir;
|
||||
|
||||
bool _userNameRequired;
|
||||
|
||||
QVector<QString> _arguments;
|
||||
QMap<QString, QString> _environment;
|
||||
|
||||
@@ -338,7 +343,7 @@ public:
|
||||
* Constructs a new NullProcessInfo instance.
|
||||
* See ProcessInfo::newInstance()
|
||||
*/
|
||||
explicit NullProcessInfo(int pid, bool readEnvironment = false);
|
||||
explicit NullProcessInfo(int pid, const QString& titleFormat, bool readEnvironment = false);
|
||||
protected:
|
||||
virtual bool readProcessInfo(int pid, bool readEnvironment);
|
||||
virtual void readUserName(void);
|
||||
@@ -356,7 +361,7 @@ public:
|
||||
* Constructs a new instance of UnixProcessInfo.
|
||||
* See ProcessInfo::newInstance()
|
||||
*/
|
||||
explicit UnixProcessInfo(int pid, bool readEnvironment = false);
|
||||
explicit UnixProcessInfo(int pid, const QString& titleFormat, bool readEnvironment = false);
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
||||
@@ -972,7 +972,8 @@ void Session::updateSessionProcessInfo()
|
||||
if (!_sessionProcessInfo ||
|
||||
(processId() != 0 && processId() != _sessionProcessInfo->pid(&ok))) {
|
||||
delete _sessionProcessInfo;
|
||||
_sessionProcessInfo = ProcessInfo::newInstance(processId());
|
||||
_sessionProcessInfo = ProcessInfo::newInstance(processId(),
|
||||
tabTitleFormat(Session::LocalTabTitle));
|
||||
_sessionProcessInfo->setUserHomeDir();
|
||||
}
|
||||
_sessionProcessInfo->update();
|
||||
@@ -985,7 +986,8 @@ bool Session::updateForegroundProcessInfo()
|
||||
const int foregroundPid = _shellProcess->foregroundProcessGroup();
|
||||
if (foregroundPid != _foregroundPid) {
|
||||
delete _foregroundProcessInfo;
|
||||
_foregroundProcessInfo = ProcessInfo::newInstance(foregroundPid);
|
||||
_foregroundProcessInfo = ProcessInfo::newInstance(foregroundPid,
|
||||
tabTitleFormat(Session::LocalTabTitle));
|
||||
_foregroundPid = foregroundPid;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user