[CRIU] [PATCH 04/11] util: Ability to ignore errno when opening proc

Pavel Emelyanov xemul at parallels.com
Tue Dec 15 11:24:39 PST 2015


When run from regular user criu will get EACCES/EPERM from
opening proc, but in some situations criu will now how to
deal with it. So this patch makes it possible not to print
error message in logs for such cases.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 include/util.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/util.h b/include/util.h
index df708c8..d68946c 100644
--- a/include/util.h
+++ b/include/util.h
@@ -75,11 +75,11 @@ extern int set_proc_fd(int fd);
 
 extern int do_open_proc(pid_t pid, int flags, const char *fmt, ...);
 
-#define __open_proc(pid, flags, fmt, ...)				\
+#define __open_proc(pid, ier, flags, fmt, ...)				\
 	({								\
 		int __fd = do_open_proc(pid, flags,			\
 					fmt, ##__VA_ARGS__);		\
-		if (__fd < 0)						\
+		if (__fd < 0 && (errno != ier))				\
 			pr_perror("Can't open %d/" fmt " on procfs",	\
 					pid, ##__VA_ARGS__);		\
 									\
@@ -88,14 +88,14 @@ extern int do_open_proc(pid_t pid, int flags, const char *fmt, ...);
 
 /* int open_proc(pid_t pid, const char *fmt, ...); */
 #define open_proc(pid, fmt, ...)				\
-	__open_proc(pid, O_RDONLY, fmt, ##__VA_ARGS__)
+	__open_proc(pid, 0, O_RDONLY, fmt, ##__VA_ARGS__)
 
 /* int open_proc_rw(pid_t pid, const char *fmt, ...); */
 #define open_proc_rw(pid, fmt, ...)				\
-	__open_proc(pid, O_RDWR, fmt, ##__VA_ARGS__)
+	__open_proc(pid, 0, O_RDWR, fmt, ##__VA_ARGS__)
 
 #define open_proc_path(pid, fmt, ...)				\
-	__open_proc(pid, O_PATH, fmt, ##__VA_ARGS__)
+	__open_proc(pid, 0, O_PATH, fmt, ##__VA_ARGS__)
 
 /* DIR *opendir_proc(pid_t pid, const char *fmt, ...); */
 #define opendir_proc(pid, fmt, ...)					\
-- 
1.9.3




More information about the CRIU mailing list