Commit 4a36feac authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

parse_proc: take into account that breadline can return an error code

Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 6b4ecb90
...@@ -1675,8 +1675,9 @@ void free_posix_timers(struct proc_posix_timers_stat *st) ...@@ -1675,8 +1675,9 @@ void free_posix_timers(struct proc_posix_timers_stat *st)
int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args) int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
{ {
int ret = 0; int exit_code = -1;
int pid_t; int pid_t;
int i = 0;
struct bfd f; struct bfd f;
char *s; char *s;
...@@ -1700,37 +1701,43 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args) ...@@ -1700,37 +1701,43 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
while (1) { while (1) {
char pbuf[17]; /* 16 + eol */ char pbuf[17]; /* 16 + eol */
if (!(s = breadline(&f))) s = breadline(&f);
goto out; if (!s)
break;
if (IS_ERR(s))
goto err;
pr_err("%s\n", s);
switch (i % 4) {
case 0:
timer = xzalloc(sizeof(struct proc_posix_timer)); timer = xzalloc(sizeof(struct proc_posix_timer));
if (timer == NULL) if (timer == NULL)
goto err; goto err;
if (sscanf(s, "ID: %ld", if (sscanf(s, "ID: %ld",
&timer->spt.it_id) != 1) &timer->spt.it_id) != 1)
goto errf; goto err;
if (!(s = breadline(&f))) break;
goto errf; case 1:
if (sscanf(s, "signal: %d/%16s", if (sscanf(s, "signal: %d/%16s",
&timer->spt.si_signo, pbuf) != 2) &timer->spt.si_signo, pbuf) != 2)
goto errf; goto err;
if (!(s = breadline(&f))) break;
goto errf; case 2:
if (sscanf(s, "notify: %6[a-z]/%3[a-z].%d\n", if (sscanf(s, "notify: %6[a-z]/%3[a-z].%d\n",
sigpid, tidpid, &pid_t) != 3) sigpid, tidpid, &pid_t) != 3)
goto errf; goto err;
if (!(s = breadline(&f))) break;
goto errf; case 3:
if (sscanf(s, "ClockID: %d\n", if (sscanf(s, "ClockID: %d\n",
&timer->spt.clock_id) != 1) &timer->spt.clock_id) != 1)
goto errf; goto err;
timer->spt.sival_ptr = NULL; timer->spt.sival_ptr = NULL;
if (sscanf(pbuf, "%p", &timer->spt.sival_ptr) != 1 && if (sscanf(pbuf, "%p", &timer->spt.sival_ptr) != 1 &&
strcmp(pbuf, "(null)")) { strcmp(pbuf, "(null)")) {
pr_err("Unable to parse '%s'\n", pbuf); pr_err("Unable to parse '%s'\n", pbuf);
goto errf; goto err;
} }
if ( tidpid[0] == 't') { if ( tidpid[0] == 't') {
...@@ -1752,17 +1759,20 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args) ...@@ -1752,17 +1759,20 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
list_add(&timer->list, &args->timers); list_add(&timer->list, &args->timers);
timer = NULL; timer = NULL;
args->timer_n++; args->timer_n++;
break;
}
i++;
} }
errf: exit_code = 0;
xfree(timer); out:
bclose(&f);
return exit_code;
err: err:
xfree(timer);
free_posix_timers(args); free_posix_timers(args);
pr_perror("Parse error in posix timers proc file!"); pr_perror("Parse error in posix timers proc file!");
ret = -1; goto out;
out:
bclose(&f);
return ret;
} }
int parse_threads(int pid, struct pid **_t, int *_n) int parse_threads(int pid, struct pid **_t, int *_n)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment