[CRIU] [PATCH] fopen_proc(), opendir_proc(): don't print two errors

Kir Kolyshkin kir at openvz.org
Wed Nov 20 21:33:24 PST 2013


Both fopen_proc() and opendir_proc() are calling open_proc().
If open_proc() fails, it prints an error message. Before this
patch, a second error message was printed due to missing brackets.
This second message is a bit more specific (it tells the exact
file/dir we failed to open) but it is redundant, because more
generic error was already printed by open_proc(). It is also
can be misleading because for the second message we reuse
the same errno while we should not.

So, let's remove this second error message print by using brackets.

Alternatively, we could leave this as is (just fixing indentation)
and let two errors be printed -- there is nothing wrong with that,
but I think in this case less messages is better.

This is a fix to commit 5661d80.

Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 include/util.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/util.h b/include/util.h
index 298d623..bad91b2 100644
--- a/include/util.h
+++ b/include/util.h
@@ -172,13 +172,13 @@ extern int do_open_proc(pid_t pid, int flags, const char *fmt, ...);
 		int __fd = open_proc(pid, fmt, ##__VA_ARGS__);		\
 		DIR *__d = NULL;					\
 									\
-		if (__fd >= 0)						\
+		if (__fd >= 0) {					\
 			__d = fdopendir(__fd);				\
 			if (__d == NULL)				\
 				pr_perror("Can't fdopendir %d "		\
 					"(/proc/%d/" fmt ")",		\
 					__fd, pid, ##__VA_ARGS__);	\
-									\
+		}							\
 		__d;							\
 	 })
 
@@ -188,13 +188,13 @@ extern int do_open_proc(pid_t pid, int flags, const char *fmt, ...);
 		int __fd = open_proc(pid,  fmt, ##__VA_ARGS__);		\
 		FILE *__f = NULL;					\
 									\
-		if (__fd >= 0)						\
+		if (__fd >= 0) {					\
 			__f = fdopen(__fd, "r");			\
 			if (__f == NULL)				\
 				pr_perror("Can't fdopen %d "		\
 					"(/proc/%d/" fmt ")",		\
 					__fd, pid, ##__VA_ARGS__);	\
-									\
+		}							\
 		__f;							\
 	 })
 
-- 
1.8.1.4



More information about the CRIU mailing list