Commit 2c8af6b8 authored by Pavel Emelyanov's avatar Pavel Emelyanov

proc_parse: Rework fdinfo parser to use bfd

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 53771adc
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "kerndat.h" #include "kerndat.h"
#include "vdso.h" #include "vdso.h"
#include "vma.h" #include "vma.h"
#include "bfd.h"
#include "proc_parse.h" #include "proc_parse.h"
#include "cr_options.h" #include "cr_options.h"
#include "sysfs_parse.h" #include "sysfs_parse.h"
...@@ -1080,7 +1080,7 @@ static void parse_fhandle_encoded(char *tok, FhEntry *fh) ...@@ -1080,7 +1080,7 @@ static void parse_fhandle_encoded(char *tok, FhEntry *fh)
} }
} }
static int parse_timerfd(FILE *f, char *buf, size_t size, TimerfdEntry *tfy) static int parse_timerfd(struct bfd *f, char *str, TimerfdEntry *tfy)
{ {
/* /*
* Format is * Format is
...@@ -1093,26 +1093,30 @@ static int parse_timerfd(FILE *f, char *buf, size_t size, TimerfdEntry *tfy) ...@@ -1093,26 +1093,30 @@ static int parse_timerfd(FILE *f, char *buf, size_t size, TimerfdEntry *tfy)
if (sscanf(buf, "clockid: %d", &tfy->clockid) != 1) if (sscanf(buf, "clockid: %d", &tfy->clockid) != 1)
goto parse_err; goto parse_err;
if (!fgets(buf, size, f)) str = breadline(f);
if (str == NULL || str == BREADERR)
goto nodata; goto nodata;
if (sscanf(buf, "ticks: %llu", (unsigned long long *)&tfy->ticks) != 1) if (sscanf(str, "ticks: %llu", (unsigned long long *)&tfy->ticks) != 1)
goto parse_err; goto parse_err;
if (!fgets(buf, size, f)) str = breadline(f);
if (str == NULL || str == BREADERR)
goto nodata; goto nodata;
if (sscanf(buf, "settime flags: 0%o", &tfy->settime_flags) != 1) if (sscanf(str, "settime flags: 0%o", &tfy->settime_flags) != 1)
goto parse_err; goto parse_err;
if (!fgets(buf, size, f)) str = breadline(f);
if (str == NULL || str == BREADERR)
goto nodata; goto nodata;
if (sscanf(buf, "it_value: (%llu, %llu)", if (sscanf(str, "it_value: (%llu, %llu)",
(unsigned long long *)&tfy->vsec, (unsigned long long *)&tfy->vsec,
(unsigned long long *)&tfy->vnsec) != 2) (unsigned long long *)&tfy->vnsec) != 2)
goto parse_err; goto parse_err;
if (!fgets(buf, size, f)) str = breadline(f);
if (str == NULL || str == BREADERR)
goto nodata; goto nodata;
if (sscanf(buf, "it_interval: (%llu, %llu)", if (sscanf(str, "it_interval: (%llu, %llu)",
(unsigned long long *)&tfy->isec, (unsigned long long *)&tfy->isec,
(unsigned long long *)&tfy->insec) != 2) (unsigned long long *)&tfy->insec) != 2)
goto parse_err; goto parse_err;
...@@ -1130,20 +1134,29 @@ nodata: ...@@ -1130,20 +1134,29 @@ nodata:
static int parse_fdinfo_pid_s(int pid, int fd, int type, static int parse_fdinfo_pid_s(int pid, int fd, int type,
int (*cb)(union fdinfo_entries *e, void *arg), void *arg) int (*cb)(union fdinfo_entries *e, void *arg), void *arg)
{ {
FILE *f; struct bfd f;
char str[256]; char *str;
bool entry_met = false; bool entry_met = false;
int ret = -1; int ret = -1;
f = fopen_proc(pid, "fdinfo/%d", fd); f.fd = open_proc(pid, "fdinfo/%d", fd);
if (!f) { if (f.fd < 0) {
pr_perror("Can't open %s to parse", str); pr_perror("Can't open fdinfo/%d to parse", fd);
return -1; return -1;
} }
while (fgets(str, sizeof(str), f)) { if (bfdopen(&f))
return -1;
while (1) {
union fdinfo_entries entry; union fdinfo_entries entry;
str = breadline(&f);
if (!str)
break;
if (str == BREADERR)
goto out;
if (fdinfo_field(str, "pos") || if (fdinfo_field(str, "pos") ||
fdinfo_field(str, "flags") || fdinfo_field(str, "flags") ||
fdinfo_field(str, "mnt_id")) { fdinfo_field(str, "mnt_id")) {
...@@ -1191,7 +1204,7 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, ...@@ -1191,7 +1204,7 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type,
if (type != FD_TYPES__TIMERFD) if (type != FD_TYPES__TIMERFD)
goto parse_err; goto parse_err;
ret = parse_timerfd(f, str, sizeof(str), &entry.tfy); ret = parse_timerfd(&f, str, &entry.tfy);
if (ret) if (ret)
goto parse_err; goto parse_err;
ret = cb(&entry, arg); ret = cb(&entry, arg);
...@@ -1394,7 +1407,7 @@ parse_err: ...@@ -1394,7 +1407,7 @@ parse_err:
ret = -1; ret = -1;
pr_perror("%s: error parsing [%s] for %d", __func__, str, type); pr_perror("%s: error parsing [%s] for %d", __func__, str, type);
out: out:
fclose(f); bclose(&f);
return ret; return ret;
} }
......
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