Commit f8ad351f authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

util: Make open_fmt being more general

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 26857cc4
......@@ -292,7 +292,7 @@ static int prepare_shmem_pid(int pid)
int sh_fd;
u32 type = 0;
sh_fd = open_fmt("shmem-%d.img", pid, O_RDONLY);
sh_fd = open_fmt("shmem-%d.img", O_RDONLY, pid);
if (sh_fd < 0) {
perror("Can't open shmem info");
return 1;
......@@ -330,7 +330,7 @@ static int prepare_pipes_pid(int pid)
int p_fd;
u32 type = 0;
p_fd = open_fmt("pipes-%d.img", pid, O_RDONLY);
p_fd = open_fmt("pipes-%d.img", O_RDONLY, pid);
if (p_fd < 0) {
perror("Can't open pipes image");
return 1;
......@@ -511,7 +511,7 @@ static int prepare_fds(int pid)
pr_info("%d: Opening files img\n", pid);
fdinfo_fd = open_fmt("fdinfo-%d.img", pid, O_RDONLY);
fdinfo_fd = open_fmt("fdinfo-%d.img", O_RDONLY, pid);
if (fdinfo_fd < 0) {
pr_perror("Can't open %d fdinfo", pid);
return 1;
......@@ -590,7 +590,7 @@ static int prepare_shmem(int pid)
int sh_fd;
u32 type = 0;
sh_fd = open_fmt("shmem-%d.img", pid, O_RDONLY);
sh_fd = open_fmt("shmem-%d.img", O_RDONLY, pid);
if (sh_fd < 0) {
perror("Can't open shmem info");
return 1;
......@@ -744,7 +744,7 @@ static int fixup_pages_data(int pid, int fd)
pr_info("%d: Reading shmem pages img\n", pid);
shfd = open_fmt("pages-shmem-%d.img", pid, O_RDONLY);
shfd = open_fmt("pages-shmem-%d.img", O_RDONLY, pid);
if (shfd < 0) {
pr_perror("Can't open %d shmem image %s", pid);
return 1;
......@@ -826,7 +826,7 @@ static int prepare_and_execute_image(int pid)
int fd, fd_new;
struct stat buf;
fd = open_fmt("core-%d.img", pid, O_RDONLY);
fd = open_fmt("core-%d.img", O_RDONLY, pid);
if (fd < 0) {
perror("Can't open exec image");
return 1;
......@@ -1037,7 +1037,7 @@ static int prepare_pipes(int pid)
pr_info("%d: Opening pipes\n", pid);
pipes_fd = open_fmt("pipes-%d.img", pid, O_RDONLY);
pipes_fd = open_fmt("pipes-%d.img", O_RDONLY, pid);
if (pipes_fd < 0) {
perror("Can't open pipes img");
return 1;
......
......@@ -156,7 +156,7 @@ 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);
int open_fmt(char *fmt, int mode, ...);
#define __xalloc(op, size, ...) \
({ \
......
......@@ -420,10 +420,14 @@ FILE *fopen_proc(char *fmt, char *mode, ...)
return fopen(fname, mode);
}
int open_fmt(char *fmt, int pid, int mode)
int open_fmt(char *fmt, int mode, ...)
{
char fname[128];
va_list args;
va_start(args, mode);
vsnprintf(fname, sizeof(fname), fmt, args);
va_end(args);
snprintf(fname, sizeof(fname), fmt, pid);
return open(fname, mode);
}
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