2016-12-31 17:51:07 +00:00
|
|
|
/* Entering namespaces for test case isolation.
|
2022-01-01 18:54:23 +00:00
|
|
|
Copyright (C) 2016-2022 Free Software Foundation, Inc.
|
2016-12-31 17:51:07 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2016-12-31 17:51:07 +00:00
|
|
|
|
|
|
|
#ifndef SUPPORT_NAMESPACE_H
|
|
|
|
#define SUPPORT_NAMESPACE_H
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
|
|
|
|
/* Attempts to become root (or acquire root-like privileges), possibly
|
|
|
|
with the help of user namespaces. Return true if (restricted) root
|
|
|
|
privileges could be attained in some way. Print diagnostics to
|
|
|
|
standard output.
|
|
|
|
|
|
|
|
Note that this function generally has to be called before a process
|
|
|
|
becomes multi-threaded, otherwise it may fail with insufficient
|
|
|
|
privileges on systems which would support this operation for
|
|
|
|
single-threaded processes. */
|
|
|
|
bool support_become_root (void);
|
|
|
|
|
2017-06-02 13:50:36 +00:00
|
|
|
/* Return true if this process can perform a chroot operation. In
|
|
|
|
general, this is only possible if support_become_root has been
|
|
|
|
called. Note that the actual test is performed in a subprocess,
|
|
|
|
after fork, so that the file system root of the original process is
|
|
|
|
not changed. */
|
|
|
|
bool support_can_chroot (void);
|
|
|
|
|
2016-12-31 17:51:07 +00:00
|
|
|
/* Enter a network namespace (and a UTS namespace if possible) and
|
|
|
|
configure the loopback interface. Return true if a network
|
|
|
|
namespace could be created. Print diagnostics to standard output.
|
|
|
|
If a network namespace could be created, but networking in it could
|
|
|
|
not be configured, terminate the process. It is recommended to
|
|
|
|
call support_become_root before this function so that the process
|
|
|
|
has sufficient privileges. */
|
|
|
|
bool support_enter_network_namespace (void);
|
|
|
|
|
2017-11-18 13:30:20 +00:00
|
|
|
/* Enter a mount namespace and mark / as private (not shared). If
|
|
|
|
this function returns true, mount operations in this process will
|
|
|
|
not affect the host system afterwards. */
|
|
|
|
bool support_enter_mount_namespace (void);
|
|
|
|
|
2016-12-31 17:51:07 +00:00
|
|
|
/* Return true if support_enter_network_namespace managed to enter a
|
|
|
|
UTS namespace. */
|
|
|
|
bool support_in_uts_namespace (void);
|
|
|
|
|
2017-06-02 13:50:36 +00:00
|
|
|
/* Invoke CALLBACK (CLOSURE) in a subprocess created using fork.
|
|
|
|
Terminate the calling process if the subprocess exits with a
|
|
|
|
non-zero exit status. */
|
|
|
|
void support_isolate_in_subprocess (void (*callback) (void *), void *closure);
|
|
|
|
|
2017-07-05 13:38:42 +00:00
|
|
|
/* Describe the setup of a chroot environment, for
|
|
|
|
support_chroot_create below. */
|
|
|
|
struct support_chroot_configuration
|
|
|
|
{
|
|
|
|
/* File contents. The files are not created if the field is
|
|
|
|
NULL. */
|
2017-09-01 06:58:07 +00:00
|
|
|
const char *resolv_conf; /* /etc/resolv.conf. */
|
|
|
|
const char *hosts; /* /etc/hosts. */
|
|
|
|
const char *host_conf; /* /etc/host.conf. */
|
2019-01-31 17:49:58 +00:00
|
|
|
const char *aliases; /* /etc/aliases. */
|
2017-07-05 13:38:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The result of the creation of a chroot. */
|
|
|
|
struct support_chroot
|
|
|
|
{
|
|
|
|
/* Path information. All these paths are relative to the parent
|
|
|
|
chroot. */
|
|
|
|
|
|
|
|
/* Path to the chroot directory. */
|
|
|
|
char *path_chroot;
|
|
|
|
|
2017-09-01 06:58:07 +00:00
|
|
|
/* Paths to files in the chroot. These are absolute and outside of
|
|
|
|
the chroot. */
|
|
|
|
char *path_resolv_conf; /* /etc/resolv.conf. */
|
|
|
|
char *path_hosts; /* /etc/hosts. */
|
|
|
|
char *path_host_conf; /* /etc/host.conf. */
|
2019-01-31 17:49:58 +00:00
|
|
|
char *path_aliases; /* /etc/aliases. */
|
2017-07-05 13:38:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Create a chroot environment. The returned data should be freed
|
|
|
|
using support_chroot_free below. The files will be deleted when
|
|
|
|
the process exits. This function does not enter the chroot. */
|
|
|
|
struct support_chroot *support_chroot_create
|
|
|
|
(struct support_chroot_configuration);
|
|
|
|
|
|
|
|
/* Deallocate the chroot information created by
|
|
|
|
support_chroot_create. */
|
|
|
|
void support_chroot_free (struct support_chroot *);
|
|
|
|
|
2016-12-31 17:51:07 +00:00
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif
|