[systemd-devel] [PATCH] nspawn: use the mode_t of the source file for copy_file()

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Sat Oct 26 21:17:10 CEST 2013


On Sat, Oct 26, 2013 at 12:59:40AM +0100, Djalal Harouni wrote:
> Instead of hard-coding the permission mode, stat() the source file and
> use its mode to create the destination file.
Hi,

Is this patch trying to fix something specific? copy_file is only used
to copy resolv.conf into the container. It's unlikely that the mode
from host is relevant in the container.

> Signed-off-by: Djalal Harouni <tixxdz at opendz.org>
No need to add that in systemd.

Zbyszek

> ---
>  src/shared/util.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/src/shared/util.c b/src/shared/util.c
> index d086fac..0886674 100644
> --- a/src/shared/util.c
> +++ b/src/shared/util.c
> @@ -4133,16 +4133,20 @@ int vt_disallocate(const char *name) {
>  
>  int copy_file(const char *from, const char *to, int flags) {
>          _cleanup_close_ int fdf = -1;
> +        struct stat st = {};
>          int r, fdt;
>  
>          assert(from);
>          assert(to);
>  
> +        if (stat(from, &st) < 0)
> +                return -errno;
> +
>          fdf = open(from, O_RDONLY|O_CLOEXEC|O_NOCTTY);
>          if (fdf < 0)
>                  return -errno;
>  
> -        fdt = open(to, flags|O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0644);
> +        fdt = open(to, flags|O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, st.st_mode);
>          if (fdt < 0)
>                  return -errno;


More information about the systemd-devel mailing list