Borrow the algorithm from kvm_getprocs() to fix procstat_getprocs() to
handle the case where the process tables grows in between the calls to fetch the size and fetch the table. MFC after: 1 week
This commit is contained in:
parent
ed8fd1989f
commit
608203fd94
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=251637
@ -253,7 +253,7 @@ procstat_getprocs(struct procstat *procstat, int what, int arg,
|
|||||||
unsigned int *count)
|
unsigned int *count)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *p0, *p;
|
struct kinfo_proc *p0, *p;
|
||||||
size_t len;
|
size_t len, olen;
|
||||||
int name[4];
|
int name[4];
|
||||||
int cnt;
|
int cnt;
|
||||||
int error;
|
int error;
|
||||||
@ -290,12 +290,16 @@ procstat_getprocs(struct procstat *procstat, int what, int arg,
|
|||||||
warnx("no processes?");
|
warnx("no processes?");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
p = malloc(len);
|
do {
|
||||||
if (p == NULL) {
|
len += len / 10;
|
||||||
warnx("malloc(%zu)", len);
|
p = reallocf(p, len);
|
||||||
goto fail;
|
if (p == NULL) {
|
||||||
}
|
warnx("reallocf(%zu)", len);
|
||||||
error = sysctl(name, 4, p, &len, NULL, 0);
|
goto fail;
|
||||||
|
}
|
||||||
|
olen = len;
|
||||||
|
error = sysctl(name, 4, p, &len, NULL, 0);
|
||||||
|
} while (error < 0 && errno == ENOMEM && olen == len);
|
||||||
if (error < 0 && errno != EPERM) {
|
if (error < 0 && errno != EPERM) {
|
||||||
warn("sysctl(kern.proc)");
|
warn("sysctl(kern.proc)");
|
||||||
goto fail;
|
goto fail;
|
||||||
|
Loading…
Reference in New Issue
Block a user