Skip to content

Commit

Permalink
procstat_getprocs() seems to return NULL if no procs match the predic…
Browse files Browse the repository at this point in the history
…ate, which breaks progress -m
  • Loading branch information
vthriller committed Feb 28, 2021
1 parent f2e1be2 commit d142d26
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ procstat = procstat_open_sysctl();
assert(procstat != NULL);

procs = procstat_getprocs(procstat, KERN_PROC_PID, pid, &proc_count);
// procstat doesn't seem to set errno, so don't nperror()
assert(procs != NULL);
if (procs == NULL)
goto done;

for (i = 0; i < proc_count; i++) {
proc = &procs[i];
Expand All @@ -312,6 +312,7 @@ for (i = 0; i < proc_count; i++) {
}

procstat_freeprocs(procstat, procs);
done:
procstat_close(procstat);

return found;
Expand All @@ -333,8 +334,8 @@ procstat = procstat_open_sysctl();
assert(procstat != NULL);

procs = procstat_getprocs(procstat, KERN_PROC_PROC, 0, &proc_count);
// procstat doesn't seem to set errno, so don't nperror()
assert(procs != NULL);
if (procs == NULL)
goto done;

for (i = 0; i < proc_count; i++) {
proc = &procs[i];
Expand All @@ -353,6 +354,7 @@ for (i = 0; i < proc_count; i++) {
}

procstat_freeprocs(procstat, procs);
done:
procstat_close(procstat);

return pid_count;
Expand Down Expand Up @@ -484,8 +486,8 @@ procstat = procstat_open_sysctl();
assert(procstat != NULL);

procs = procstat_getprocs(procstat, KERN_PROC_PID, pid, &proc_count);
// procstat doesn't seem to set errno, so don't nperror()
assert(procs != NULL);
if (procs == NULL)
goto done;

for (i = 0; i < proc_count; i++) {
proc = &procs[i];
Expand Down Expand Up @@ -524,6 +526,7 @@ for (i = 0; i < proc_count; i++) {
}

procstat_freeprocs(procstat, procs);
done:
procstat_close(procstat);

return count;
Expand Down Expand Up @@ -578,8 +581,8 @@ procstat = procstat_open_sysctl();
assert(procstat != NULL);

procs = procstat_getprocs(procstat, KERN_PROC_PID, pid, &proc_count);
// procstat doesn't seem to set errno, so don't nperror()
assert(procs != NULL);
if (procs == NULL)
goto done;

for (i = 0; i < proc_count; i++) {
proc = &procs[i];
Expand Down Expand Up @@ -617,6 +620,7 @@ for (i = 0; i < proc_count; i++) {
}

procstat_freeprocs(procstat, procs);
done:
procstat_close(procstat);
#endif // __FreeBSD__

Expand Down

0 comments on commit d142d26

Please sign in to comment.