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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user