mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-02 07:15:31 +00:00
proc_parse: Rework timers parser to use bfd
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
53
proc_parse.c
53
proc_parse.c
@@ -1573,8 +1573,8 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
int pid_t;
|
int pid_t;
|
||||||
|
|
||||||
FILE * file;
|
struct bfd f;
|
||||||
|
char *s;
|
||||||
char sigpid[7];
|
char sigpid[7];
|
||||||
char tidpid[4];
|
char tidpid[4];
|
||||||
|
|
||||||
@@ -1583,40 +1583,48 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
|
|||||||
INIT_LIST_HEAD(&args->timers);
|
INIT_LIST_HEAD(&args->timers);
|
||||||
args->timer_n = 0;
|
args->timer_n = 0;
|
||||||
|
|
||||||
file = fopen_proc(pid, "timers");
|
f.fd = open_proc(pid, "timers");
|
||||||
if (file == NULL) {
|
if (f.fd < 0) {
|
||||||
pr_perror("Can't open posix timers file!");
|
pr_perror("Can't open posix timers file!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bfdopen(&f))
|
||||||
|
return -1;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
char pbuf[17]; /* 16 + eol */
|
char pbuf[17]; /* 16 + eol */
|
||||||
|
|
||||||
timer = xzalloc(sizeof(struct proc_posix_timer));
|
timer = xzalloc(sizeof(struct proc_posix_timer));
|
||||||
if (timer == NULL)
|
if (timer == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
ret = fscanf(file, "ID: %ld\n"
|
if (!(s = breadline(&f)))
|
||||||
"signal: %d/%16s\n"
|
goto out;
|
||||||
"notify: %6[a-z]/%3[a-z].%d\n"
|
if (sscanf(s, "ID: %ld",
|
||||||
"ClockID: %d\n",
|
&timer->spt.it_id) != 1)
|
||||||
&timer->spt.it_id,
|
goto err;
|
||||||
&timer->spt.si_signo, pbuf,
|
if (!(s = breadline(&f)))
|
||||||
sigpid, tidpid, &pid_t,
|
goto err;
|
||||||
&timer->spt.clock_id);
|
if (sscanf(s, "signal: %d/%16s",
|
||||||
if (ret != 7) {
|
&timer->spt.si_signo, pbuf) != 2)
|
||||||
ret = 0;
|
goto err;
|
||||||
xfree(timer);
|
if (!(s = breadline(&f)))
|
||||||
if (feof(file))
|
goto err;
|
||||||
goto out;
|
if (sscanf(s, "notify: %6[a-z]/%3[a-z].%d\n",
|
||||||
|
sigpid, tidpid, &pid_t) != 3)
|
||||||
|
goto err;
|
||||||
|
if (!(s = breadline(&f)))
|
||||||
|
goto err;
|
||||||
|
if (sscanf(s, "ClockID: %d\n",
|
||||||
|
&timer->spt.clock_id) != 1)
|
||||||
goto err;
|
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);
|
||||||
xfree(timer);
|
goto errf;
|
||||||
goto err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( tidpid[0] == 't') {
|
if ( tidpid[0] == 't') {
|
||||||
@@ -1639,12 +1647,15 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
|
|||||||
timer = NULL;
|
timer = NULL;
|
||||||
args->timer_n++;
|
args->timer_n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errf:
|
||||||
|
xfree(timer);
|
||||||
err:
|
err:
|
||||||
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;
|
ret = -1;
|
||||||
out:
|
out:
|
||||||
fclose(file);
|
bclose(&f);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user