mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 14:55:39 +00:00
proc-parse: Add alloc_fhandle/free_fhandle helpers
This removes code duplication. There is no strong need for free_fhandle but I decided to add it to be consistent with alloc/free handlers. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
8573f5ec53
commit
d6664eea4a
27
proc_parse.c
27
proc_parse.c
@@ -831,6 +831,19 @@ static char nybble(const char n)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int alloc_fhandle(FhEntry *fh)
|
||||||
|
{
|
||||||
|
fh->n_handle = FH_ENTRY_SIZES__min_entries;
|
||||||
|
fh->handle = xmalloc(pb_repeated_size(fh, handle));
|
||||||
|
|
||||||
|
return fh->handle == NULL ? -1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void free_fhandle(FhEntry *fh)
|
||||||
|
{
|
||||||
|
xfree(fh->handle);
|
||||||
|
}
|
||||||
|
|
||||||
static void parse_fhandle_encoded(char *tok, FhEntry *fh)
|
static void parse_fhandle_encoded(char *tok, FhEntry *fh)
|
||||||
{
|
{
|
||||||
char *d = (char *)fh->handle;
|
char *d = (char *)fh->handle;
|
||||||
@@ -958,17 +971,14 @@ int parse_fdinfo(int fd, int type,
|
|||||||
if (ret != 7)
|
if (ret != 7)
|
||||||
goto parse_err;
|
goto parse_err;
|
||||||
|
|
||||||
f_handle.n_handle = FH_ENTRY_SIZES__min_entries;
|
if (alloc_fhandle(&f_handle))
|
||||||
f_handle.handle = xmalloc(pb_repeated_size(&f_handle, handle));
|
|
||||||
if (!f_handle.handle)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
parse_fhandle_encoded(str + hoff, &f_handle);
|
parse_fhandle_encoded(str + hoff, &f_handle);
|
||||||
|
|
||||||
entry.ffy.type = MARK_TYPE__INODE;
|
entry.ffy.type = MARK_TYPE__INODE;
|
||||||
ret = cb(&entry, arg);
|
ret = cb(&entry, arg);
|
||||||
|
|
||||||
xfree(f_handle.handle);
|
free_fhandle(&f_handle);
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
@@ -1021,16 +1031,13 @@ int parse_fdinfo(int fd, int type,
|
|||||||
if (ret != 7)
|
if (ret != 7)
|
||||||
goto parse_err;
|
goto parse_err;
|
||||||
|
|
||||||
f_handle.n_handle = FH_ENTRY_SIZES__min_entries;
|
if (alloc_fhandle(&f_handle))
|
||||||
f_handle.handle = xmalloc(pb_repeated_size(&f_handle, handle));
|
|
||||||
if (!f_handle.handle)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
parse_fhandle_encoded(str + hoff, entry.ify.f_handle);
|
parse_fhandle_encoded(str + hoff, entry.ify.f_handle);
|
||||||
|
|
||||||
ret = cb(&entry, arg);
|
ret = cb(&entry, arg);
|
||||||
|
|
||||||
xfree(f_handle.handle);
|
free_fhandle(&f_handle);
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
Reference in New Issue
Block a user