From df1729e3eca2daea114e2d031bc2c016ec55c457 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 15 Dec 2015 22:24:39 +0300 Subject: [PATCH] util: Ability to ignore errno when opening proc 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 Looks-good-to-me: Andrew Vagin --- include/util.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/util.h b/include/util.h index 22a67a9d8..a64782783 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, ...) \