part 2
This commit is contained in:
parent
c471462b3d
commit
c846a886db
29
w.c
29
w.c
@ -123,7 +123,9 @@ static void print_logintime(time_t logt, FILE* fout) {
|
|||||||
*/
|
*/
|
||||||
static proc_t *getproc(const utmp_t *restrict const u, const char *restrict const tty, const unsigned long long *restrict jcpu, const int *restrict found_utpid) {
|
static proc_t *getproc(const utmp_t *restrict const u, const char *restrict const tty, const unsigned long long *restrict jcpu, const int *restrict found_utpid) {
|
||||||
int line;
|
int line;
|
||||||
proc_t **p, *best = NULL, *secondbest = NULL;
|
proc_t **pptr = procs;
|
||||||
|
proc_t *best = NULL;
|
||||||
|
proc_t *secondbest = NULL;
|
||||||
unsigned uid = ~0U;
|
unsigned uid = ~0U;
|
||||||
|
|
||||||
if(!ignoreuser){
|
if(!ignoreuser){
|
||||||
@ -139,22 +141,23 @@ static proc_t *getproc(const utmp_t *restrict const u, const char *restrict cons
|
|||||||
line = tty_to_dev(tty);
|
line = tty_to_dev(tty);
|
||||||
*jcpu = 0;
|
*jcpu = 0;
|
||||||
*found_utpid = 0;
|
*found_utpid = 0;
|
||||||
for(p = procs; *p; p++) {
|
for(; *pptr; pptr++) {
|
||||||
if((**p).pid == u->ut_pid) {
|
const proc_t *restrict const tmp = *pptr;
|
||||||
|
if(tmp->pid == u->ut_pid) {
|
||||||
*found_utpid = 1;
|
*found_utpid = 1;
|
||||||
best = *p;
|
best = tmp;
|
||||||
}
|
}
|
||||||
if((**p).tty != line) continue;
|
if(tmp->tty != line) continue;
|
||||||
(*jcpu) += (**p).utime + (**p).stime;
|
(*jcpu) += tmp->utime + tmp->stime;
|
||||||
secondbest = *p;
|
secondbest = tmp;
|
||||||
/* same time-logic here as for "best" below */
|
/* same time-logic here as for "best" below */
|
||||||
if(! (secondbest && (**p).start_time <= secondbest->start_time) ){
|
if(! (secondbest && tmp->start_time <= secondbest->start_time) ){
|
||||||
secondbest = *p;
|
secondbest = tmp;
|
||||||
}
|
}
|
||||||
if(!ignoreuser && uid != (**p).euid && uid != (**p).ruid) continue;
|
if(!ignoreuser && uid != tmp->euid && uid != tmp->ruid) continue;
|
||||||
if((**p).pid != (**p).tpgid) continue;
|
if(tmp->pid != tmp->tpgid) continue;
|
||||||
if(best && (**p).start_time <= best->start_time) continue;
|
if(best && tmp->start_time <= best->start_time) continue;
|
||||||
best = *p;
|
best = tmp;
|
||||||
}
|
}
|
||||||
return best ? best : secondbest;
|
return best ? best : secondbest;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user