mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 01:51:51 +00:00
util: Helper for reading a string from image
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
fc416d8694
commit
57095eb946
11
files-reg.c
11
files-reg.c
@ -394,8 +394,6 @@ int collect_reg_files(void)
|
||||
return -1;
|
||||
|
||||
while (1) {
|
||||
int len;
|
||||
|
||||
rfi = xmalloc(sizeof(*rfi));
|
||||
ret = -1;
|
||||
if (rfi == NULL)
|
||||
@ -406,18 +404,11 @@ int collect_reg_files(void)
|
||||
if (ret <= 0)
|
||||
break;
|
||||
|
||||
len = rfi->rfe.len;
|
||||
rfi->path = xmalloc(len + 1);
|
||||
ret = -1;
|
||||
if (rfi->path == NULL)
|
||||
break;
|
||||
|
||||
ret = read_img_buf(fd, rfi->path, len);
|
||||
ret = read_img_str(fd, &rfi->path, rfi->rfe.len);
|
||||
if (ret < 0)
|
||||
break;
|
||||
|
||||
rfi->remap_path = NULL;
|
||||
rfi->path[len] = '\0';
|
||||
|
||||
pr_info("Collected [%s] ID %#x\n", rfi->path, rfi->rfe.id);
|
||||
file_desc_add(&rfi->d, rfi->rfe.id, ®_desc_ops);
|
||||
|
@ -235,6 +235,8 @@ int do_open_proc(pid_t pid, int flags, const char *fmt, ...);
|
||||
___p; \
|
||||
})
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#define xstrdup(str) __xalloc(strdup, strlen(str) + 1, str)
|
||||
#define xmalloc(size) __xalloc(malloc, size, size)
|
||||
#define xzalloc(size) __xalloc(calloc, size, 1, size)
|
||||
@ -287,4 +289,29 @@ int is_anon_link_type(int lfd, char *type);
|
||||
((c) >= 'a' && (c) <= 'f') || \
|
||||
((c) >= 'A' && (c) <= 'F'))
|
||||
|
||||
/*
|
||||
* read_img_str -- same as read_img_buf, but allocates memory for
|
||||
* the buffer and puts the '\0' at the end
|
||||
*/
|
||||
|
||||
static inline int read_img_str(int fd, char **pstr, int size)
|
||||
{
|
||||
int ret;
|
||||
char *str;
|
||||
|
||||
str = xmalloc(size + 1);
|
||||
if (!str)
|
||||
return -1;
|
||||
|
||||
ret = read_img_buf(fd, str, size);
|
||||
if (ret < 0) {
|
||||
xfree(str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
str[size] = '\0';
|
||||
*pstr = str;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* UTIL_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user