likely to help
This commit is contained in:
parent
dc5cb1da28
commit
4382008ad0
@ -361,7 +361,6 @@ proc_t* readproc(PROCTAB* PT, proc_t* p) {
|
|||||||
static struct direct *ent; /* dirent handle */
|
static struct direct *ent; /* dirent handle */
|
||||||
static struct stat sb; /* stat buffer */
|
static struct stat sb; /* stat buffer */
|
||||||
static char path[32], sbuf[1024]; /* bufs for stat,statm */
|
static char path[32], sbuf[1024]; /* bufs for stat,statm */
|
||||||
int matched = 0; /* flags */
|
|
||||||
#ifdef FLASK_LINUX
|
#ifdef FLASK_LINUX
|
||||||
security_id_t secsid;
|
security_id_t secsid;
|
||||||
#endif
|
#endif
|
||||||
@ -374,22 +373,21 @@ next_proc: /* get next PID for consideration */
|
|||||||
#define flags (PT->flags)
|
#define flags (PT->flags)
|
||||||
|
|
||||||
if (flags & PROC_PID) {
|
if (flags & PROC_PID) {
|
||||||
if (!*PT->pids) /* set to next item in pids */
|
if (unlikely(!*PT->pids)) /* set to next item in pids */
|
||||||
return NULL;
|
return NULL;
|
||||||
sprintf(path, "/proc/%d", *(PT->pids)++);
|
sprintf(path, "/proc/%d", *(PT->pids)++);
|
||||||
matched = 1;
|
|
||||||
} else { /* get next numeric /proc ent */
|
} else { /* get next numeric /proc ent */
|
||||||
while ((ent = readdir(PT->procfs)) &&
|
for (;;) {
|
||||||
(*ent->d_name < '0' || *ent->d_name > '9'))
|
ent = readdir(PT->procfs);
|
||||||
;
|
if(unlikely(unlikely(!ent) || unlikely(!ent->d_name))) return NULL;
|
||||||
if (!ent || !ent->d_name)
|
if(likely( likely(*ent->d_name > '0') && likely(*ent->d_name < '9') )) break;
|
||||||
return NULL;
|
}
|
||||||
sprintf(path, "/proc/%s", ent->d_name);
|
sprintf(path, "/proc/%s", ent->d_name);
|
||||||
}
|
}
|
||||||
#ifdef FLASK_LINUX
|
#ifdef FLASK_LINUX
|
||||||
if ( stat_secure(path, &sb, &secsid) == -1 ) /* no such dirent (anymore) */
|
if ( stat_secure(path, &sb, &secsid) == -1 ) /* no such dirent (anymore) */
|
||||||
#else
|
#else
|
||||||
if (stat(path, &sb) == -1) /* no such dirent (anymore) */
|
if (unlikely(stat(path, &sb) == -1)) /* no such dirent (anymore) */
|
||||||
#endif
|
#endif
|
||||||
goto next_proc;
|
goto next_proc;
|
||||||
|
|
||||||
@ -405,18 +403,18 @@ next_proc: /* get next PID for consideration */
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (flags & PROC_FILLSTAT) { /* read, parse /proc/#/stat */
|
if (flags & PROC_FILLSTAT) { /* read, parse /proc/#/stat */
|
||||||
if ((file2str(path, "stat", sbuf, sizeof sbuf)) == -1)
|
if (unlikely( file2str(path, "stat", sbuf, sizeof sbuf) == -1 ))
|
||||||
goto next_proc; /* error reading /proc/#/stat */
|
goto next_proc; /* error reading /proc/#/stat */
|
||||||
stat2proc(sbuf, p); /* parse /proc/#/stat */
|
stat2proc(sbuf, p); /* parse /proc/#/stat */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & PROC_FILLMEM) { /* read, parse /proc/#/statm */
|
if (unlikely(flags & PROC_FILLMEM)) { /* read, parse /proc/#/statm */
|
||||||
if ((file2str(path, "statm", sbuf, sizeof sbuf)) != -1 )
|
if (likely( file2str(path, "statm", sbuf, sizeof sbuf) != -1 ))
|
||||||
statm2proc(sbuf, p); /* ignore statm errors here */
|
statm2proc(sbuf, p); /* ignore statm errors here */
|
||||||
} /* statm fields just zero */
|
} /* statm fields just zero */
|
||||||
|
|
||||||
if (flags & PROC_FILLSTATUS) { /* read, parse /proc/#/status */
|
if (flags & PROC_FILLSTATUS) { /* read, parse /proc/#/status */
|
||||||
if ((file2str(path, "status", sbuf, sizeof sbuf)) != -1 ){
|
if (likely( file2str(path, "status", sbuf, sizeof sbuf) != -1 )){
|
||||||
status2proc(sbuf, p);
|
status2proc(sbuf, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -446,12 +444,12 @@ next_proc: /* get next PID for consideration */
|
|||||||
else
|
else
|
||||||
p->cmdline = NULL;
|
p->cmdline = NULL;
|
||||||
|
|
||||||
if (flags & PROC_FILLENV) /* read+parse /proc/#/environ */
|
if (unlikely(flags & PROC_FILLENV)) /* read+parse /proc/#/environ */
|
||||||
p->environ = file2strvec(path, "environ");
|
p->environ = file2strvec(path, "environ");
|
||||||
else
|
else
|
||||||
p->environ = NULL;
|
p->environ = NULL;
|
||||||
|
|
||||||
if (p->state == 'Z') /* fixup cmd for zombies */
|
if (unlikely(p->state == 'Z')) /* fixup cmd for zombies */
|
||||||
strncat(p->cmd," <defunct>", sizeof p->cmd);
|
strncat(p->cmd," <defunct>", sizeof p->cmd);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
@ -132,7 +132,7 @@ typedef struct proc_t {
|
|||||||
exit_signal, /* might not be SIGCHLD */
|
exit_signal, /* might not be SIGCHLD */
|
||||||
processor; /* current (or most recent?) CPU */
|
processor; /* current (or most recent?) CPU */
|
||||||
#ifdef FLASK_LINUX
|
#ifdef FLASK_LINUX
|
||||||
security_id_t secsid;
|
security_id_t secsid;
|
||||||
#endif
|
#endif
|
||||||
} proc_t;
|
} proc_t;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user