Re: [lxc-devel] [PATCH v2] open_without_symlink: Don't SYSERROR on something else than ELOOP

2016-03-23 Thread Christian Brauner
Hi,

I've applied your changes to a local branch of mine to have them tested by our
Jenkins testsuite:

https://github.com/lxc/lxc/pull/911

Once that passes I'll merge (Your authorship and signoff are of course
preserved!).

Best
Christian

On Wed, Mar 23, 2016 at 12:30:05PM +, Bogdan Purcareata wrote:
> The open_without_symlink routine has been specifically created to prevent
> mounts with synlinks as source or destination. Keep SYSERROR'ing in that
> particular scenario, but leave error handling to calling functions for the
> other ones - e.g. optional bind mount when the source dir doesn't exist
> throws a nasty error.
> 
> Changes since v1:
> - maintain errno in safe_mount when opening the mount destination fails
> 
> Signed-off-by: Bogdan Purcareata 
> ---
>  src/lxc/utils.c | 7 ---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/src/lxc/utils.c b/src/lxc/utils.c
> index 6bee698..8e7ebbc 100644
> --- a/src/lxc/utils.c
> +++ b/src/lxc/utils.c
> @@ -1621,8 +1621,6 @@ static int open_without_symlink(const char *target, 
> const char *prefix_skip)
>   errno = saved_errno;
>   if (errno == ELOOP)
>   SYSERROR("%s in %s was a symbolic link!", 
> nextpath, target);
> - else
> - SYSERROR("Error examining %s in %s", nextpath, 
> target);
>   goto out;
>   }
>   }
> @@ -1667,8 +1665,11 @@ int safe_mount(const char *src, const char *dest, 
> const char *fstype,
>  
>   destfd = open_without_symlink(dest, rootfs);
>   if (destfd < 0) {
> - if (srcfd != -1)
> + if (srcfd != -1) {
> + saved_errno = errno;
>   close(srcfd);
> + errno = saved_errno;
> + }
>   return destfd;
>   }
>  
> -- 
> 1.9.1
> 
> ___
> lxc-devel mailing list
> lxc-devel@lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


[lxc-devel] [PATCH v2] open_without_symlink: Don't SYSERROR on something else than ELOOP

2016-03-23 Thread Bogdan Purcareata
The open_without_symlink routine has been specifically created to prevent
mounts with synlinks as source or destination. Keep SYSERROR'ing in that
particular scenario, but leave error handling to calling functions for the
other ones - e.g. optional bind mount when the source dir doesn't exist
throws a nasty error.

Changes since v1:
- maintain errno in safe_mount when opening the mount destination fails

Signed-off-by: Bogdan Purcareata 
---
 src/lxc/utils.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 6bee698..8e7ebbc 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -1621,8 +1621,6 @@ static int open_without_symlink(const char *target, const 
char *prefix_skip)
errno = saved_errno;
if (errno == ELOOP)
SYSERROR("%s in %s was a symbolic link!", 
nextpath, target);
-   else
-   SYSERROR("Error examining %s in %s", nextpath, 
target);
goto out;
}
}
@@ -1667,8 +1665,11 @@ int safe_mount(const char *src, const char *dest, const 
char *fstype,
 
destfd = open_without_symlink(dest, rootfs);
if (destfd < 0) {
-   if (srcfd != -1)
+   if (srcfd != -1) {
+   saved_errno = errno;
close(srcfd);
+   errno = saved_errno;
+   }
return destfd;
}
 
-- 
1.9.1

___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel