diff --git a/Process.c b/Process.c index 4223adc1..87869552 100644 --- a/Process.c +++ b/Process.c @@ -968,6 +968,7 @@ void Process_init(Process* this, const Settings* settings) { this->show = true; this->updated = false; this->cmdlineBasenameEnd = -1; + this->st_uid = (uid_t)-1; if (Process_getuid == (uid_t)-1) { Process_getuid = getuid(); diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index fdde57c3..168c7eb7 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -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; #ifdef HAVE_OPENAT int statok = fstat(procFd, &sstat); @@ -389,7 +389,12 @@ static bool LinuxProcessList_statProcessDir(Process* process, openat_arg_t procF #endif if (statok == -1) 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; } @@ -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_mem = proc->m_resident / (double)(pl->totalMem) * 100.0; + if (! LinuxProcessList_updateUser(pl, proc, procFd)) + goto errorReadingProcess; + if (!preExisting) { - if (! LinuxProcessList_statProcessDir(proc, procFd)) - goto errorReadingProcess; - - proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid); - #ifdef HAVE_OPENVZ if (settings->flags & PROCESS_FLAG_LINUX_OPENVZ) { LinuxProcessList_readOpenVZData(lp, procFd);