mirror of https://github.com/xzeldon/htop.git
Linux: update process uid on change
Always check if the user of a process changed, e.g. by using setuid(2).
This commit is contained in:
parent
faabbaa71e
commit
9114cf6ea3
|
@ -968,6 +968,7 @@ void Process_init(Process* this, const Settings* settings) {
|
||||||
this->show = true;
|
this->show = true;
|
||||||
this->updated = false;
|
this->updated = false;
|
||||||
this->cmdlineBasenameEnd = -1;
|
this->cmdlineBasenameEnd = -1;
|
||||||
|
this->st_uid = (uid_t)-1;
|
||||||
|
|
||||||
if (Process_getuid == (uid_t)-1) {
|
if (Process_getuid == (uid_t)-1) {
|
||||||
Process_getuid = getuid();
|
Process_getuid = getuid();
|
||||||
|
|
|
@ -380,7 +380,7 @@ static bool LinuxProcessList_readStatFile(Process* process, openat_arg_t procFd,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool LinuxProcessList_statProcessDir(Process* process, openat_arg_t procFd) {
|
static bool LinuxProcessList_updateUser(ProcessList* processList, Process* process, openat_arg_t procFd) {
|
||||||
struct stat sstat;
|
struct stat sstat;
|
||||||
#ifdef HAVE_OPENAT
|
#ifdef HAVE_OPENAT
|
||||||
int statok = fstat(procFd, &sstat);
|
int statok = fstat(procFd, &sstat);
|
||||||
|
@ -389,7 +389,12 @@ static bool LinuxProcessList_statProcessDir(Process* process, openat_arg_t procF
|
||||||
#endif
|
#endif
|
||||||
if (statok == -1)
|
if (statok == -1)
|
||||||
return false;
|
return false;
|
||||||
process->st_uid = sstat.st_uid;
|
|
||||||
|
if (process->st_uid != sstat.st_uid) {
|
||||||
|
process->st_uid = sstat.st_uid;
|
||||||
|
process->user = UsersTable_getRef(processList->usersTable, sstat.st_uid);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1402,13 +1407,11 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
|
||||||
proc->percent_cpu = CLAMP(percent_cpu, 0.0F, cpus * 100.0F);
|
proc->percent_cpu = CLAMP(percent_cpu, 0.0F, cpus * 100.0F);
|
||||||
proc->percent_mem = proc->m_resident / (double)(pl->totalMem) * 100.0;
|
proc->percent_mem = proc->m_resident / (double)(pl->totalMem) * 100.0;
|
||||||
|
|
||||||
|
if (! LinuxProcessList_updateUser(pl, proc, procFd))
|
||||||
|
goto errorReadingProcess;
|
||||||
|
|
||||||
if (!preExisting) {
|
if (!preExisting) {
|
||||||
|
|
||||||
if (! LinuxProcessList_statProcessDir(proc, procFd))
|
|
||||||
goto errorReadingProcess;
|
|
||||||
|
|
||||||
proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid);
|
|
||||||
|
|
||||||
#ifdef HAVE_OPENVZ
|
#ifdef HAVE_OPENVZ
|
||||||
if (settings->flags & PROCESS_FLAG_LINUX_OPENVZ) {
|
if (settings->flags & PROCESS_FLAG_LINUX_OPENVZ) {
|
||||||
LinuxProcessList_readOpenVZData(lp, procFd);
|
LinuxProcessList_readOpenVZData(lp, procFd);
|
||||||
|
|
Loading…
Reference in New Issue