[05/14] Use pr_perror() on open() failure

Submitted by Kir Kolyshkin on March 21, 2017, 10 p.m.

Details

Message ID 20170321220101.21228-6-kir@openvz.org
State New
Series "Spring '07 cleaning"
Headers show

Commit Message

Kir Kolyshkin March 21, 2017, 10 p.m.
It makes sense to show errno to a user.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
---
 criu/namespaces.c | 2 +-
 criu/sk-unix.c    | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/namespaces.c b/criu/namespaces.c
index 77308cc..01afca4 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -2210,7 +2210,7 @@  static int create_user_ns_hierarhy_fn(void *in_arg)
 		futex_set_and_wake(p_futex, NS__CREATED);
 		fd = open("/proc/self/ns/user", O_RDONLY);
 		if (fd < 0) {
-			pr_err("Can't get self user ns");
+			pr_perror("Can't get self user ns");
 			goto out;
 		}
 		me->user.nsfd_id = fdstore_add(fd);
diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index a44d998..c0759dc 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -887,7 +887,7 @@  static int prep_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, int *prev
 
 	*prev_cwd_fd = open(".", O_RDONLY);
 	if (*prev_cwd_fd < 0) {
-		pr_err("Can't open current dir\n");
+		pr_perror("Can't open current dir");
 		return -1;
 	}
 
@@ -896,7 +896,7 @@  static int prep_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, int *prev
 			root = lookup_ns_by_id(root_item->ids->mnt_ns_id, &mnt_ns_desc);
 		*prev_root_fd = open("/", O_RDONLY);
 		if (*prev_root_fd < 0) {
-			pr_err("Can't open current root\n");
+			pr_perror("Can't open current root");
 			goto err;
 		}
 

Comments

Pavel Emelianov March 22, 2017, 2:09 p.m.
On 03/22/2017 01:00 AM, Kir Kolyshkin wrote:
> It makes sense to show errno to a user.
> 
> Signed-off-by: Kir Kolyshkin <kir@openvz.org>
> ---
>  criu/namespaces.c | 2 +-
>  criu/sk-unix.c    | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/criu/namespaces.c b/criu/namespaces.c
> index 77308cc..01afca4 100644
> --- a/criu/namespaces.c
> +++ b/criu/namespaces.c
> @@ -2210,7 +2210,7 @@ static int create_user_ns_hierarhy_fn(void *in_arg)
>  		futex_set_and_wake(p_futex, NS__CREATED);
>  		fd = open("/proc/self/ns/user", O_RDONLY);

BTW, would someone also scan for open("/proc...")-s and fix
them to use open_proc-s?

-- Pavel

>  		if (fd < 0) {
> -			pr_err("Can't get self user ns");
> +			pr_perror("Can't get self user ns");
>  			goto out;
>  		}
>  		me->user.nsfd_id = fdstore_add(fd);
> diff --git a/criu/sk-unix.c b/criu/sk-unix.c
> index a44d998..c0759dc 100644
> --- a/criu/sk-unix.c
> +++ b/criu/sk-unix.c
> @@ -887,7 +887,7 @@ static int prep_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, int *prev
>  
>  	*prev_cwd_fd = open(".", O_RDONLY);
>  	if (*prev_cwd_fd < 0) {
> -		pr_err("Can't open current dir\n");
> +		pr_perror("Can't open current dir");
>  		return -1;
>  	}
>  
> @@ -896,7 +896,7 @@ static int prep_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, int *prev
>  			root = lookup_ns_by_id(root_item->ids->mnt_ns_id, &mnt_ns_desc);
>  		*prev_root_fd = open("/", O_RDONLY);
>  		if (*prev_root_fd < 0) {
> -			pr_err("Can't open current root\n");
> +			pr_perror("Can't open current root");
>  			goto err;
>  		}
>  
>