[CRIU] [PATCH 3/9] open_proc: don't print error twice
Kir Kolyshkin
kir at openvz.org
Mon Nov 7 13:37:47 PST 2016
open_proc* and fopen_proc* are all macros, and they print errors in case
something is wrong (and as they are macros they print correct file:line
info, too). So, there is no need to print another error message
right after calling those.
This fixes double error messages like these:
(00.047295) Error (criu/proc_parse.c:990): Can't open 18472/status on procfs: No such file or directory
(00.047298) Error (criu/proc_parse.c:992): Can't open proc status: No such file or directory
Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
criu/autofs.c | 4 +---
criu/cr-check.c | 4 +---
criu/cr-restore.c | 8 ++------
criu/kerndat.c | 4 +---
criu/namespaces.c | 4 +---
criu/net.c | 4 +---
criu/proc_parse.c | 28 +++++++---------------------
criu/seize.c | 2 +-
criu/shmem.c | 3 ---
criu/vdso.c | 4 +---
10 files changed, 16 insertions(+), 49 deletions(-)
diff --git a/criu/autofs.c b/criu/autofs.c
index 345a703..6adc378 100644
--- a/criu/autofs.c
+++ b/criu/autofs.c
@@ -297,10 +297,8 @@ static int autofs_revisit_options(struct mount_info *pm)
}
f = fopen_proc(getpid(), "mountinfo");
- if (!f) {
- pr_perror("Can't open %d mountinfo", getpid());
+ if (!f)
goto free_str;
- }
while (fgets(str, 1024, f)) {
int mnt_id = -1;
diff --git a/criu/cr-check.c b/criu/cr-check.c
index 0422860..d72391f 100644
--- a/criu/cr-check.c
+++ b/criu/cr-check.c
@@ -838,10 +838,8 @@ static int check_autofs_pipe_ino(void)
int ret = -ENOENT;
f = fopen_proc(PROC_SELF, "mountinfo");
- if (!f) {
- pr_perror("Can't open %d mountinfo", getpid());
+ if (!f)
return -1;
- }
while (fgets(str, sizeof(str), f)) {
if (strstr(str, " autofs ")) {
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 4bf61a6..07ec4e1 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1015,10 +1015,8 @@ static inline int fork_with_pid(struct pstree_item *item)
int len;
ca.fd = open_proc_rw(PROC_GEN, LAST_PID_PATH);
- if (ca.fd < 0) {
- pr_perror("%d: Can't open %s", pid, LAST_PID_PATH);
+ if (ca.fd < 0)
goto err;
- }
if (flock(ca.fd, LOCK_EX)) {
close(ca.fd);
@@ -1841,10 +1839,8 @@ static int restore_root_task(struct pstree_item *init)
if (root_ns_mask & CLONE_NEWNS) {
mnt_ns_fd = open_proc(init->pid.real, "ns/mnt");
- if (mnt_ns_fd < 0) {
- pr_perror("Can't open init's mntns fd");
+ if (mnt_ns_fd < 0)
goto out_kill;
- }
}
ret = run_scripts(ACT_SETUP_NS);
diff --git a/criu/kerndat.c b/criu/kerndat.c
index 0a2e5c2..47e566d 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -74,10 +74,8 @@ static int parse_self_maps(unsigned long vm_start, dev_t *device)
char buf[1024];
maps = fopen_proc(PROC_SELF, "maps");
- if (maps == NULL) {
- pr_perror("Can't open self maps");
+ if (maps == NULL)
return -1;
- }
while (fgets(buf, sizeof(buf), maps) != NULL) {
char *end, *aux;
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 5a434a1..26ccf13 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -225,10 +225,8 @@ int switch_ns(int pid, struct ns_desc *nd, int *rst)
int ret;
nsfd = open_proc(pid, "ns/%s", nd->str);
- if (nsfd < 0) {
- pr_perror("Can't open ns file");
+ if (nsfd < 0)
return -1;
- }
ret = switch_ns_by_fd(nsfd, nd, rst);
diff --git a/criu/net.c b/criu/net.c
index f563f00..6e4cfea 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -1151,10 +1151,8 @@ static int restore_one_macvlan(NetDeviceEntry *nde, int nlsk, int criu_nlsk)
extras.link = (int) (unsigned long) val;
my_netns = open_proc(PROC_SELF, "ns/net");
- if (my_netns < 0) {
- pr_perror("couldn't get my netns");
+ if (my_netns < 0)
return -1;
- }
{
struct newlink_req req;
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 0a0de7d..c00e7da 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -423,10 +423,8 @@ int parse_self_maps_lite(struct vm_area_list *vms)
vm_area_list_init(vms);
maps = fopen_proc(PROC_SELF, "maps");
- if (maps == NULL) {
- pr_perror("Can't open self maps");
+ if (maps == NULL)
return -1;
- }
while (fgets(buf, BUF_SIZE, maps) != NULL) {
struct vma_area *vma;
@@ -988,10 +986,8 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
bool parsed_seccomp = false;
f.fd = open_proc(pid, "status");
- if (f.fd < 0) {
- pr_perror("Can't open proc status");
+ if (f.fd < 0)
return -1;
- }
cr->sigpnd = 0;
cr->shdpnd = 0;
@@ -1414,10 +1410,8 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump)
FILE *f;
f = fopen_proc(pid, "mountinfo");
- if (!f) {
- pr_perror("Can't open %d mountinfo", pid);
+ if (!f)
return NULL;
- }
while (fgets(buf, BUF_SIZE, f)) {
struct mount_info *new;
@@ -1626,10 +1620,8 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type,
int ret, exit_code = -1;;
f.fd = open_proc(pid, "fdinfo/%d", fd);
- if (f.fd < 0) {
- pr_perror("Can't open fdinfo/%d to parse", fd);
+ if (f.fd < 0)
return -1;
- }
if (bfdopenr(&f))
return -1;
@@ -2029,10 +2021,8 @@ int parse_file_locks(void)
return 0;
fl_locks = fopen_proc(PROC_GEN, "locks");
- if (!fl_locks) {
- pr_perror("Can't open file locks file!");
+ if (!fl_locks)
return -1;
- }
while (fgets(buf, BUF_SIZE, fl_locks)) {
is_blocked = strstr(buf, "->") != NULL;
@@ -2117,10 +2107,8 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
args->timer_n = 0;
f.fd = open_proc(pid, "timers");
- if (f.fd < 0) {
- pr_perror("Can't open posix timers file!");
+ if (f.fd < 0)
return -1;
- }
if (bfdopenr(&f))
return -1;
@@ -2323,10 +2311,8 @@ int parse_task_cgroup(int pid, struct parasite_dump_cgroup_args *args, struct li
struct cg_ctl *intern, *ext;
f = fopen_proc(pid, "cgroup");
- if (!f) {
- pr_perror("couldn't open task cgroup file");
+ if (!f)
return -1;
- }
ret = parse_cgroup_file(f, retl, n);
fclose(f);
diff --git a/criu/seize.c b/criu/seize.c
index 5a6cef4..7bef10b 100644
--- a/criu/seize.c
+++ b/criu/seize.c
@@ -273,7 +273,7 @@ static int log_unfrozen_stacks(char *root)
stack = open_proc(pid, "stack");
if (stack < 0) {
- pr_perror("couldn't log %d's stack", pid);
+ pr_err("`- couldn't log %d's stack\n", pid);
fclose(f);
return -1;
}
diff --git a/criu/shmem.c b/criu/shmem.c
index 5065abd..b475ebb 100644
--- a/criu/shmem.c
+++ b/criu/shmem.c
@@ -450,9 +450,6 @@ static int shmem_wait_and_open(int pid, struct shmem_info *si, VmaEntry *vi)
pr_info("Opening shmem [%s] \n", path);
ret = open_proc_rw(si->pid, "fd/%d", si->fd);
- if (ret < 0)
- pr_perror(" %d: Can't stat shmem at %s",
- si->pid, path);
futex_inc_and_wake(&si->lock);
if (ret < 0)
return -1;
diff --git a/criu/vdso.c b/criu/vdso.c
index da6e965..1d70f8a 100644
--- a/criu/vdso.c
+++ b/criu/vdso.c
@@ -230,10 +230,8 @@ static int vdso_fill_self_symtable(struct vdso_symtable *s)
*s = (struct vdso_symtable)VDSO_SYMTABLE_INIT;
maps = fopen_proc(PROC_SELF, "maps");
- if (!maps) {
- pr_perror("Can't open self-vma");
+ if (!maps)
return -1;
- }
while (fgets(buf, sizeof(buf), maps)) {
unsigned long start, end;
--
2.7.4
More information about the CRIU
mailing list