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,69 +1701,78 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args) ...@@ -1700,69 +1701,78 @@ 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;
timer = xzalloc(sizeof(struct proc_posix_timer)); if (IS_ERR(s))
if (timer == NULL)
goto err; goto err;
if (sscanf(s, "ID: %ld", pr_err("%s\n", s);
&timer->spt.it_id) != 1) switch (i % 4) {
goto errf; case 0:
if (!(s = breadline(&f))) timer = xzalloc(sizeof(struct proc_posix_timer));
goto errf; if (timer == NULL)
if (sscanf(s, "signal: %d/%16s", goto err;
&timer->spt.si_signo, pbuf) != 2)
goto errf;
if (!(s = breadline(&f)))
goto errf;
if (sscanf(s, "notify: %6[a-z]/%3[a-z].%d\n",
sigpid, tidpid, &pid_t) != 3)
goto errf;
if (!(s = breadline(&f)))
goto errf;
if (sscanf(s, "ClockID: %d\n",
&timer->spt.clock_id) != 1)
goto errf;
timer->spt.sival_ptr = NULL;
if (sscanf(pbuf, "%p", &timer->spt.sival_ptr) != 1 &&
strcmp(pbuf, "(null)")) {
pr_err("Unable to parse '%s'\n", pbuf);
goto errf;
}
if ( tidpid[0] == 't') { if (sscanf(s, "ID: %ld",
timer->spt.it_sigev_notify = SIGEV_THREAD_ID; &timer->spt.it_id) != 1)
} else { goto err;
switch (sigpid[0]) { break;
case 's' : case 1:
timer->spt.it_sigev_notify = SIGEV_SIGNAL; if (sscanf(s, "signal: %d/%16s",
break; &timer->spt.si_signo, pbuf) != 2)
case 't' : goto err;
timer->spt.it_sigev_notify = SIGEV_THREAD; break;
break; case 2:
default : if (sscanf(s, "notify: %6[a-z]/%3[a-z].%d\n",
timer->spt.it_sigev_notify = SIGEV_NONE; sigpid, tidpid, &pid_t) != 3)
break; goto err;
break;
case 3:
if (sscanf(s, "ClockID: %d\n",
&timer->spt.clock_id) != 1)
goto err;
timer->spt.sival_ptr = NULL;
if (sscanf(pbuf, "%p", &timer->spt.sival_ptr) != 1 &&
strcmp(pbuf, "(null)")) {
pr_err("Unable to parse '%s'\n", pbuf);
goto err;
}
if ( tidpid[0] == 't') {
timer->spt.it_sigev_notify = SIGEV_THREAD_ID;
} else {
switch (sigpid[0]) {
case 's' :
timer->spt.it_sigev_notify = SIGEV_SIGNAL;
break;
case 't' :
timer->spt.it_sigev_notify = SIGEV_THREAD;
break;
default :
timer->spt.it_sigev_notify = SIGEV_NONE;
break;
}
} }
}
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