mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-25 06:20:06 +00:00
support_chroot_create: Add support for /etc/hosts, /etc/host.conf
This commit is contained in:
parent
a2881ef014
commit
65329bd233
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
2017-09-01 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
|
* support/namespace.h (struct support_chroot_configuration): Add
|
||||||
|
hosts, host_conf.
|
||||||
|
(struct support_chroot): Add path_hosts, path_host_conf.
|
||||||
|
* support/support_chroot.c (write_file): New function.
|
||||||
|
(support_chroot_create): Call it to process /etc/resolv.conf,
|
||||||
|
/etc/hosts, /etc/host.conf.
|
||||||
|
(support_chroot_free): Update.
|
||||||
|
|
||||||
2017-09-01 Florian Weimer <fweimer@redhat.com>
|
2017-09-01 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
* sysdeps/posix/getaddrinfo.c (gaih_inet): Only use h_errno if
|
* sysdeps/posix/getaddrinfo.c (gaih_inet): Only use h_errno if
|
||||||
|
@ -66,7 +66,9 @@ struct support_chroot_configuration
|
|||||||
{
|
{
|
||||||
/* File contents. The files are not created if the field is
|
/* File contents. The files are not created if the field is
|
||||||
NULL. */
|
NULL. */
|
||||||
const char *resolv_conf;
|
const char *resolv_conf; /* /etc/resolv.conf. */
|
||||||
|
const char *hosts; /* /etc/hosts. */
|
||||||
|
const char *host_conf; /* /etc/host.conf. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The result of the creation of a chroot. */
|
/* The result of the creation of a chroot. */
|
||||||
@ -78,8 +80,11 @@ struct support_chroot
|
|||||||
/* Path to the chroot directory. */
|
/* Path to the chroot directory. */
|
||||||
char *path_chroot;
|
char *path_chroot;
|
||||||
|
|
||||||
/* Path to the /etc/resolv.conf file. */
|
/* Paths to files in the chroot. These are absolute and outside of
|
||||||
char *path_resolv_conf;
|
the chroot. */
|
||||||
|
char *path_resolv_conf; /* /etc/resolv.conf. */
|
||||||
|
char *path_hosts; /* /etc/hosts. */
|
||||||
|
char *path_host_conf; /* /etc/host.conf. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Create a chroot environment. The returned data should be freed
|
/* Create a chroot environment. The returned data should be freed
|
||||||
|
@ -24,6 +24,23 @@
|
|||||||
#include <support/test-driver.h>
|
#include <support/test-driver.h>
|
||||||
#include <support/xunistd.h>
|
#include <support/xunistd.h>
|
||||||
|
|
||||||
|
/* If CONTENTS is not NULL, write it to the file at DIRECTORY/RELPATH,
|
||||||
|
and store the name in *ABSPATH. If CONTENTS is NULL, store NULL in
|
||||||
|
*ABSPATH. */
|
||||||
|
static void
|
||||||
|
write_file (const char *directory, const char *relpath, const char *contents,
|
||||||
|
char **abspath)
|
||||||
|
{
|
||||||
|
if (contents != NULL)
|
||||||
|
{
|
||||||
|
*abspath = xasprintf ("%s/%s", directory, relpath);
|
||||||
|
add_temp_file (*abspath);
|
||||||
|
support_write_file_string (*abspath, contents);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*abspath = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
struct support_chroot *
|
struct support_chroot *
|
||||||
support_chroot_create (struct support_chroot_configuration conf)
|
support_chroot_create (struct support_chroot_configuration conf)
|
||||||
{
|
{
|
||||||
@ -39,15 +56,10 @@ support_chroot_create (struct support_chroot_configuration conf)
|
|||||||
xmkdir (path_etc, 0777);
|
xmkdir (path_etc, 0777);
|
||||||
add_temp_file (path_etc);
|
add_temp_file (path_etc);
|
||||||
|
|
||||||
if (conf.resolv_conf != NULL)
|
write_file (path_etc, "resolv.conf", conf.resolv_conf,
|
||||||
{
|
&chroot->path_resolv_conf);
|
||||||
/* Create an empty resolv.conf file. */
|
write_file (path_etc, "hosts", conf.hosts, &chroot->path_hosts);
|
||||||
chroot->path_resolv_conf = xasprintf ("%s/resolv.conf", path_etc);
|
write_file (path_etc, "host.conf", conf.host_conf, &chroot->path_host_conf);
|
||||||
add_temp_file (chroot->path_resolv_conf);
|
|
||||||
support_write_file_string (chroot->path_resolv_conf, conf.resolv_conf);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
chroot->path_resolv_conf = NULL;
|
|
||||||
|
|
||||||
free (path_etc);
|
free (path_etc);
|
||||||
|
|
||||||
@ -67,5 +79,7 @@ support_chroot_free (struct support_chroot *chroot)
|
|||||||
{
|
{
|
||||||
free (chroot->path_chroot);
|
free (chroot->path_chroot);
|
||||||
free (chroot->path_resolv_conf);
|
free (chroot->path_resolv_conf);
|
||||||
|
free (chroot->path_hosts);
|
||||||
|
free (chroot->path_host_conf);
|
||||||
free (chroot);
|
free (chroot);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user