Commit 10ba98f7 authored by Topi Miettinen's avatar Topi Miettinen Committed by Nate Graham

process: add NoNewPrivileges

Summary: Signed-off-by: Topi Miettinen <toiwoton@gmail.com>

Reviewers: davidedmundson

Reviewed By: davidedmundson

Subscribers: ngraham, davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D20645
parent 574e0b7d
......@@ -82,6 +82,7 @@ public:
int index;
Process::Changes changes;
int elapsedTimeMilliSeconds;
int noNewPrivileges;
};
Process::Process()
......@@ -291,6 +292,11 @@ qlonglong Process::startTime() const
return d->startTime;
}
int Process::noNewPrivileges() const
{
return d->noNewPrivileges;
}
int Process::userUsage() const
{
return d->userUsage;
......@@ -582,6 +588,12 @@ void Process::setStartTime(qlonglong startTime)
d->startTime = startTime;
}
void Process::setNoNewPrivileges(int number) {
if(d->noNewPrivileges == number) return;
d->noNewPrivileges = number;
d->changes |= Process::Status;
}
void Process::setUserUsage(int _userUsage) {
if(d->userUsage == _userUsage) return;
d->userUsage = _userUsage;
......
......@@ -184,6 +184,9 @@ public:
int numThreads() const; ///< Number of threads that this process has, including the main one. 0 if not known
void setNumThreads(int number); ///< The number of threads that this process has, including this process.
int noNewPrivileges() const;
void setNoNewPrivileges(int number); ///< Linux process flag NoNewPrivileges
int index() const; ///< Each process has a parent process. Each sibling has a unique number to identify it under that parent. This is that number.
void setIndex(int index);
......
......@@ -138,6 +138,7 @@ bool ProcessesLocal::Private::readProcStatus(const QString &dir, Process *proces
process->setGid(0);
process->setTracerpid(-1);
process->setNumThreads(0);
process->setNoNewPrivileges(0);
int size;
int found = 0; //count how many fields we found
......@@ -147,7 +148,10 @@ bool ProcessesLocal::Private::readProcStatus(const QString &dir, Process *proces
if((unsigned int)size > sizeof("Name:") && qstrncmp(mBuffer, "Name:", sizeof("Name:")-1) == 0) {
if(process->command().isEmpty())
process->setName(QString::fromLocal8Bit(mBuffer + sizeof("Name:")-1, size-sizeof("Name:")+1).trimmed());
if(++found == 5) goto finish;
if(++found == 6) goto finish;
} else if((unsigned int)size > sizeof("NoNewPrivs:") && qstrncmp(mBuffer, "NoNewPrivs:", sizeof("NoNewPrivs:")-1) == 0) {
process->setNoNewPrivileges(atol(mBuffer + sizeof("NoNewPrivs:")-1));
if(++found == 6) goto finish;
}
break;
case 'U':
......@@ -161,7 +165,7 @@ bool ProcessesLocal::Private::readProcStatus(const QString &dir, Process *proces
process->setEuid(euid);
process->setSuid(suid);
process->setFsuid(fsuid);
if(++found == 5) goto finish;
if(++found == 6) goto finish;
}
break;
case 'G':
......@@ -172,7 +176,7 @@ bool ProcessesLocal::Private::readProcStatus(const QString &dir, Process *proces
process->setEgid(egid);
process->setSgid(sgid);
process->setFsgid(fsgid);
if(++found == 5) goto finish;
if(++found == 6) goto finish;
}
break;
case 'T':
......@@ -180,10 +184,10 @@ bool ProcessesLocal::Private::readProcStatus(const QString &dir, Process *proces
process->setTracerpid(atol(mBuffer + sizeof("TracerPid:")-1));
if (process->tracerpid() == 0)
process->setTracerpid(-1);
if(++found == 5) goto finish;
if(++found == 6) goto finish;
} else if((unsigned int)size > sizeof("Threads:") && qstrncmp(mBuffer, "Threads:", sizeof("Threads:")-1) == 0) {
process->setNumThreads(atol(mBuffer + sizeof("Threads:")-1));
if(++found == 5) goto finish;
if(++found == 6) goto finish;
}
break;
default:
......
......@@ -42,7 +42,7 @@ namespace KSysGuard
statusColumn = userColumn = systemColumn = niceColumn =
vmSizeColumn = vmRSSColumn = loginColumn = commandColumn =
tracerPidColumn = ttyColumn = ioprioClassColumn = ioprioColumn =
vmURSSColumn = -1;
vmURSSColumn = noNewPrivilegesColumn = -1;
usedMemory = freeMemory;}
~Private() {}
QString host;
......@@ -69,6 +69,7 @@ namespace KSysGuard
int ioprioClassColumn;
int ioprioColumn;
int ttyColumn;
int noNewPrivilegesColumn;
int numColumns;
......@@ -137,6 +138,7 @@ bool ProcessesRemote::updateProcessInfo( long pid, Process *process)
if(d->ttyColumn!= -1) process->setTty(p.at(d->ttyColumn));
if(d->ioprioColumn!= -1) process->setIoniceLevel(p.at(d->ioprioColumn).toInt());
if(d->ioprioClassColumn!= -1) process->setIoPriorityClass((KSysGuard::Process::IoPriorityClass)(p.at(d->ioprioClassColumn).toInt()));
if(d->noNewPrivilegesColumn!= -1) process->setNoNewPrivileges(p.at(d->noNewPrivilegesColumn).toLong());
return true;
}
......@@ -242,6 +244,8 @@ void ProcessesRemote::answerReceived( int id, const QList<QByteArray>& answer )
d->ioprioClassColumn = i;
else if(info[i] == "IO Priority")
d->ioprioColumn = i;
else if(info[i] == "NNP")
d->noNewPrivilegesColumn = i;
}
d->havePsInfo = true;
break;
......
......@@ -262,6 +262,8 @@ bool ProcessModel::lessThan(const QModelIndex &left, const QModelIndex &right) c
case HeadingStartTime: {
return processLeft->startTime() > processRight->startTime();
}
case HeadingNoNewPrivileges:
return processLeft->noNewPrivileges() > processRight->noNewPrivileges();
case HeadingXMemory:
return processLeft->pixmapBytes() > processRight->pixmapBytes();
case HeadingVmSize:
......@@ -756,6 +758,11 @@ void ProcessModelPrivate::processChanged(KSysGuard::Process *process, bool onlyT
index = q->createIndex(row, ProcessModel::HeadingUser, process);
emit q->dataChanged(index, index);
}
if(process->changes() & KSysGuard::Process::Status) {
totalUpdated++;
QModelIndex index = q->createIndex(row, ProcessModel::HeadingNoNewPrivileges, process);
emit q->dataChanged(index, index);
}
if(process->changes() & KSysGuard::Process::NiceLevels) {
totalUpdated++;
QModelIndex index = q->createIndex(row, ProcessModel::HeadingNiceness, process);
......@@ -961,6 +968,7 @@ QVariant ProcessModel::headerData(int section, Qt::Orientation orientation,
case HeadingXMemory:
case HeadingSharedMemory:
case HeadingStartTime:
case HeadingNoNewPrivileges:
case HeadingIoRead:
case HeadingIoWrite:
case HeadingVmSize:
......@@ -1007,6 +1015,8 @@ QVariant ProcessModel::headerData(int section, Qt::Orientation orientation,
return i18n("<qt>This is approximately the amount of real physical memory that this process's shared libraries are using.<br>This memory is shared among all processes that use this library.</qt>");
case HeadingStartTime:
return i18n("<qt>The elapsed time since the process was started.</qt>");
case HeadingNoNewPrivileges:
return i18n("<qt>Linux flag NoNewPrivileges, if set the process can't gain further privileges via setuid etc.</qt>");
case HeadingCommand:
return i18n("<qt>The command with which this process was launched.</qt>");
case HeadingXMemory:
......@@ -1050,6 +1060,8 @@ QVariant ProcessModel::headerData(int section, Qt::Orientation orientation,
return i18n("<qt><i>Technical information: </i>This is an approximation of the Shared memory, called SHR in top. It is the number of pages that are backed by a file (see kernel Documentation/filesystems/proc.txt). For an individual process, see \"Detailed Memory Information\" for a more accurate, but slower, calculation of the true Shared memory usage.");
case HeadingStartTime:
return i18n("<qt><i>Technical information: </i>The underlying value (clock ticks since system boot) is retrieved from /proc/[pid]/stat");
case HeadingNoNewPrivileges:
return i18n("<qt><i>Technical information: </i>The flag is retrieved from /proc/[pid]/status");
case HeadingCommand:
return i18n("<qt><i>Technical information: </i>This is from /proc/*/cmdline");
case HeadingXMemory:
......@@ -1316,6 +1328,8 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
const auto relativeStartTime = absoluteStartTime.secsTo(QDateTime::currentDateTime());
return TimeUtil::secondsToHumanElapsedString(relativeStartTime);
}
case HeadingNoNewPrivileges:
return QString::number(process->noNewPrivileges());
case HeadingCommand:
{
return process->command().replace(QLatin1Char('\n'),QLatin1Char(' '));
......@@ -1659,6 +1673,7 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
case HeadingNiceness:
case HeadingCPUTime:
case HeadingStartTime:
case HeadingNoNewPrivileges:
case HeadingPid:
case HeadingMemory:
case HeadingXMemory:
......@@ -1720,6 +1735,8 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
return (qlonglong)(process->vmRSS() - process->vmURSS());
case HeadingStartTime:
return process->startTime(); // 2015-01-03, gregormi: can maybe be replaced with something better later
case HeadingNoNewPrivileges:
return process->noNewPrivileges();
case HeadingCommand:
return process->command();
case HeadingIoRead:
......@@ -1942,6 +1959,7 @@ void ProcessModel::setupHeader() {
headings << i18nc("process heading", "Memory");
headings << i18nc("process heading", "Shared Mem");
headings << i18nc("process heading", "Relative Start Time");
headings << i18nc("process heading", "NNP");
headings << i18nc("process heading", "Command");
#if HAVE_X11
if (d->mIsX11) {
......
......@@ -138,7 +138,7 @@ class KSYSGUARD_EXPORT ProcessModel : public QAbstractItemModel
* setup header function, and make sure you increase PROCESSHEADERVERSION. This will ensure
* that old saved settings won't be used
*/
#define PROCESSHEADERVERSION 6
#define PROCESSHEADERVERSION 7
enum { HeadingName=0,
HeadingUser,
HeadingPid,
......@@ -152,6 +152,7 @@ class KSYSGUARD_EXPORT ProcessModel : public QAbstractItemModel
HeadingMemory,
HeadingSharedMemory,
HeadingStartTime,
HeadingNoNewPrivileges,
HeadingCommand,
HeadingXMemory,
HeadingXTitle
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment