mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 14:55:39 +00:00
proc-parse: Parse pid's fdinfo entries
The existing code opens "self" and parses what's in there, just twist the code a little to accept generic pid. Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
@@ -154,6 +154,8 @@ union fdinfo_entries {
|
|||||||
|
|
||||||
extern int parse_fdinfo(int fd, int type,
|
extern int parse_fdinfo(int fd, int type,
|
||||||
int (*cb)(union fdinfo_entries *e, void *arg), void *arg);
|
int (*cb)(union fdinfo_entries *e, void *arg), void *arg);
|
||||||
|
extern int parse_fdinfo_pid(int pid, int fd, int type,
|
||||||
|
int (*cb)(union fdinfo_entries *e, void *arg), void *arg);
|
||||||
extern int parse_cpuinfo_features(int (*handler)(char *tok));
|
extern int parse_cpuinfo_features(int (*handler)(char *tok));
|
||||||
extern int parse_file_locks(void);
|
extern int parse_file_locks(void);
|
||||||
|
|
||||||
|
21
proc_parse.c
21
proc_parse.c
@@ -880,7 +880,7 @@ static void parse_fhandle_encoded(char *tok, FhEntry *fh)
|
|||||||
|
|
||||||
#define fdinfo_field(str, field) !strncmp(str, field":", sizeof(field))
|
#define fdinfo_field(str, field) !strncmp(str, field":", sizeof(field))
|
||||||
|
|
||||||
int parse_fdinfo(int fd, int type,
|
static int parse_fdinfo_pid_s(char *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;
|
FILE *f;
|
||||||
@@ -888,10 +888,10 @@ int parse_fdinfo(int fd, int type,
|
|||||||
bool entry_met = false;
|
bool entry_met = false;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
sprintf(str, "/proc/self/fdinfo/%d", fd);
|
sprintf(str, "/proc/%s/fdinfo/%d", pid, fd);
|
||||||
f = fopen(str, "r");
|
f = fopen(str, "r");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
pr_perror("Can't open fdinfo to parse");
|
pr_perror("Can't open %s to parse", str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1084,6 +1084,21 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int parse_fdinfo_pid(int pid, int fd, int type,
|
||||||
|
int (*cb)(union fdinfo_entries *e, void *arg), void *arg)
|
||||||
|
{
|
||||||
|
char pid_s[10];
|
||||||
|
|
||||||
|
sprintf(pid_s, "%d", pid);
|
||||||
|
return parse_fdinfo_pid_s(pid_s, fd, type, cb, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
int parse_fdinfo(int fd, int type,
|
||||||
|
int (*cb)(union fdinfo_entries *e, void *arg), void *arg)
|
||||||
|
{
|
||||||
|
return parse_fdinfo_pid_s("self", fd, type, cb, arg);
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_file_lock_buf(char *buf, struct file_lock *fl,
|
static int parse_file_lock_buf(char *buf, struct file_lock *fl,
|
||||||
bool is_blocked)
|
bool is_blocked)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user