mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 14:25:49 +00:00
util: Move various helpers there
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
27
cr-dump.c
27
cr-dump.c
@@ -40,34 +40,7 @@
|
||||
# error No x86-32 support yet
|
||||
#endif
|
||||
|
||||
static DIR *opendir_proc(char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
char path[128];
|
||||
|
||||
sprintf(path, "/proc/");
|
||||
va_start(args, fmt);
|
||||
vsnprintf(path + 6, sizeof(path) - 6, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return opendir(path);
|
||||
}
|
||||
|
||||
static FILE *fopen_proc(char *fmt, char *mode, ...)
|
||||
{
|
||||
va_list args;
|
||||
char fname[128];
|
||||
|
||||
sprintf(fname, "/proc/");
|
||||
va_start(args, mode);
|
||||
vsnprintf(fname + 6, sizeof(fname) - 6, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return fopen(fname, mode);
|
||||
}
|
||||
|
||||
static char big_buffer[PATH_MAX];
|
||||
|
||||
static char loc_buf[PAGE_SIZE];
|
||||
|
||||
static void free_pstree(struct list_head *pstree_list)
|
||||
|
@@ -89,14 +89,6 @@ static int nr_pipes;
|
||||
|
||||
static int restore_task_with_children(int my_pid, char *pstree_path);
|
||||
|
||||
static int open_fmt(char *fmt, int pid, int mode)
|
||||
{
|
||||
char fname[64];
|
||||
|
||||
snprintf(fname, sizeof(fname), fmt, pid);
|
||||
return open(fname, mode);
|
||||
}
|
||||
|
||||
static void show_saved_shmems(void)
|
||||
{
|
||||
int i;
|
||||
|
@@ -7,8 +7,10 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "compiler.h"
|
||||
#include "types.h"
|
||||
@@ -152,6 +154,10 @@ int reopen_fd_as(int new_fd, int old_fd);
|
||||
int parse_maps(pid_t pid, struct list_head *vma_list);
|
||||
int close_safe(int *fd);
|
||||
|
||||
DIR *opendir_proc(char *fmt, ...);
|
||||
FILE *fopen_proc(char *fmt, char *mode, ...);
|
||||
int open_fmt(char *fmt, int pid, int mode);
|
||||
|
||||
#define __xalloc(op, size, ...) \
|
||||
({ \
|
||||
void *___p = op( __VA_ARGS__ ); \
|
||||
|
34
util.c
34
util.c
@@ -393,3 +393,37 @@ err_bogus_mapping:
|
||||
vma_area->vma.end);
|
||||
goto err;
|
||||
}
|
||||
|
||||
DIR *opendir_proc(char *fmt, ...)
|
||||
{
|
||||
char path[128];
|
||||
va_list args;
|
||||
|
||||
sprintf(path, "/proc/");
|
||||
va_start(args, fmt);
|
||||
vsnprintf(path + 6, sizeof(path) - 6, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return opendir(path);
|
||||
}
|
||||
|
||||
FILE *fopen_proc(char *fmt, char *mode, ...)
|
||||
{
|
||||
char fname[128];
|
||||
va_list args;
|
||||
|
||||
sprintf(fname, "/proc/");
|
||||
va_start(args, mode);
|
||||
vsnprintf(fname + 6, sizeof(fname) - 6, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return fopen(fname, mode);
|
||||
}
|
||||
|
||||
int open_fmt(char *fmt, int pid, int mode)
|
||||
{
|
||||
char fname[128];
|
||||
|
||||
snprintf(fname, sizeof(fname), fmt, pid);
|
||||
return open(fname, mode);
|
||||
}
|
||||
|
Reference in New Issue
Block a user