Skip to content

Commit

Permalink
Non-existence of /proc/$PID/stat should not be fatal
Browse files Browse the repository at this point in the history
With the proxy, it is possible that the inside process just
disappears under the keeper's hands.
  • Loading branch information
gollux committed Mar 27, 2018
1 parent 295d383 commit fe211cb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions isolate.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,24 +337,25 @@ reset_signals(void)
/*** The keeper process ***/

#define PROC_BUF_SIZE 4096
static void
static int
read_proc_file(char *buf, char *name, int *fdp)
{
int c;

if (!*fdp)
if (*fdp < 0)
{
snprintf(buf, PROC_BUF_SIZE, "/proc/%d/%s", (int) box_pid, name);
*fdp = open(buf, O_RDONLY);
if (*fdp < 0)
die("open(%s): %m", buf);
return 0; // This is OK, the process could have finished
}
lseek(*fdp, 0, SEEK_SET);
if ((c = read(*fdp, buf, PROC_BUF_SIZE-1)) < 0)
die("read on /proc/$pid/%s: %m", name);
if (c >= PROC_BUF_SIZE-1)
die("/proc/$pid/%s too long", name);
buf[c] = 0;
return 1;
}

static int
Expand Down Expand Up @@ -385,9 +386,10 @@ get_run_time_ms(struct rusage *rus)

char buf[PROC_BUF_SIZE], *x;
int utime, stime;
static int proc_stat_fd;
static int proc_stat_fd = -1;

read_proc_file(buf, "stat", &proc_stat_fd);
if (!read_proc_file(buf, "stat", &proc_stat_fd))
return 0;
x = buf;
while (*x && *x != ' ')
x++;
Expand Down

0 comments on commit fe211cb

Please sign in to comment.