Skip to content

Commit

Permalink
cgroup-util: make cg_read_pid skip zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
BtbN committed Apr 28, 2024
1 parent b2173f5 commit ce2ac5d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/basic/cgroup-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,22 @@ int cg_read_pid(FILE *f, pid_t *ret) {
assert(f);
assert(ret);

errno = 0;
if (fscanf(f, "%lu", &ul) != 1) {
/* In some environments(WSL), the pid list contains a bunch of zeros.
* Maybe the kernel is hiding pids from other containerized instances.
* Just skip over those and move on. */
do {
errno = 0;
if (fscanf(f, "%lu", &ul) != 1) {

if (feof(f)) {
*ret = 0;
return 0;
}
if (feof(f)) {
*ret = 0;
return 0;
}

return errno_or_else(EIO);
}
return errno_or_else(EIO);
}
} while (ul == 0);

if (ul <= 0)
return -EIO;
if (ul > PID_T_MAX)
return -EIO;

Expand Down

0 comments on commit ce2ac5d

Please sign in to comment.