|
|
d8307d |
This patch backports the support/ directory as of the upstream commit
|
|
|
d8307d |
below. (It does not include the required Makefile changes to enable
|
|
|
d8307d |
test-in-container builds.)
|
|
|
d8307d |
|
|
|
d8307d |
commit 00c86a37d1b63044e3169d1f2ebec23447c73f79
|
|
|
d8307d |
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
|
d8307d |
Date: Wed Nov 7 11:09:02 2018 -0200
|
|
|
d8307d |
|
|
|
d8307d |
support: Fix printf format for TEST_COMPARE_STRING
|
|
|
d8307d |
|
|
|
d8307d |
Fix the following on 32 bits targets:
|
|
|
d8307d |
|
|
|
d8307d |
support_test_compare_string.c: In function ‘support_test_compare_string’:
|
|
|
d8307d |
support_test_compare_string.c:80:37: error: format ‘%lu’ expects argument of
|
|
|
d8307d |
type ‘long unsigned int’, but argument 2 has type ‘size_t’ {aka ‘unsigned int’}
|
|
|
d8307d |
[-Werror=format=]
|
|
|
d8307d |
printf (" string length: %lu bytes\n", left_length);
|
|
|
d8307d |
~~^ ~~~~~~~~~~~
|
|
|
d8307d |
%u
|
|
|
d8307d |
Checked on arm-linux-gnueabihf.
|
|
|
d8307d |
|
|
|
d8307d |
* support/support_test_compare_string.c
|
|
|
d8307d |
(support_test_compare_string): Fix printf format.
|
|
|
d8307d |
|
|
|
d8307d |
diff --git a/support/Makefile b/support/Makefile
|
|
|
d8307d |
index 652d2cdf6945b2eb..2b663fbbfa334ea2 100644
|
|
|
d8307d |
--- a/support/Makefile
|
|
|
d8307d |
+++ b/support/Makefile
|
|
|
d8307d |
@@ -25,6 +25,7 @@ extra-libs-others = $(extra-libs)
|
|
|
d8307d |
extra-libs-noinstall := $(extra-libs)
|
|
|
d8307d |
|
|
|
d8307d |
libsupport-routines = \
|
|
|
d8307d |
+ blob_repeat \
|
|
|
d8307d |
check \
|
|
|
d8307d |
check_addrinfo \
|
|
|
d8307d |
check_dns_packet \
|
|
|
d8307d |
@@ -43,6 +44,8 @@ libsupport-routines = \
|
|
|
d8307d |
support_capture_subprocess \
|
|
|
d8307d |
support_capture_subprocess_check \
|
|
|
d8307d |
support_chroot \
|
|
|
d8307d |
+ support_copy_file_range \
|
|
|
d8307d |
+ support_descriptor_supports_holes \
|
|
|
d8307d |
support_enter_mount_namespace \
|
|
|
d8307d |
support_enter_network_namespace \
|
|
|
d8307d |
support_format_address_family \
|
|
|
d8307d |
@@ -53,12 +56,14 @@ libsupport-routines = \
|
|
|
d8307d |
support_format_netent \
|
|
|
d8307d |
support_isolate_in_subprocess \
|
|
|
d8307d |
support_openpty \
|
|
|
d8307d |
+ support_paths \
|
|
|
d8307d |
support_quote_blob \
|
|
|
d8307d |
support_record_failure \
|
|
|
d8307d |
support_run_diff \
|
|
|
d8307d |
support_shared_allocate \
|
|
|
d8307d |
support_test_compare_blob \
|
|
|
d8307d |
support_test_compare_failure \
|
|
|
d8307d |
+ support_test_compare_string \
|
|
|
d8307d |
support_write_file_string \
|
|
|
d8307d |
support_test_main \
|
|
|
d8307d |
support_test_verify_impl \
|
|
|
d8307d |
@@ -72,6 +77,7 @@ libsupport-routines = \
|
|
|
d8307d |
xchroot \
|
|
|
d8307d |
xclose \
|
|
|
d8307d |
xconnect \
|
|
|
d8307d |
+ xcopy_file_range \
|
|
|
d8307d |
xdlfcn \
|
|
|
d8307d |
xdup2 \
|
|
|
d8307d |
xfclose \
|
|
|
d8307d |
@@ -84,6 +90,7 @@ libsupport-routines = \
|
|
|
d8307d |
xmalloc \
|
|
|
d8307d |
xmemstream \
|
|
|
d8307d |
xmkdir \
|
|
|
d8307d |
+ xmkdirp \
|
|
|
d8307d |
xmmap \
|
|
|
d8307d |
xmprotect \
|
|
|
d8307d |
xmunmap \
|
|
|
d8307d |
@@ -139,6 +146,7 @@ libsupport-routines = \
|
|
|
d8307d |
xsocket \
|
|
|
d8307d |
xstrdup \
|
|
|
d8307d |
xstrndup \
|
|
|
d8307d |
+ xsymlink \
|
|
|
d8307d |
xsysconf \
|
|
|
d8307d |
xunlink \
|
|
|
d8307d |
xwaitpid \
|
|
|
d8307d |
@@ -151,15 +159,47 @@ ifeq ($(build-shared),yes)
|
|
|
d8307d |
libsupport-inhibit-o += .o
|
|
|
d8307d |
endif
|
|
|
d8307d |
|
|
|
d8307d |
+CFLAGS-support_paths.c = \
|
|
|
d8307d |
+ -DSRCDIR_PATH=\"`cd .. ; pwd`\" \
|
|
|
d8307d |
+ -DOBJDIR_PATH=\"`cd $(objpfx)/..; pwd`\" \
|
|
|
d8307d |
+ -DOBJDIR_ELF_LDSO_PATH=\"`cd $(objpfx)/..; pwd`/elf/$(rtld-installed-name)\" \
|
|
|
d8307d |
+ -DINSTDIR_PATH=\"$(prefix)\" \
|
|
|
d8307d |
+ -DLIBDIR_PATH=\"$(libdir)\"
|
|
|
d8307d |
+
|
|
|
d8307d |
+ifeq (,$(CXX))
|
|
|
d8307d |
+LINKS_DSO_PROGRAM = links-dso-program-c
|
|
|
d8307d |
+else
|
|
|
d8307d |
+LINKS_DSO_PROGRAM = links-dso-program
|
|
|
d8307d |
+LDLIBS-links-dso-program = -lstdc++ -lgcc -lgcc_s $(libunwind)
|
|
|
d8307d |
+endif
|
|
|
d8307d |
+
|
|
|
d8307d |
+LDLIBS-test-container = $(libsupport)
|
|
|
d8307d |
+
|
|
|
d8307d |
+others += test-container
|
|
|
d8307d |
+others-noinstall += test-container
|
|
|
d8307d |
+
|
|
|
d8307d |
+others += shell-container echo-container true-container
|
|
|
d8307d |
+others-noinstall += shell-container echo-container true-container
|
|
|
d8307d |
+
|
|
|
d8307d |
+others += $(LINKS_DSO_PROGRAM)
|
|
|
d8307d |
+others-noinstall += $(LINKS_DSO_PROGRAM)
|
|
|
d8307d |
+
|
|
|
d8307d |
+$(objpfx)test-container : $(libsupport)
|
|
|
d8307d |
+$(objpfx)shell-container : $(libsupport)
|
|
|
d8307d |
+$(objpfx)echo-container : $(libsupport)
|
|
|
d8307d |
+$(objpfx)true-container : $(libsupport)
|
|
|
d8307d |
+
|
|
|
d8307d |
tests = \
|
|
|
d8307d |
README-testing \
|
|
|
d8307d |
tst-support-namespace \
|
|
|
d8307d |
+ tst-support_blob_repeat \
|
|
|
d8307d |
tst-support_capture_subprocess \
|
|
|
d8307d |
tst-support_format_dns_packet \
|
|
|
d8307d |
tst-support_quote_blob \
|
|
|
d8307d |
tst-support_record_failure \
|
|
|
d8307d |
tst-test_compare \
|
|
|
d8307d |
tst-test_compare_blob \
|
|
|
d8307d |
+ tst-test_compare_string \
|
|
|
d8307d |
tst-xreadlink \
|
|
|
d8307d |
|
|
|
d8307d |
ifeq ($(run-built-tests),yes)
|
|
|
d8307d |
diff --git a/support/blob_repeat.c b/support/blob_repeat.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..16c1e448b990e386
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/blob_repeat.c
|
|
|
d8307d |
@@ -0,0 +1,282 @@
|
|
|
d8307d |
+/* Repeating a memory blob, with alias mapping optimization.
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <errno.h>
|
|
|
d8307d |
+#include <fcntl.h>
|
|
|
d8307d |
+#include <stdbool.h>
|
|
|
d8307d |
+#include <stdlib.h>
|
|
|
d8307d |
+#include <string.h>
|
|
|
d8307d |
+#include <support/blob_repeat.h>
|
|
|
d8307d |
+#include <support/check.h>
|
|
|
d8307d |
+#include <support/test-driver.h>
|
|
|
d8307d |
+#include <support/support.h>
|
|
|
d8307d |
+#include <support/xunistd.h>
|
|
|
d8307d |
+#include <sys/mman.h>
|
|
|
d8307d |
+#include <unistd.h>
|
|
|
d8307d |
+#include <wchar.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Small allocations should use malloc directly instead of the mmap
|
|
|
d8307d |
+ optimization because mappings carry a lot of overhead. */
|
|
|
d8307d |
+static const size_t maximum_small_size = 4 * 1024 * 1024;
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Internal helper for fill. */
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+fill0 (char *target, const char *element, size_t element_size,
|
|
|
d8307d |
+ size_t count)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ while (count > 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ memcpy (target, element, element_size);
|
|
|
d8307d |
+ target += element_size;
|
|
|
d8307d |
+ --count;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Fill the buffer at TARGET with COUNT copies of the ELEMENT_SIZE
|
|
|
d8307d |
+ bytes starting at ELEMENT. */
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+fill (char *target, const char *element, size_t element_size,
|
|
|
d8307d |
+ size_t count)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ if (element_size == 0 || count == 0)
|
|
|
d8307d |
+ return;
|
|
|
d8307d |
+ else if (element_size == 1)
|
|
|
d8307d |
+ memset (target, element[0], count);
|
|
|
d8307d |
+ else if (element_size == sizeof (wchar_t))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ wchar_t wc;
|
|
|
d8307d |
+ memcpy (&wc, element, sizeof (wc));
|
|
|
d8307d |
+ wmemset ((wchar_t *) target, wc, count);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ else if (element_size < 1024 && count > 4096)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* Use larger copies for really small element sizes. */
|
|
|
d8307d |
+ char buffer[8192];
|
|
|
d8307d |
+ size_t buffer_count = sizeof (buffer) / element_size;
|
|
|
d8307d |
+ fill0 (buffer, element, element_size, buffer_count);
|
|
|
d8307d |
+ while (count > 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ size_t copy_count = buffer_count;
|
|
|
d8307d |
+ if (copy_count > count)
|
|
|
d8307d |
+ copy_count = count;
|
|
|
d8307d |
+ size_t copy_bytes = copy_count * element_size;
|
|
|
d8307d |
+ memcpy (target, buffer, copy_bytes);
|
|
|
d8307d |
+ target += copy_bytes;
|
|
|
d8307d |
+ count -= copy_count;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ fill0 (target, element, element_size, count);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Use malloc instead of mmap for small allocations and unusual size
|
|
|
d8307d |
+ combinations. */
|
|
|
d8307d |
+static struct support_blob_repeat
|
|
|
d8307d |
+allocate_malloc (size_t total_size, const void *element, size_t element_size,
|
|
|
d8307d |
+ size_t count)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ void *buffer = malloc (total_size);
|
|
|
d8307d |
+ if (buffer == NULL)
|
|
|
d8307d |
+ return (struct support_blob_repeat) { 0 };
|
|
|
d8307d |
+ fill (buffer, element, element_size, count);
|
|
|
d8307d |
+ return (struct support_blob_repeat)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ .start = buffer,
|
|
|
d8307d |
+ .size = total_size,
|
|
|
d8307d |
+ .use_malloc = true
|
|
|
d8307d |
+ };
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Return the least common multiple of PAGE_SIZE and ELEMENT_SIZE,
|
|
|
d8307d |
+ avoiding overflow. This assumes that PAGE_SIZE is a power of
|
|
|
d8307d |
+ two. */
|
|
|
d8307d |
+static size_t
|
|
|
d8307d |
+minimum_stride_size (size_t page_size, size_t element_size)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ TEST_VERIFY_EXIT (page_size > 0);
|
|
|
d8307d |
+ TEST_VERIFY_EXIT (element_size > 0);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Compute the number of trailing zeros common to both sizes. */
|
|
|
d8307d |
+ unsigned int common_zeros = __builtin_ctzll (page_size | element_size);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* In the product, this power of two appears twice, but in the least
|
|
|
d8307d |
+ common multiple, it appears only once. Therefore, shift one
|
|
|
d8307d |
+ factor. */
|
|
|
d8307d |
+ size_t multiple;
|
|
|
d8307d |
+ if (__builtin_mul_overflow (page_size >> common_zeros, element_size,
|
|
|
d8307d |
+ &multiple))
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+ return multiple;
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Allocations larger than maximum_small_size potentially use mmap
|
|
|
d8307d |
+ with alias mappings. */
|
|
|
d8307d |
+static struct support_blob_repeat
|
|
|
d8307d |
+allocate_big (size_t total_size, const void *element, size_t element_size,
|
|
|
d8307d |
+ size_t count)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ unsigned long page_size = xsysconf (_SC_PAGESIZE);
|
|
|
d8307d |
+ size_t stride_size = minimum_stride_size (page_size, element_size);
|
|
|
d8307d |
+ if (stride_size == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ errno = EOVERFLOW;
|
|
|
d8307d |
+ return (struct support_blob_repeat) { 0 };
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Ensure that the stride size is at least maximum_small_size. This
|
|
|
d8307d |
+ is necessary to reduce the number of distinct mappings. */
|
|
|
d8307d |
+ if (stride_size < maximum_small_size)
|
|
|
d8307d |
+ stride_size
|
|
|
d8307d |
+ = ((maximum_small_size + stride_size - 1) / stride_size) * stride_size;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (stride_size > total_size)
|
|
|
d8307d |
+ /* The mmap optimization would not save anything. */
|
|
|
d8307d |
+ return allocate_malloc (total_size, element, element_size, count);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Reserve the memory region. If we cannot create the mapping,
|
|
|
d8307d |
+ there is no reason to set up the backing file. */
|
|
|
d8307d |
+ void *target = mmap (NULL, total_size, PROT_NONE,
|
|
|
d8307d |
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
|
|
|
d8307d |
+ if (target == MAP_FAILED)
|
|
|
d8307d |
+ return (struct support_blob_repeat) { 0 };
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Create the backing file for the repeated mapping. Call mkstemp
|
|
|
d8307d |
+ directly to remove the resources backing the temporary file
|
|
|
d8307d |
+ immediately, once support_blob_repeat_free is called. Using
|
|
|
d8307d |
+ create_temp_file would result in a warning during post-test
|
|
|
d8307d |
+ cleanup. */
|
|
|
d8307d |
+ int fd;
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ char *temppath = xasprintf ("%s/support_blob_repeat-XXXXXX", test_dir);
|
|
|
d8307d |
+ fd = mkstemp (temppath);
|
|
|
d8307d |
+ if (fd < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("mkstemp (\"%s\"): %m", temppath);
|
|
|
d8307d |
+ xunlink (temppath);
|
|
|
d8307d |
+ free (temppath);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Make sure that there is backing storage, so that the fill
|
|
|
d8307d |
+ operation will not fault. */
|
|
|
d8307d |
+ if (posix_fallocate (fd, 0, stride_size) != 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("posix_fallocate (%zu): %m", stride_size);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* The stride size must still be a multiple of the page size and
|
|
|
d8307d |
+ element size. */
|
|
|
d8307d |
+ TEST_VERIFY_EXIT ((stride_size % page_size) == 0);
|
|
|
d8307d |
+ TEST_VERIFY_EXIT ((stride_size % element_size) == 0);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Fill the backing store. */
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ void *ptr = mmap (target, stride_size, PROT_READ | PROT_WRITE,
|
|
|
d8307d |
+ MAP_FIXED | MAP_FILE | MAP_SHARED, fd, 0);
|
|
|
d8307d |
+ if (ptr == MAP_FAILED)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ int saved_errno = errno;
|
|
|
d8307d |
+ xmunmap (target, total_size);
|
|
|
d8307d |
+ xclose (fd);
|
|
|
d8307d |
+ errno = saved_errno;
|
|
|
d8307d |
+ return (struct support_blob_repeat) { 0 };
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ if (ptr != target)
|
|
|
d8307d |
+ FAIL_EXIT1 ("mapping of %zu bytes moved from %p to %p",
|
|
|
d8307d |
+ stride_size, target, ptr);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Write the repeating data. */
|
|
|
d8307d |
+ fill (target, element, element_size, stride_size / element_size);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Return to a PROT_NONE mapping, just to be on the safe side. */
|
|
|
d8307d |
+ ptr = mmap (target, stride_size, PROT_NONE,
|
|
|
d8307d |
+ MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
|
|
|
d8307d |
+ if (ptr == MAP_FAILED)
|
|
|
d8307d |
+ FAIL_EXIT1 ("Failed to reinstate PROT_NONE mapping: %m");
|
|
|
d8307d |
+ if (ptr != target)
|
|
|
d8307d |
+ FAIL_EXIT1 ("PROT_NONE mapping of %zu bytes moved from %p to %p",
|
|
|
d8307d |
+ stride_size, target, ptr);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Create the alias mappings. */
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ size_t remaining_size = total_size;
|
|
|
d8307d |
+ char *current = target;
|
|
|
d8307d |
+ int flags = MAP_FIXED | MAP_FILE | MAP_PRIVATE;
|
|
|
d8307d |
+#ifdef MAP_NORESERVE
|
|
|
d8307d |
+ flags |= MAP_NORESERVE;
|
|
|
d8307d |
+#endif
|
|
|
d8307d |
+ while (remaining_size > 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ size_t to_map = stride_size;
|
|
|
d8307d |
+ if (to_map > remaining_size)
|
|
|
d8307d |
+ to_map = remaining_size;
|
|
|
d8307d |
+ void *ptr = mmap (current, to_map, PROT_READ | PROT_WRITE,
|
|
|
d8307d |
+ flags, fd, 0);
|
|
|
d8307d |
+ if (ptr == MAP_FAILED)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ int saved_errno = errno;
|
|
|
d8307d |
+ xmunmap (target, total_size);
|
|
|
d8307d |
+ xclose (fd);
|
|
|
d8307d |
+ errno = saved_errno;
|
|
|
d8307d |
+ return (struct support_blob_repeat) { 0 };
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ if (ptr != current)
|
|
|
d8307d |
+ FAIL_EXIT1 ("MAP_PRIVATE mapping of %zu bytes moved from %p to %p",
|
|
|
d8307d |
+ to_map, target, ptr);
|
|
|
d8307d |
+ remaining_size -= to_map;
|
|
|
d8307d |
+ current += to_map;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ xclose (fd);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ return (struct support_blob_repeat)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ .start = target,
|
|
|
d8307d |
+ .size = total_size,
|
|
|
d8307d |
+ .use_malloc = false
|
|
|
d8307d |
+ };
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+struct support_blob_repeat
|
|
|
d8307d |
+support_blob_repeat_allocate (const void *element, size_t element_size,
|
|
|
d8307d |
+ size_t count)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ size_t total_size;
|
|
|
d8307d |
+ if (__builtin_mul_overflow (element_size, count, &total_size))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ errno = EOVERFLOW;
|
|
|
d8307d |
+ return (struct support_blob_repeat) { 0 };
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ if (total_size <= maximum_small_size)
|
|
|
d8307d |
+ return allocate_malloc (total_size, element, element_size, count);
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ return allocate_big (total_size, element, element_size, count);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+void
|
|
|
d8307d |
+support_blob_repeat_free (struct support_blob_repeat *blob)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ if (blob->size > 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ int saved_errno = errno;
|
|
|
d8307d |
+ if (blob->use_malloc)
|
|
|
d8307d |
+ free (blob->start);
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ xmunmap (blob->start, blob->size);
|
|
|
d8307d |
+ errno = saved_errno;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ *blob = (struct support_blob_repeat) { 0 };
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/blob_repeat.h b/support/blob_repeat.h
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..8e9d7ff5f1e01f66
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/blob_repeat.h
|
|
|
d8307d |
@@ -0,0 +1,44 @@
|
|
|
d8307d |
+/* Repeating a memory blob, with alias mapping optimization.
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#ifndef SUPPORT_BLOB_REPEAT_H
|
|
|
d8307d |
+#define SUPPORT_BLOB_REPEAT_H
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <stdbool.h>
|
|
|
d8307d |
+#include <stddef.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+struct support_blob_repeat
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ void *start;
|
|
|
d8307d |
+ size_t size;
|
|
|
d8307d |
+ bool use_malloc;
|
|
|
d8307d |
+};
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Return an allocation of COUNT elements, each of ELEMENT_SIZE bytes,
|
|
|
d8307d |
+ initialized with the bytes starting at ELEMENT. The memory is
|
|
|
d8307d |
+ writable (and thus counts towards the commit charge). In case of
|
|
|
d8307d |
+ on error, all members of the return struct are zero-initialized,
|
|
|
d8307d |
+ and errno is set accordingly. */
|
|
|
d8307d |
+struct support_blob_repeat support_blob_repeat_allocate (const void *element,
|
|
|
d8307d |
+ size_t element_size,
|
|
|
d8307d |
+ size_t count);
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Deallocate the blob created by support_blob_repeat_allocate. */
|
|
|
d8307d |
+void support_blob_repeat_free (struct support_blob_repeat *);
|
|
|
d8307d |
+
|
|
|
d8307d |
+#endif /* SUPPORT_BLOB_REPEAT_H */
|
|
|
d8307d |
diff --git a/support/check.h b/support/check.h
|
|
|
d8307d |
index b3a4645e9255e90d..e6765289f2492501 100644
|
|
|
d8307d |
--- a/support/check.h
|
|
|
d8307d |
+++ b/support/check.h
|
|
|
d8307d |
@@ -163,6 +163,19 @@ void support_test_compare_blob (const void *left,
|
|
|
d8307d |
const char *right_exp,
|
|
|
d8307d |
const char *right_len_exp);
|
|
|
d8307d |
|
|
|
d8307d |
+/* Compare the strings LEFT and RIGHT and report a test failure if
|
|
|
d8307d |
+ they are different. Also report failure if one of the arguments is
|
|
|
d8307d |
+ a null pointer and the other is not. The strings should be
|
|
|
d8307d |
+ reasonably short because on mismatch, both are printed. */
|
|
|
d8307d |
+#define TEST_COMPARE_STRING(left, right) \
|
|
|
d8307d |
+ (support_test_compare_string (left, right, __FILE__, __LINE__, \
|
|
|
d8307d |
+ #left, #right))
|
|
|
d8307d |
+
|
|
|
d8307d |
+void support_test_compare_string (const char *left, const char *right,
|
|
|
d8307d |
+ const char *file, int line,
|
|
|
d8307d |
+ const char *left_expr,
|
|
|
d8307d |
+ const char *right_expr);
|
|
|
d8307d |
+
|
|
|
d8307d |
/* Internal function called by the test driver. */
|
|
|
d8307d |
int support_report_failure (int status)
|
|
|
d8307d |
__attribute__ ((weak, warn_unused_result));
|
|
|
d8307d |
diff --git a/support/echo-container.c b/support/echo-container.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..e4d48df95722af2e
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/echo-container.c
|
|
|
d8307d |
@@ -0,0 +1,34 @@
|
|
|
d8307d |
+/* Minimal /bin/echo for in-container use.
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <stdio.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+int
|
|
|
d8307d |
+main (int argc, const char **argv)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ int i;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ for (i = 1; i < argc; i++)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (i > 1)
|
|
|
d8307d |
+ putchar (' ');
|
|
|
d8307d |
+ fputs (argv[i], stdout);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ putchar ('\n');
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/links-dso-program-c.c b/support/links-dso-program-c.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..d28a28a0d09c743c
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/links-dso-program-c.c
|
|
|
d8307d |
@@ -0,0 +1,9 @@
|
|
|
d8307d |
+#include <stdio.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+int
|
|
|
d8307d |
+main (int argc, char **argv)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ /* Complexity to keep gcc from optimizing this away. */
|
|
|
d8307d |
+ printf ("This is a test %s.\n", argc > 1 ? argv[1] : "null");
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/links-dso-program.cc b/support/links-dso-program.cc
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..dba6976c0609a332
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/links-dso-program.cc
|
|
|
d8307d |
@@ -0,0 +1,11 @@
|
|
|
d8307d |
+#include <iostream>
|
|
|
d8307d |
+
|
|
|
d8307d |
+using namespace std;
|
|
|
d8307d |
+
|
|
|
d8307d |
+int
|
|
|
d8307d |
+main (int argc, char **argv)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ /* Complexity to keep gcc from optimizing this away. */
|
|
|
d8307d |
+ cout << (argc > 1 ? argv[1] : "null");
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/shell-container.c b/support/shell-container.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..9bd90d3f60529079
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/shell-container.c
|
|
|
d8307d |
@@ -0,0 +1,395 @@
|
|
|
d8307d |
+/* Minimal /bin/sh for in-container use.
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#define _FILE_OFFSET_BITS 64
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <stdio.h>
|
|
|
d8307d |
+#include <stdlib.h>
|
|
|
d8307d |
+#include <string.h>
|
|
|
d8307d |
+#include <sched.h>
|
|
|
d8307d |
+#include <sys/syscall.h>
|
|
|
d8307d |
+#include <unistd.h>
|
|
|
d8307d |
+#include <sys/types.h>
|
|
|
d8307d |
+#include <dirent.h>
|
|
|
d8307d |
+#include <string.h>
|
|
|
d8307d |
+#include <sys/stat.h>
|
|
|
d8307d |
+#include <sys/fcntl.h>
|
|
|
d8307d |
+#include <sys/file.h>
|
|
|
d8307d |
+#include <sys/wait.h>
|
|
|
d8307d |
+#include <stdarg.h>
|
|
|
d8307d |
+#include <sys/sysmacros.h>
|
|
|
d8307d |
+#include <ctype.h>
|
|
|
d8307d |
+#include <utime.h>
|
|
|
d8307d |
+#include <errno.h>
|
|
|
d8307d |
+#include <error.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <support/support.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Design considerations
|
|
|
d8307d |
+
|
|
|
d8307d |
+ General rule: optimize for developer time, not run time.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ Specifically:
|
|
|
d8307d |
+
|
|
|
d8307d |
+ * Don't worry about slow algorithms
|
|
|
d8307d |
+ * Don't worry about free'ing memory
|
|
|
d8307d |
+ * Don't implement anything the testsuite doesn't need.
|
|
|
d8307d |
+ * Line and argument counts are limited, see below.
|
|
|
d8307d |
+
|
|
|
d8307d |
+*/
|
|
|
d8307d |
+
|
|
|
d8307d |
+#define MAX_ARG_COUNT 100
|
|
|
d8307d |
+#define MAX_LINE_LENGTH 1000
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Debugging is enabled via --debug, which must be the first argument. */
|
|
|
d8307d |
+static int debug_mode = 0;
|
|
|
d8307d |
+#define dprintf if (debug_mode) fprintf
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Emulate the "/bin/true" command. Arguments are ignored. */
|
|
|
d8307d |
+static int
|
|
|
d8307d |
+true_func (char **argv)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Emulate the "/bin/echo" command. Options are ignored, arguments
|
|
|
d8307d |
+ are printed to stdout. */
|
|
|
d8307d |
+static int
|
|
|
d8307d |
+echo_func (char **argv)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ int i;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ for (i = 0; argv[i]; i++)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (i > 0)
|
|
|
d8307d |
+ putchar (' ');
|
|
|
d8307d |
+ fputs (argv[i], stdout);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ putchar ('\n');
|
|
|
d8307d |
+
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Emulate the "/bin/cp" command. Options are ignored. Only copies
|
|
|
d8307d |
+ one source file to one destination file. Directory destinations
|
|
|
d8307d |
+ are not supported. */
|
|
|
d8307d |
+static int
|
|
|
d8307d |
+copy_func (char **argv)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ char *sname = argv[0];
|
|
|
d8307d |
+ char *dname = argv[1];
|
|
|
d8307d |
+ int sfd, dfd;
|
|
|
d8307d |
+ struct stat st;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ sfd = open (sname, O_RDONLY);
|
|
|
d8307d |
+ if (sfd < 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ fprintf (stderr, "cp: unable to open %s for reading: %s\n",
|
|
|
d8307d |
+ sname, strerror (errno));
|
|
|
d8307d |
+ return 1;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (fstat (sfd, &st) < 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ fprintf (stderr, "cp: unable to fstat %s: %s\n",
|
|
|
d8307d |
+ sname, strerror (errno));
|
|
|
d8307d |
+ return 1;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ dfd = open (dname, O_WRONLY | O_TRUNC | O_CREAT, 0600);
|
|
|
d8307d |
+ if (dfd < 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ fprintf (stderr, "cp: unable to open %s for writing: %s\n",
|
|
|
d8307d |
+ dname, strerror (errno));
|
|
|
d8307d |
+ return 1;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (support_copy_file_range (sfd, 0, dfd, 0, st.st_size, 0) != st.st_size)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ fprintf (stderr, "cp: cannot copy file %s to %s: %s\n",
|
|
|
d8307d |
+ sname, dname, strerror (errno));
|
|
|
d8307d |
+ return 1;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ close (sfd);
|
|
|
d8307d |
+ close (dfd);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ chmod (dname, st.st_mode & 0777);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* This is a list of all the built-in commands we understand. */
|
|
|
d8307d |
+static struct {
|
|
|
d8307d |
+ const char *name;
|
|
|
d8307d |
+ int (*func) (char **argv);
|
|
|
d8307d |
+} builtin_funcs[] = {
|
|
|
d8307d |
+ { "true", true_func },
|
|
|
d8307d |
+ { "echo", echo_func },
|
|
|
d8307d |
+ { "cp", copy_func },
|
|
|
d8307d |
+ { NULL, NULL }
|
|
|
d8307d |
+};
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Run one tokenized command. argv[0] is the command. argv is
|
|
|
d8307d |
+ NULL-terminated. */
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+run_command_array (char **argv)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ int i, j;
|
|
|
d8307d |
+ pid_t pid;
|
|
|
d8307d |
+ int status;
|
|
|
d8307d |
+ int (*builtin_func) (char **args);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (argv[0] == NULL)
|
|
|
d8307d |
+ return;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ builtin_func = NULL;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ int new_stdin = 0;
|
|
|
d8307d |
+ int new_stdout = 1;
|
|
|
d8307d |
+ int new_stderr = 2;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ dprintf (stderr, "run_command_array starting\n");
|
|
|
d8307d |
+ for (i = 0; argv[i]; i++)
|
|
|
d8307d |
+ dprintf (stderr, " argv [%d] `%s'\n", i, argv[i]);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ for (j = i = 0; argv[i]; i++)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (strcmp (argv[i], "<") == 0 && argv[i + 1])
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ new_stdin = open (argv[i + 1], O_WRONLY|O_CREAT|O_TRUNC, 0777);
|
|
|
d8307d |
+ ++i;
|
|
|
d8307d |
+ continue;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ if (strcmp (argv[i], ">") == 0 && argv[i + 1])
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ new_stdout = open (argv[i + 1], O_WRONLY|O_CREAT|O_TRUNC, 0777);
|
|
|
d8307d |
+ ++i;
|
|
|
d8307d |
+ continue;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ if (strcmp (argv[i], ">>") == 0 && argv[i + 1])
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ new_stdout = open (argv[i + 1], O_WRONLY|O_CREAT|O_APPEND, 0777);
|
|
|
d8307d |
+ ++i;
|
|
|
d8307d |
+ continue;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ if (strcmp (argv[i], "2>") == 0 && argv[i + 1])
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ new_stderr = open (argv[i + 1], O_WRONLY|O_CREAT|O_TRUNC, 0777);
|
|
|
d8307d |
+ ++i;
|
|
|
d8307d |
+ continue;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ argv[j++] = argv[i];
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ argv[j] = NULL;
|
|
|
d8307d |
+
|
|
|
d8307d |
+
|
|
|
d8307d |
+ for (i = 0; builtin_funcs[i].name != NULL; i++)
|
|
|
d8307d |
+ if (strcmp (argv[0], builtin_funcs[i].name) == 0)
|
|
|
d8307d |
+ builtin_func = builtin_funcs[i].func;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ dprintf (stderr, "builtin %p argv0 `%s'\n", builtin_func, argv[0]);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ pid = fork ();
|
|
|
d8307d |
+ if (pid < 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ fprintf (stderr, "sh: fork failed\n");
|
|
|
d8307d |
+ exit (1);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (pid == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (new_stdin != 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ dup2 (new_stdin, 0);
|
|
|
d8307d |
+ close (new_stdin);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ if (new_stdout != 1)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ dup2 (new_stdout, 1);
|
|
|
d8307d |
+ close (new_stdout);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ if (new_stderr != 2)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ dup2 (new_stderr, 2);
|
|
|
d8307d |
+ close (new_stdout);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (builtin_func != NULL)
|
|
|
d8307d |
+ exit (builtin_func (argv + 1));
|
|
|
d8307d |
+
|
|
|
d8307d |
+ execvp (argv[0], argv);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ fprintf (stderr, "sh: execing %s failed: %s",
|
|
|
d8307d |
+ argv[0], strerror (errno));
|
|
|
d8307d |
+ exit (1);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ waitpid (pid, &status, 0);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ dprintf (stderr, "exiting run_command_array\n");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (WIFEXITED (status))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ int rv = WEXITSTATUS (status);
|
|
|
d8307d |
+ if (rv)
|
|
|
d8307d |
+ exit (rv);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ exit (1);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Run one command-as-a-string, by tokenizing it. Limited to
|
|
|
d8307d |
+ MAX_ARG_COUNT arguments. Simple substitution is done of $1 to $9
|
|
|
d8307d |
+ (as whole separate tokens) from iargs[]. Quoted strings work if
|
|
|
d8307d |
+ the quotes wrap whole tokens; i.e. "foo bar" but not foo" bar". */
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+run_command_string (const char *cmdline, const char **iargs)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ char *args[MAX_ARG_COUNT+1];
|
|
|
d8307d |
+ int ap = 0;
|
|
|
d8307d |
+ const char *start, *end;
|
|
|
d8307d |
+ int nargs;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ for (nargs = 0; iargs[nargs] != NULL; ++nargs)
|
|
|
d8307d |
+ ;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ dprintf (stderr, "run_command_string starting: '%s'\n", cmdline);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ while (ap < MAX_ARG_COUNT)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* If the argument is quoted, this is the quote character, else NUL. */
|
|
|
d8307d |
+ int in_quote = 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Skip whitespace up to the next token. */
|
|
|
d8307d |
+ while (*cmdline && isspace (*cmdline))
|
|
|
d8307d |
+ cmdline ++;
|
|
|
d8307d |
+ if (*cmdline == 0)
|
|
|
d8307d |
+ break;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ start = cmdline;
|
|
|
d8307d |
+ /* Check for quoted argument. */
|
|
|
d8307d |
+ in_quote = (*cmdline == '\'' || *cmdline == '"') ? *cmdline : 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Skip to end of token; either by whitespace or matching quote. */
|
|
|
d8307d |
+ dprintf (stderr, "in_quote %d\n", in_quote);
|
|
|
d8307d |
+ while (*cmdline
|
|
|
d8307d |
+ && (!isspace (*cmdline) || in_quote))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (*cmdline == in_quote
|
|
|
d8307d |
+ && cmdline != start)
|
|
|
d8307d |
+ in_quote = 0;
|
|
|
d8307d |
+ dprintf (stderr, "[%c]%d ", *cmdline, in_quote);
|
|
|
d8307d |
+ cmdline ++;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ dprintf (stderr, "\n");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Allocate space for this token and store it in args[]. */
|
|
|
d8307d |
+ end = cmdline;
|
|
|
d8307d |
+ dprintf (stderr, "start<%s> end<%s>\n", start, end);
|
|
|
d8307d |
+ args[ap] = (char *) xmalloc (end - start + 1);
|
|
|
d8307d |
+ memcpy (args[ap], start, end - start);
|
|
|
d8307d |
+ args[ap][end - start] = 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Strip off quotes, if found. */
|
|
|
d8307d |
+ dprintf (stderr, "args[%d] = <%s>\n", ap, args[ap]);
|
|
|
d8307d |
+ if (args[ap][0] == '\''
|
|
|
d8307d |
+ && args[ap][strlen (args[ap])-1] == '\'')
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ args[ap][strlen (args[ap])-1] = 0;
|
|
|
d8307d |
+ args[ap] ++;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ else if (args[ap][0] == '"'
|
|
|
d8307d |
+ && args[ap][strlen (args[ap])-1] == '"')
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ args[ap][strlen (args[ap])-1] = 0;
|
|
|
d8307d |
+ args[ap] ++;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Replace positional parameters like $4. */
|
|
|
d8307d |
+ else if (args[ap][0] == '$'
|
|
|
d8307d |
+ && isdigit (args[ap][1])
|
|
|
d8307d |
+ && args[ap][2] == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ int a = args[ap][1] - '1';
|
|
|
d8307d |
+ if (0 <= a && a < nargs)
|
|
|
d8307d |
+ args[ap] = strdup (iargs[a]);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ ap ++;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (*cmdline == 0)
|
|
|
d8307d |
+ break;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Lastly, NULL terminate the array and run it. */
|
|
|
d8307d |
+ args[ap] = NULL;
|
|
|
d8307d |
+ run_command_array (args);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Run a script by reading lines and passing them to the above
|
|
|
d8307d |
+ function. */
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+run_script (const char *filename, const char **args)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ char line[MAX_LINE_LENGTH + 1];
|
|
|
d8307d |
+ dprintf (stderr, "run_script starting: '%s'\n", filename);
|
|
|
d8307d |
+ FILE *f = fopen (filename, "r");
|
|
|
d8307d |
+ if (f == NULL)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ fprintf (stderr, "sh: %s: %s\n", filename, strerror (errno));
|
|
|
d8307d |
+ exit (1);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ while (fgets (line, sizeof (line), f) != NULL)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (line[0] == '#')
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ dprintf (stderr, "comment: %s\n", line);
|
|
|
d8307d |
+ continue;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ run_command_string (line, args);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ fclose (f);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+int
|
|
|
d8307d |
+main (int argc, const char **argv)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ int i;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (strcmp (argv[1], "--debug") == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ debug_mode = 1;
|
|
|
d8307d |
+ --argc;
|
|
|
d8307d |
+ ++argv;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ dprintf (stderr, "container-sh starting:\n");
|
|
|
d8307d |
+ for (i = 0; i < argc; i++)
|
|
|
d8307d |
+ dprintf (stderr, " argv[%d] is `%s'\n", i, argv[i]);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (strcmp (argv[1], "-c") == 0)
|
|
|
d8307d |
+ run_command_string (argv[2], argv+3);
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ run_script (argv[1], argv+2);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ dprintf (stderr, "normal exit 0\n");
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/support.h b/support/support.h
|
|
|
d8307d |
index b61fe0735c9204de..9418cd11ef6e684d 100644
|
|
|
d8307d |
--- a/support/support.h
|
|
|
d8307d |
+++ b/support/support.h
|
|
|
d8307d |
@@ -25,6 +25,10 @@
|
|
|
d8307d |
|
|
|
d8307d |
#include <stddef.h>
|
|
|
d8307d |
#include <sys/cdefs.h>
|
|
|
d8307d |
+/* For mode_t. */
|
|
|
d8307d |
+#include <sys/stat.h>
|
|
|
d8307d |
+/* For ssize_t and off64_t. */
|
|
|
d8307d |
+#include <sys/types.h>
|
|
|
d8307d |
|
|
|
d8307d |
__BEGIN_DECLS
|
|
|
d8307d |
|
|
|
d8307d |
@@ -65,6 +69,12 @@ void support_write_file_string (const char *path, const char *contents);
|
|
|
d8307d |
the result). */
|
|
|
d8307d |
char *support_quote_blob (const void *blob, size_t length);
|
|
|
d8307d |
|
|
|
d8307d |
+/* Returns non-zero if the file descriptor is a regular file on a file
|
|
|
d8307d |
+ system which supports holes (that is, seeking and writing does not
|
|
|
d8307d |
+ allocate storage for the range of zeros). FD must refer to a
|
|
|
d8307d |
+ regular file open for writing, and initially empty. */
|
|
|
d8307d |
+int support_descriptor_supports_holes (int fd);
|
|
|
d8307d |
+
|
|
|
d8307d |
/* Error-checking wrapper functions which terminate the process on
|
|
|
d8307d |
error. */
|
|
|
d8307d |
|
|
|
d8307d |
@@ -76,6 +86,23 @@ char *xasprintf (const char *format, ...)
|
|
|
d8307d |
char *xstrdup (const char *);
|
|
|
d8307d |
char *xstrndup (const char *, size_t);
|
|
|
d8307d |
|
|
|
d8307d |
+/* These point to the TOP of the source/build tree, not your (or
|
|
|
d8307d |
+ support's) subdirectory. */
|
|
|
d8307d |
+extern const char support_srcdir_root[];
|
|
|
d8307d |
+extern const char support_objdir_root[];
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Corresponds to the path to the runtime linker used by the testsuite,
|
|
|
d8307d |
+ e.g. OBJDIR_PATH/elf/ld-linux-x86-64.so.2 */
|
|
|
d8307d |
+extern const char support_objdir_elf_ldso[];
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Corresponds to the --prefix= passed to configure. */
|
|
|
d8307d |
+extern const char support_install_prefix[];
|
|
|
d8307d |
+/* Corresponds to the install's lib/ or lib64/ directory. */
|
|
|
d8307d |
+extern const char support_libdir_prefix[];
|
|
|
d8307d |
+
|
|
|
d8307d |
+extern ssize_t support_copy_file_range (int, off64_t *, int, off64_t *,
|
|
|
d8307d |
+ size_t, unsigned int);
|
|
|
d8307d |
+
|
|
|
d8307d |
__END_DECLS
|
|
|
d8307d |
|
|
|
d8307d |
#endif /* SUPPORT_H */
|
|
|
d8307d |
diff --git a/support/support_copy_file_range.c b/support/support_copy_file_range.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..9a1e39773e0481c9
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/support_copy_file_range.c
|
|
|
d8307d |
@@ -0,0 +1,143 @@
|
|
|
d8307d |
+/* Simplified copy_file_range with cross-device copy.
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <errno.h>
|
|
|
d8307d |
+#include <fcntl.h>
|
|
|
d8307d |
+#include <inttypes.h>
|
|
|
d8307d |
+#include <limits.h>
|
|
|
d8307d |
+#include <sys/stat.h>
|
|
|
d8307d |
+#include <sys/types.h>
|
|
|
d8307d |
+#include <unistd.h>
|
|
|
d8307d |
+#include <support/support.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+ssize_t
|
|
|
d8307d |
+support_copy_file_range (int infd, __off64_t *pinoff,
|
|
|
d8307d |
+ int outfd, __off64_t *poutoff,
|
|
|
d8307d |
+ size_t length, unsigned int flags)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ if (flags != 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ errno = EINVAL;
|
|
|
d8307d |
+ return -1;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ struct stat64 instat;
|
|
|
d8307d |
+ struct stat64 outstat;
|
|
|
d8307d |
+ if (fstat64 (infd, &instat) != 0 || fstat64 (outfd, &outstat) != 0)
|
|
|
d8307d |
+ return -1;
|
|
|
d8307d |
+ if (S_ISDIR (instat.st_mode) || S_ISDIR (outstat.st_mode))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ errno = EISDIR;
|
|
|
d8307d |
+ return -1;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ if (!S_ISREG (instat.st_mode) || !S_ISREG (outstat.st_mode))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* We need a regular input file so that the we can seek
|
|
|
d8307d |
+ backwards in case of a write failure. */
|
|
|
d8307d |
+ errno = EINVAL;
|
|
|
d8307d |
+ return -1;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* The output descriptor must not have O_APPEND set. */
|
|
|
d8307d |
+ if (fcntl (outfd, F_GETFL) & O_APPEND)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ errno = EBADF;
|
|
|
d8307d |
+ return -1;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Avoid an overflow in the result. */
|
|
|
d8307d |
+ if (length > SSIZE_MAX)
|
|
|
d8307d |
+ length = SSIZE_MAX;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Main copying loop. The buffer size is arbitrary and is a
|
|
|
d8307d |
+ trade-off between stack size consumption, cache usage, and
|
|
|
d8307d |
+ amortization of system call overhead. */
|
|
|
d8307d |
+ size_t copied = 0;
|
|
|
d8307d |
+ char buf[8192];
|
|
|
d8307d |
+ while (length > 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ size_t to_read = length;
|
|
|
d8307d |
+ if (to_read > sizeof (buf))
|
|
|
d8307d |
+ to_read = sizeof (buf);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Fill the buffer. */
|
|
|
d8307d |
+ ssize_t read_count;
|
|
|
d8307d |
+ if (pinoff == NULL)
|
|
|
d8307d |
+ read_count = read (infd, buf, to_read);
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ read_count = pread64 (infd, buf, to_read, *pinoff);
|
|
|
d8307d |
+ if (read_count == 0)
|
|
|
d8307d |
+ /* End of file reached prematurely. */
|
|
|
d8307d |
+ return copied;
|
|
|
d8307d |
+ if (read_count < 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (copied > 0)
|
|
|
d8307d |
+ /* Report the number of bytes copied so far. */
|
|
|
d8307d |
+ return copied;
|
|
|
d8307d |
+ return -1;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ if (pinoff != NULL)
|
|
|
d8307d |
+ *pinoff += read_count;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Write the buffer part which was read to the destination. */
|
|
|
d8307d |
+ char *end = buf + read_count;
|
|
|
d8307d |
+ for (char *p = buf; p < end; )
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ ssize_t write_count;
|
|
|
d8307d |
+ if (poutoff == NULL)
|
|
|
d8307d |
+ write_count = write (outfd, p, end - p);
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ write_count = pwrite64 (outfd, p, end - p, *poutoff);
|
|
|
d8307d |
+ if (write_count < 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* Adjust the input read position to match what we have
|
|
|
d8307d |
+ written, so that the caller can pick up after the
|
|
|
d8307d |
+ error. */
|
|
|
d8307d |
+ size_t written = p - buf;
|
|
|
d8307d |
+ /* NB: This needs to be signed so that we can form the
|
|
|
d8307d |
+ negative value below. */
|
|
|
d8307d |
+ ssize_t overread = read_count - written;
|
|
|
d8307d |
+ if (pinoff == NULL)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (overread > 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* We are on an error recovery path, so we
|
|
|
d8307d |
+ cannot deal with failure here. */
|
|
|
d8307d |
+ int save_errno = errno;
|
|
|
d8307d |
+ (void) lseek64 (infd, -overread, SEEK_CUR);
|
|
|
d8307d |
+ errno = save_errno;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ else /* pinoff != NULL */
|
|
|
d8307d |
+ *pinoff -= overread;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (copied + written > 0)
|
|
|
d8307d |
+ /* Report the number of bytes copied so far. */
|
|
|
d8307d |
+ return copied + written;
|
|
|
d8307d |
+ return -1;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ p += write_count;
|
|
|
d8307d |
+ if (poutoff != NULL)
|
|
|
d8307d |
+ *poutoff += write_count;
|
|
|
d8307d |
+ } /* Write loop. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+ copied += read_count;
|
|
|
d8307d |
+ length -= read_count;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ return copied;
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/support_descriptor_supports_holes.c b/support/support_descriptor_supports_holes.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..c7099ca67caf803c
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/support_descriptor_supports_holes.c
|
|
|
d8307d |
@@ -0,0 +1,87 @@
|
|
|
d8307d |
+/* Test for file system hole support.
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <stdbool.h>
|
|
|
d8307d |
+#include <support.h>
|
|
|
d8307d |
+#include <support/check.h>
|
|
|
d8307d |
+#include <sys/stat.h>
|
|
|
d8307d |
+#include <xunistd.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+int
|
|
|
d8307d |
+support_descriptor_supports_holes (int fd)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ enum
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* Write offset for the enlarged file. This value is arbitrary
|
|
|
d8307d |
+ and hopefully large enough to trigger the creation of holes.
|
|
|
d8307d |
+ We cannot use the file system block size as a reference here
|
|
|
d8307d |
+ because it is incorrect for network file systems. */
|
|
|
d8307d |
+ write_offset = 16 * 1024 * 1024,
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Our write may add this number of additional blocks (see
|
|
|
d8307d |
+ block_limit below). */
|
|
|
d8307d |
+ block_headroom = 8,
|
|
|
d8307d |
+ };
|
|
|
d8307d |
+
|
|
|
d8307d |
+ struct stat64 st;
|
|
|
d8307d |
+ xfstat (fd, &st);
|
|
|
d8307d |
+ if (!S_ISREG (st.st_mode))
|
|
|
d8307d |
+ FAIL_EXIT1 ("descriptor %d does not refer to a regular file", fd);
|
|
|
d8307d |
+ if (st.st_size != 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("descriptor %d does not refer to an empty file", fd);
|
|
|
d8307d |
+ if (st.st_blocks > block_headroom)
|
|
|
d8307d |
+ FAIL_EXIT1 ("descriptor %d refers to a pre-allocated file (%lld blocks)",
|
|
|
d8307d |
+ fd, (long long int) st.st_blocks);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Write a single byte at the start of the file to compute the block
|
|
|
d8307d |
+ usage for a single byte. */
|
|
|
d8307d |
+ xlseek (fd, 0, SEEK_SET);
|
|
|
d8307d |
+ char b = '@';
|
|
|
d8307d |
+ xwrite (fd, &b, 1);
|
|
|
d8307d |
+ /* Attempt to bypass delayed allocation. */
|
|
|
d8307d |
+ TEST_COMPARE (fsync (fd), 0);
|
|
|
d8307d |
+ xfstat (fd, &st);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* This limit is arbitrary. The file system needs to store
|
|
|
d8307d |
+ somewhere that data exists at the write offset, and this may
|
|
|
d8307d |
+ moderately increase the number of blocks used by the file, in
|
|
|
d8307d |
+ proportion to the initial block count, but not in proportion to
|
|
|
d8307d |
+ the write offset. */
|
|
|
d8307d |
+ unsigned long long int block_limit = 2 * st.st_blocks + block_headroom;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Write a single byte at 16 megabytes. */
|
|
|
d8307d |
+ xlseek (fd, write_offset, SEEK_SET);
|
|
|
d8307d |
+ xwrite (fd, &b, 1);
|
|
|
d8307d |
+ /* Attempt to bypass delayed allocation. */
|
|
|
d8307d |
+ TEST_COMPARE (fsync (fd), 0);
|
|
|
d8307d |
+ xfstat (fd, &st);
|
|
|
d8307d |
+ bool supports_holes = st.st_blocks <= block_limit;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Also check that extending the file does not fill up holes. */
|
|
|
d8307d |
+ xftruncate (fd, 2 * write_offset);
|
|
|
d8307d |
+ /* Attempt to bypass delayed allocation. */
|
|
|
d8307d |
+ TEST_COMPARE (fsync (fd), 0);
|
|
|
d8307d |
+ xfstat (fd, &st);
|
|
|
d8307d |
+ supports_holes = supports_holes && st.st_blocks <= block_limit;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Return to a zero-length file. */
|
|
|
d8307d |
+ xftruncate (fd, 0);
|
|
|
d8307d |
+ xlseek (fd, 0, SEEK_SET);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ return supports_holes;
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/support_paths.c b/support/support_paths.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..6d0beb102c9b4bed
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/support_paths.c
|
|
|
d8307d |
@@ -0,0 +1,59 @@
|
|
|
d8307d |
+/* Various paths that might be needed.
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <support/support.h>
|
|
|
d8307d |
+#include <support/check.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* The idea here is to make various makefile-level paths available to
|
|
|
d8307d |
+ support programs, as canonicalized absolute paths. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* These point to the TOP of the source/build tree, not your (or
|
|
|
d8307d |
+ support's) subdirectory. */
|
|
|
d8307d |
+#ifdef SRCDIR_PATH
|
|
|
d8307d |
+const char support_srcdir_root[] = SRCDIR_PATH;
|
|
|
d8307d |
+#else
|
|
|
d8307d |
+# error please -DSRCDIR_PATH=something in the Makefile
|
|
|
d8307d |
+#endif
|
|
|
d8307d |
+
|
|
|
d8307d |
+#ifdef OBJDIR_PATH
|
|
|
d8307d |
+const char support_objdir_root[] = OBJDIR_PATH;
|
|
|
d8307d |
+#else
|
|
|
d8307d |
+# error please -DOBJDIR_PATH=something in the Makefile
|
|
|
d8307d |
+#endif
|
|
|
d8307d |
+
|
|
|
d8307d |
+#ifdef OBJDIR_ELF_LDSO_PATH
|
|
|
d8307d |
+/* Corresponds to the path to the runtime linker used by the testsuite,
|
|
|
d8307d |
+ e.g. OBJDIR_PATH/elf/ld-linux-x86-64.so.2 */
|
|
|
d8307d |
+const char support_objdir_elf_ldso[] = OBJDIR_ELF_LDSO_PATH;
|
|
|
d8307d |
+#else
|
|
|
d8307d |
+# error please -DOBJDIR_ELF_LDSO_PATH=something in the Makefile
|
|
|
d8307d |
+#endif
|
|
|
d8307d |
+
|
|
|
d8307d |
+#ifdef INSTDIR_PATH
|
|
|
d8307d |
+/* Corresponds to the --prefix= passed to configure. */
|
|
|
d8307d |
+const char support_install_prefix[] = INSTDIR_PATH;
|
|
|
d8307d |
+#else
|
|
|
d8307d |
+# error please -DINSTDIR_PATH=something in the Makefile
|
|
|
d8307d |
+#endif
|
|
|
d8307d |
+
|
|
|
d8307d |
+#ifdef LIBDIR_PATH
|
|
|
d8307d |
+/* Corresponds to the install's lib/ or lib64/ directory. */
|
|
|
d8307d |
+const char support_libdir_prefix[] = LIBDIR_PATH;
|
|
|
d8307d |
+#else
|
|
|
d8307d |
+# error please -DLIBDIR_PATH=something in the Makefile
|
|
|
d8307d |
+#endif
|
|
|
d8307d |
diff --git a/support/support_test_compare_string.c b/support/support_test_compare_string.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..a76ba8eda7782d9d
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/support_test_compare_string.c
|
|
|
d8307d |
@@ -0,0 +1,91 @@
|
|
|
d8307d |
+/* Check two strings for equality.
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <stdio.h>
|
|
|
d8307d |
+#include <stdlib.h>
|
|
|
d8307d |
+#include <string.h>
|
|
|
d8307d |
+#include <support/check.h>
|
|
|
d8307d |
+#include <support/support.h>
|
|
|
d8307d |
+#include <support/xmemstream.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+report_length (const char *what, const char *str, size_t length)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ if (str == NULL)
|
|
|
d8307d |
+ printf (" %s string: NULL\n", what);
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ printf (" %s string: %zu bytes\n", what, length);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+report_string (const char *what, const unsigned char *blob,
|
|
|
d8307d |
+ size_t length, const char *expr)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ if (length > 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ printf (" %s (evaluated from %s):\n", what, expr);
|
|
|
d8307d |
+ char *quoted = support_quote_blob (blob, length);
|
|
|
d8307d |
+ printf (" \"%s\"\n", quoted);
|
|
|
d8307d |
+ free (quoted);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ fputs (" ", stdout);
|
|
|
d8307d |
+ for (size_t i = 0; i < length; ++i)
|
|
|
d8307d |
+ printf (" %02X", blob[i]);
|
|
|
d8307d |
+ putc ('\n', stdout);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+static size_t
|
|
|
d8307d |
+string_length_or_zero (const char *str)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ if (str == NULL)
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ return strlen (str);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+void
|
|
|
d8307d |
+support_test_compare_string (const char *left, const char *right,
|
|
|
d8307d |
+ const char *file, int line,
|
|
|
d8307d |
+ const char *left_expr, const char *right_expr)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ /* Two null pointers are accepted. */
|
|
|
d8307d |
+ if (left == NULL && right == NULL)
|
|
|
d8307d |
+ return;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ size_t left_length = string_length_or_zero (left);
|
|
|
d8307d |
+ size_t right_length = string_length_or_zero (right);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (left_length != right_length || left == NULL || right == NULL
|
|
|
d8307d |
+ || memcmp (left, right, left_length) != 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ support_record_failure ();
|
|
|
d8307d |
+ printf ("%s:%d: error: blob comparison failed\n", file, line);
|
|
|
d8307d |
+ if (left_length == right_length && right != NULL && left != NULL)
|
|
|
d8307d |
+ printf (" string length: %zu bytes\n", left_length);
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ report_length ("left", left, left_length);
|
|
|
d8307d |
+ report_length ("right", right, right_length);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ report_string ("left", (const unsigned char *) left,
|
|
|
d8307d |
+ left_length, left_expr);
|
|
|
d8307d |
+ report_string ("right", (const unsigned char *) right,
|
|
|
d8307d |
+ right_length, right_expr);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/test-container.c b/support/test-container.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..b58f0f7b3d1d4859
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/test-container.c
|
|
|
d8307d |
@@ -0,0 +1,988 @@
|
|
|
d8307d |
+/* Run a test case in an isolated namespace.
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#define _FILE_OFFSET_BITS 64
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <stdio.h>
|
|
|
d8307d |
+#include <stdlib.h>
|
|
|
d8307d |
+#include <string.h>
|
|
|
d8307d |
+#include <sched.h>
|
|
|
d8307d |
+#include <sys/syscall.h>
|
|
|
d8307d |
+#include <unistd.h>
|
|
|
d8307d |
+#include <sys/types.h>
|
|
|
d8307d |
+#include <dirent.h>
|
|
|
d8307d |
+#include <string.h>
|
|
|
d8307d |
+#include <sys/stat.h>
|
|
|
d8307d |
+#include <sys/fcntl.h>
|
|
|
d8307d |
+#include <sys/file.h>
|
|
|
d8307d |
+#include <sys/wait.h>
|
|
|
d8307d |
+#include <stdarg.h>
|
|
|
d8307d |
+#include <sys/sysmacros.h>
|
|
|
d8307d |
+#include <ctype.h>
|
|
|
d8307d |
+#include <utime.h>
|
|
|
d8307d |
+#include <errno.h>
|
|
|
d8307d |
+#include <error.h>
|
|
|
d8307d |
+#include <libc-pointer-arith.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+#ifdef __linux__
|
|
|
d8307d |
+#include <sys/mount.h>
|
|
|
d8307d |
+#endif
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <support/support.h>
|
|
|
d8307d |
+#include <support/xunistd.h>
|
|
|
d8307d |
+#include "check.h"
|
|
|
d8307d |
+#include "test-driver.h"
|
|
|
d8307d |
+
|
|
|
d8307d |
+#ifndef __linux__
|
|
|
d8307d |
+#define mount(s,t,fs,f,d) no_mount()
|
|
|
d8307d |
+int no_mount (void)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ FAIL_UNSUPPORTED("mount not supported; port needed");
|
|
|
d8307d |
+}
|
|
|
d8307d |
+#endif
|
|
|
d8307d |
+
|
|
|
d8307d |
+int verbose = 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Running a test in a container is tricky. There are two main
|
|
|
d8307d |
+ categories of things to do:
|
|
|
d8307d |
+
|
|
|
d8307d |
+ 1. "Once" actions, like setting up the container and doing an
|
|
|
d8307d |
+ install into it.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ 2. "Per-test" actions, like copying in support files and
|
|
|
d8307d |
+ configuring the container.
|
|
|
d8307d |
+
|
|
|
d8307d |
+
|
|
|
d8307d |
+ "Once" actions:
|
|
|
d8307d |
+
|
|
|
d8307d |
+ * mkdir $buildroot/testroot.pristine/
|
|
|
d8307d |
+ * install into it
|
|
|
d8307d |
+ * rsync to $buildroot/testroot.root/
|
|
|
d8307d |
+
|
|
|
d8307d |
+ "Per-test" actions:
|
|
|
d8307d |
+ * maybe rsync to $buildroot/testroot.root/
|
|
|
d8307d |
+ * copy support files and test binary
|
|
|
d8307d |
+ * chroot/unshare
|
|
|
d8307d |
+ * set up any mounts (like /proc)
|
|
|
d8307d |
+
|
|
|
d8307d |
+ Magic files:
|
|
|
d8307d |
+
|
|
|
d8307d |
+ For test $srcdir/foo/mytest.c we look for $srcdir/foo/mytest.root
|
|
|
d8307d |
+ and, if found...
|
|
|
d8307d |
+
|
|
|
d8307d |
+ * mytest.root/ is rsync'd into container
|
|
|
d8307d |
+ * mytest.root/preclean.req causes fresh rsync (with delete) before
|
|
|
d8307d |
+ test if present
|
|
|
d8307d |
+ * mytest.root/mytset.script has a list of "commands" to run:
|
|
|
d8307d |
+ syntax:
|
|
|
d8307d |
+ # comment
|
|
|
d8307d |
+ mv FILE FILE
|
|
|
d8307d |
+ cp FILE FILE
|
|
|
d8307d |
+ rm FILE
|
|
|
d8307d |
+ FILE must start with $B/, $S/, $I/, $L/, or /
|
|
|
d8307d |
+ (expands to build dir, source dir, install dir, library dir
|
|
|
d8307d |
+ (in container), or container's root)
|
|
|
d8307d |
+ * mytest.root/postclean.req causes fresh rsync (with delete) after
|
|
|
d8307d |
+ test if present
|
|
|
d8307d |
+
|
|
|
d8307d |
+ Note that $srcdir/foo/mytest.script may be used instead of a
|
|
|
d8307d |
+ $srcdir/foo/mytest.root/mytest.script in the sysroot template, if
|
|
|
d8307d |
+ there is no other reason for a sysroot.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ Design goals:
|
|
|
d8307d |
+
|
|
|
d8307d |
+ * independent of other packages which may not be installed (like
|
|
|
d8307d |
+ rsync or Docker, or even "cp")
|
|
|
d8307d |
+
|
|
|
d8307d |
+ * Simple, easy to review code (i.e. prefer simple naive code over
|
|
|
d8307d |
+ complex efficient code)
|
|
|
d8307d |
+
|
|
|
d8307d |
+ * The current implementation ist parallel-make-safe, but only in
|
|
|
d8307d |
+ that it uses a lock to prevent parallel access to the testroot. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Utility Functions */
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Like xunlink, but it's OK if the file already doesn't exist. */
|
|
|
d8307d |
+void
|
|
|
d8307d |
+maybe_xunlink (const char *path)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ int rv = unlink (path);
|
|
|
d8307d |
+ if (rv < 0 && errno != ENOENT)
|
|
|
d8307d |
+ FAIL_EXIT1 ("unlink (\"%s\"): %m", path);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Like xmkdir, but it's OK if the directory already exists. */
|
|
|
d8307d |
+void
|
|
|
d8307d |
+maybe_xmkdir (const char *path, mode_t mode)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ struct stat st;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (stat (path, &st) == 0
|
|
|
d8307d |
+ && S_ISDIR (st.st_mode))
|
|
|
d8307d |
+ return;
|
|
|
d8307d |
+ xmkdir (path, mode);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Temporarily concatenate multiple strings into one. Allows up to 10
|
|
|
d8307d |
+ temporary results; use strdup () if you need them to be
|
|
|
d8307d |
+ permanent. */
|
|
|
d8307d |
+static char *
|
|
|
d8307d |
+concat (const char *str, ...)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ /* Assume initialized to NULL/zero. */
|
|
|
d8307d |
+ static char *bufs[10];
|
|
|
d8307d |
+ static size_t buflens[10];
|
|
|
d8307d |
+ static int bufn = 0;
|
|
|
d8307d |
+ int n;
|
|
|
d8307d |
+ size_t len;
|
|
|
d8307d |
+ va_list ap, ap2;
|
|
|
d8307d |
+ char *cp;
|
|
|
d8307d |
+ char *next;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ va_start (ap, str);
|
|
|
d8307d |
+ va_copy (ap2, ap);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ n = bufn;
|
|
|
d8307d |
+ bufn = (bufn + 1) % 10;
|
|
|
d8307d |
+ len = strlen (str);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ while ((next = va_arg (ap, char *)) != NULL)
|
|
|
d8307d |
+ len = len + strlen (next);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ va_end (ap);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (bufs[n] == NULL)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ bufs[n] = xmalloc (len + 1); /* NUL */
|
|
|
d8307d |
+ buflens[n] = len + 1;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ else if (buflens[n] < len + 1)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ bufs[n] = xrealloc (bufs[n], len + 1); /* NUL */
|
|
|
d8307d |
+ buflens[n] = len + 1;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ strcpy (bufs[n], str);
|
|
|
d8307d |
+ cp = strchr (bufs[n], '\0');
|
|
|
d8307d |
+ while ((next = va_arg (ap2, char *)) != NULL)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ strcpy (cp, next);
|
|
|
d8307d |
+ cp = strchr (cp, '\0');
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ *cp = 0;
|
|
|
d8307d |
+ va_end (ap2);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ return bufs[n];
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Try to mount SRC onto DEST. */
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+trymount (const char *src, const char *dest)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ if (mount (src, dest, "", MS_BIND, NULL) < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("can't mount %s onto %s\n", src, dest);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Special case of above for devices like /dev/zero where we have to
|
|
|
d8307d |
+ mount a device over a device, not a directory over a directory. */
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+devmount (const char *new_root_path, const char *which)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ int fd;
|
|
|
d8307d |
+ fd = open (concat (new_root_path, "/dev/", which, NULL),
|
|
|
d8307d |
+ O_CREAT | O_TRUNC | O_RDWR, 0777);
|
|
|
d8307d |
+ xclose (fd);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ trymount (concat ("/dev/", which, NULL),
|
|
|
d8307d |
+ concat (new_root_path, "/dev/", which, NULL));
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Returns true if the string "looks like" an environement variable
|
|
|
d8307d |
+ being set. */
|
|
|
d8307d |
+static int
|
|
|
d8307d |
+is_env_setting (const char *a)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ int count_name = 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ while (*a)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (isalnum (*a) || *a == '_')
|
|
|
d8307d |
+ ++count_name;
|
|
|
d8307d |
+ else if (*a == '=' && count_name > 0)
|
|
|
d8307d |
+ return 1;
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+ ++a;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Break the_line into words and store in the_words. Max nwords,
|
|
|
d8307d |
+ returns actual count. */
|
|
|
d8307d |
+static int
|
|
|
d8307d |
+tokenize (char *the_line, char **the_words, int nwords)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ int rv = 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ while (nwords > 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* Skip leading whitespace, if any. */
|
|
|
d8307d |
+ while (*the_line && isspace (*the_line))
|
|
|
d8307d |
+ ++the_line;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* End of line? */
|
|
|
d8307d |
+ if (*the_line == 0)
|
|
|
d8307d |
+ return rv;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* THE_LINE points to a non-whitespace character, so we have a
|
|
|
d8307d |
+ word. */
|
|
|
d8307d |
+ *the_words = the_line;
|
|
|
d8307d |
+ ++the_words;
|
|
|
d8307d |
+ nwords--;
|
|
|
d8307d |
+ ++rv;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Skip leading whitespace, if any. */
|
|
|
d8307d |
+ while (*the_line && ! isspace (*the_line))
|
|
|
d8307d |
+ ++the_line;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* We now point at the trailing NUL *or* some whitespace. */
|
|
|
d8307d |
+ if (*the_line == 0)
|
|
|
d8307d |
+ return rv;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* It was whitespace, skip and keep tokenizing. */
|
|
|
d8307d |
+ *the_line++ = 0;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* We get here if we filled the words buffer. */
|
|
|
d8307d |
+ return rv;
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Mini-RSYNC implementation. Optimize later. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* A few routines for an "rsync buffer" which stores the paths we're
|
|
|
d8307d |
+ working on. We continuously grow and shrink the paths in each
|
|
|
d8307d |
+ buffer so there's lot of re-use. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* We rely on "initialized to zero" to set these up. */
|
|
|
d8307d |
+typedef struct
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ char *buf;
|
|
|
d8307d |
+ size_t len;
|
|
|
d8307d |
+ size_t size;
|
|
|
d8307d |
+} path_buf;
|
|
|
d8307d |
+
|
|
|
d8307d |
+static path_buf spath, dpath;
|
|
|
d8307d |
+
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+r_setup (char *path, path_buf * pb)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ size_t len = strlen (path);
|
|
|
d8307d |
+ if (pb->buf == NULL || pb->size < len + 1)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* Round up. This is an arbitrary number, just to keep from
|
|
|
d8307d |
+ reallocing too often. */
|
|
|
d8307d |
+ size_t sz = ALIGN_UP (len + 1, 512);
|
|
|
d8307d |
+ if (pb->buf == NULL)
|
|
|
d8307d |
+ pb->buf = (char *) xmalloc (sz);
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ pb->buf = (char *) xrealloc (pb->buf, sz);
|
|
|
d8307d |
+ if (pb->buf == NULL)
|
|
|
d8307d |
+ FAIL_EXIT1 ("Out of memory while rsyncing\n");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ pb->size = sz;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ strcpy (pb->buf, path);
|
|
|
d8307d |
+ pb->len = len;
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+r_append (const char *path, path_buf * pb)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ size_t len = strlen (path) + pb->len;
|
|
|
d8307d |
+ if (pb->size < len + 1)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* Round up */
|
|
|
d8307d |
+ size_t sz = ALIGN_UP (len + 1, 512);
|
|
|
d8307d |
+ pb->buf = (char *) xrealloc (pb->buf, sz);
|
|
|
d8307d |
+ if (pb->buf == NULL)
|
|
|
d8307d |
+ FAIL_EXIT1 ("Out of memory while rsyncing\n");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ pb->size = sz;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ strcpy (pb->buf + pb->len, path);
|
|
|
d8307d |
+ pb->len = len;
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+static int
|
|
|
d8307d |
+file_exists (char *path)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ struct stat st;
|
|
|
d8307d |
+ if (lstat (path, &st) == 0)
|
|
|
d8307d |
+ return 1;
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+recursive_remove (char *path)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ pid_t child;
|
|
|
d8307d |
+ int status;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ child = fork ();
|
|
|
d8307d |
+
|
|
|
d8307d |
+ switch (child) {
|
|
|
d8307d |
+ case -1:
|
|
|
d8307d |
+ FAIL_EXIT1 ("Unable to fork");
|
|
|
d8307d |
+ case 0:
|
|
|
d8307d |
+ /* Child. */
|
|
|
d8307d |
+ execlp ("rm", "rm", "-rf", path, NULL);
|
|
|
d8307d |
+ default:
|
|
|
d8307d |
+ /* Parent. */
|
|
|
d8307d |
+ waitpid (child, &status, 0);
|
|
|
d8307d |
+ /* "rm" would have already printed a suitable error message. */
|
|
|
d8307d |
+ if (! WIFEXITED (status)
|
|
|
d8307d |
+ || WEXITSTATUS (status) != 0)
|
|
|
d8307d |
+ exit (1);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ break;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Used for both rsync and the mytest.script "cp" command. */
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+copy_one_file (const char *sname, const char *dname)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ int sfd, dfd;
|
|
|
d8307d |
+ struct stat st;
|
|
|
d8307d |
+ struct utimbuf times;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ sfd = open (sname, O_RDONLY);
|
|
|
d8307d |
+ if (sfd < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("unable to open %s for reading\n", sname);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (fstat (sfd, &st) < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("unable to fstat %s\n", sname);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ dfd = open (dname, O_WRONLY | O_TRUNC | O_CREAT, 0600);
|
|
|
d8307d |
+ if (dfd < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("unable to open %s for writing\n", dname);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ xcopy_file_range (sfd, 0, dfd, 0, st.st_size, 0);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ xclose (sfd);
|
|
|
d8307d |
+ xclose (dfd);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (chmod (dname, st.st_mode & 0777) < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("chmod %s: %s\n", dname, strerror (errno));
|
|
|
d8307d |
+
|
|
|
d8307d |
+ times.actime = st.st_atime;
|
|
|
d8307d |
+ times.modtime = st.st_mtime;
|
|
|
d8307d |
+ if (utime (dname, ×) < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("utime %s: %s\n", dname, strerror (errno));
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* We don't check *everything* about the two files to see if a copy is
|
|
|
d8307d |
+ needed, just the minimum to make sure we get the latest copy. */
|
|
|
d8307d |
+static int
|
|
|
d8307d |
+need_sync (char *ap, char *bp, struct stat *a, struct stat *b)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ if ((a->st_mode & S_IFMT) != (b->st_mode & S_IFMT))
|
|
|
d8307d |
+ return 1;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (S_ISLNK (a->st_mode))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ int rv;
|
|
|
d8307d |
+ char *al, *bl;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (a->st_size != b->st_size)
|
|
|
d8307d |
+ return 1;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ al = xreadlink (ap);
|
|
|
d8307d |
+ bl = xreadlink (bp);
|
|
|
d8307d |
+ rv = strcmp (al, bl);
|
|
|
d8307d |
+ free (al);
|
|
|
d8307d |
+ free (bl);
|
|
|
d8307d |
+ if (rv == 0)
|
|
|
d8307d |
+ return 0; /* links are same */
|
|
|
d8307d |
+ return 1; /* links differ */
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (verbose)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (a->st_size != b->st_size)
|
|
|
d8307d |
+ printf ("SIZE\n");
|
|
|
d8307d |
+ if ((a->st_mode & 0777) != (b->st_mode & 0777))
|
|
|
d8307d |
+ printf ("MODE\n");
|
|
|
d8307d |
+ if (a->st_mtime != b->st_mtime)
|
|
|
d8307d |
+ printf ("TIME\n");
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (a->st_size == b->st_size
|
|
|
d8307d |
+ && ((a->st_mode & 0777) == (b->st_mode & 0777))
|
|
|
d8307d |
+ && a->st_mtime == b->st_mtime)
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ return 1;
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+rsync_1 (path_buf * src, path_buf * dest, int and_delete)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ DIR *dir;
|
|
|
d8307d |
+ struct dirent *de;
|
|
|
d8307d |
+ struct stat s, d;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ r_append ("/", src);
|
|
|
d8307d |
+ r_append ("/", dest);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (verbose)
|
|
|
d8307d |
+ printf ("sync %s to %s %s\n", src->buf, dest->buf,
|
|
|
d8307d |
+ and_delete ? "and delete" : "");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ size_t staillen = src->len;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ size_t dtaillen = dest->len;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ dir = opendir (src->buf);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ while ((de = readdir (dir)) != NULL)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (strcmp (de->d_name, ".") == 0
|
|
|
d8307d |
+ || strcmp (de->d_name, "..") == 0)
|
|
|
d8307d |
+ continue;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ src->len = staillen;
|
|
|
d8307d |
+ r_append (de->d_name, src);
|
|
|
d8307d |
+ dest->len = dtaillen;
|
|
|
d8307d |
+ r_append (de->d_name, dest);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ s.st_mode = ~0;
|
|
|
d8307d |
+ d.st_mode = ~0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (lstat (src->buf, &s) != 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("%s obtained by readdir, but stat failed.\n", src->buf);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* It's OK if this one fails, since we know the file might be
|
|
|
d8307d |
+ missing. */
|
|
|
d8307d |
+ lstat (dest->buf, &d);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (! need_sync (src->buf, dest->buf, &s, &d))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (S_ISDIR (s.st_mode))
|
|
|
d8307d |
+ rsync_1 (src, dest, and_delete);
|
|
|
d8307d |
+ continue;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (d.st_mode != ~0)
|
|
|
d8307d |
+ switch (d.st_mode & S_IFMT)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ case S_IFDIR:
|
|
|
d8307d |
+ if (!S_ISDIR (s.st_mode))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (verbose)
|
|
|
d8307d |
+ printf ("-D %s\n", dest->buf);
|
|
|
d8307d |
+ recursive_remove (dest->buf);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ break;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ default:
|
|
|
d8307d |
+ if (verbose)
|
|
|
d8307d |
+ printf ("-F %s\n", dest->buf);
|
|
|
d8307d |
+ maybe_xunlink (dest->buf);
|
|
|
d8307d |
+ break;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ switch (s.st_mode & S_IFMT)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ case S_IFREG:
|
|
|
d8307d |
+ if (verbose)
|
|
|
d8307d |
+ printf ("+F %s\n", dest->buf);
|
|
|
d8307d |
+ copy_one_file (src->buf, dest->buf);
|
|
|
d8307d |
+ break;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ case S_IFDIR:
|
|
|
d8307d |
+ if (verbose)
|
|
|
d8307d |
+ printf ("+D %s\n", dest->buf);
|
|
|
d8307d |
+ maybe_xmkdir (dest->buf, (s.st_mode & 0777) | 0700);
|
|
|
d8307d |
+ rsync_1 (src, dest, and_delete);
|
|
|
d8307d |
+ break;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ case S_IFLNK:
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ char *lp;
|
|
|
d8307d |
+ if (verbose)
|
|
|
d8307d |
+ printf ("+L %s\n", dest->buf);
|
|
|
d8307d |
+ lp = xreadlink (src->buf);
|
|
|
d8307d |
+ xsymlink (lp, dest->buf);
|
|
|
d8307d |
+ free (lp);
|
|
|
d8307d |
+ break;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ default:
|
|
|
d8307d |
+ break;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ closedir (dir);
|
|
|
d8307d |
+ src->len = staillen;
|
|
|
d8307d |
+ src->buf[staillen] = 0;
|
|
|
d8307d |
+ dest->len = dtaillen;
|
|
|
d8307d |
+ dest->buf[dtaillen] = 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (!and_delete)
|
|
|
d8307d |
+ return;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* The rest of this function removes any files/directories in DEST
|
|
|
d8307d |
+ that do not exist in SRC. This is triggered as part of a
|
|
|
d8307d |
+ preclean or postsclean step. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+ dir = opendir (dest->buf);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ while ((de = readdir (dir)) != NULL)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (strcmp (de->d_name, ".") == 0
|
|
|
d8307d |
+ || strcmp (de->d_name, "..") == 0)
|
|
|
d8307d |
+ continue;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ src->len = staillen;
|
|
|
d8307d |
+ r_append (de->d_name, src);
|
|
|
d8307d |
+ dest->len = dtaillen;
|
|
|
d8307d |
+ r_append (de->d_name, dest);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ s.st_mode = ~0;
|
|
|
d8307d |
+ d.st_mode = ~0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ lstat (src->buf, &s);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (lstat (dest->buf, &d) != 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("%s obtained by readdir, but stat failed.\n", dest->buf);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (s.st_mode == ~0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* dest exists and src doesn't, clean it. */
|
|
|
d8307d |
+ switch (d.st_mode & S_IFMT)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ case S_IFDIR:
|
|
|
d8307d |
+ if (!S_ISDIR (s.st_mode))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (verbose)
|
|
|
d8307d |
+ printf ("-D %s\n", dest->buf);
|
|
|
d8307d |
+ recursive_remove (dest->buf);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ break;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ default:
|
|
|
d8307d |
+ if (verbose)
|
|
|
d8307d |
+ printf ("-F %s\n", dest->buf);
|
|
|
d8307d |
+ maybe_xunlink (dest->buf);
|
|
|
d8307d |
+ break;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ closedir (dir);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+rsync (char *src, char *dest, int and_delete)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ r_setup (src, &spath);
|
|
|
d8307d |
+ r_setup (dest, &dpath);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ rsync_1 (&spath, &dpath, and_delete);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+
|
|
|
d8307d |
+int
|
|
|
d8307d |
+main (int argc, char **argv)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ pid_t child;
|
|
|
d8307d |
+ char *pristine_root_path;
|
|
|
d8307d |
+ char *new_root_path;
|
|
|
d8307d |
+ char *new_cwd_path;
|
|
|
d8307d |
+ char *new_objdir_path;
|
|
|
d8307d |
+ char *new_srcdir_path;
|
|
|
d8307d |
+ char **new_child_proc;
|
|
|
d8307d |
+ char *command_root;
|
|
|
d8307d |
+ char *command_base;
|
|
|
d8307d |
+ char *command_basename;
|
|
|
d8307d |
+ char *so_base;
|
|
|
d8307d |
+ int do_postclean = 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ uid_t original_uid;
|
|
|
d8307d |
+ gid_t original_gid;
|
|
|
d8307d |
+ int UMAP;
|
|
|
d8307d |
+ int GMAP;
|
|
|
d8307d |
+ /* Used for "%lld %lld 1" so need not be large. */
|
|
|
d8307d |
+ char tmp[100];
|
|
|
d8307d |
+ struct stat st;
|
|
|
d8307d |
+ int lock_fd;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ setbuf (stdout, NULL);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* The command line we're expecting looks like this:
|
|
|
d8307d |
+ env <set some vars> ld.so <library path> test-binary
|
|
|
d8307d |
+
|
|
|
d8307d |
+ We need to peel off any "env" or "ld.so" portion of the command
|
|
|
d8307d |
+ line, and keep track of which env vars we should preserve and
|
|
|
d8307d |
+ which we drop. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (argc < 2)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ fprintf (stderr, "Usage: containerize <program to run> <args...>\n");
|
|
|
d8307d |
+ exit (1);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (strcmp (argv[1], "-v") == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ verbose = 1;
|
|
|
d8307d |
+ ++argv;
|
|
|
d8307d |
+ --argc;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (strcmp (argv[1], "env") == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ ++argv;
|
|
|
d8307d |
+ --argc;
|
|
|
d8307d |
+ while (is_env_setting (argv[1]))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* If there are variables we do NOT want to propogate, this
|
|
|
d8307d |
+ is where the test for them goes. */
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* Need to keep these. Note that putenv stores a
|
|
|
d8307d |
+ pointer to our argv. */
|
|
|
d8307d |
+ putenv (argv[1]);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ ++argv;
|
|
|
d8307d |
+ --argc;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (strcmp (argv[1], support_objdir_elf_ldso) == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ ++argv;
|
|
|
d8307d |
+ --argc;
|
|
|
d8307d |
+ while (argv[1][0] == '-')
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (strcmp (argv[1], "--library-path") == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ ++argv;
|
|
|
d8307d |
+ --argc;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ ++argv;
|
|
|
d8307d |
+ --argc;
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ pristine_root_path = strdup (concat (support_objdir_root,
|
|
|
d8307d |
+ "/testroot.pristine", NULL));
|
|
|
d8307d |
+ new_root_path = strdup (concat (support_objdir_root,
|
|
|
d8307d |
+ "/testroot.root", NULL));
|
|
|
d8307d |
+ new_cwd_path = get_current_dir_name ();
|
|
|
d8307d |
+ new_child_proc = argv + 1;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ lock_fd = open (concat (pristine_root_path, "/lock.fd", NULL),
|
|
|
d8307d |
+ O_CREAT | O_TRUNC | O_RDWR, 0666);
|
|
|
d8307d |
+ if (lock_fd < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("Cannot create testroot lock.\n");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ while (flock (lock_fd, LOCK_EX) != 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (errno != EINTR)
|
|
|
d8307d |
+ FAIL_EXIT1 ("Cannot lock testroot.\n");
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ xmkdirp (new_root_path, 0755);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* We look for extra setup info in a subdir in the same spot as the
|
|
|
d8307d |
+ test, with the same name but a ".root" extension. This is that
|
|
|
d8307d |
+ directory. We try to look in the source tree if the path we're
|
|
|
d8307d |
+ given refers to the build tree, but we rely on the path to be
|
|
|
d8307d |
+ absolute. This is what the glibc makefiles do. */
|
|
|
d8307d |
+ command_root = concat (argv[1], ".root", NULL);
|
|
|
d8307d |
+ if (strncmp (command_root, support_objdir_root,
|
|
|
d8307d |
+ strlen (support_objdir_root)) == 0
|
|
|
d8307d |
+ && command_root[strlen (support_objdir_root)] == '/')
|
|
|
d8307d |
+ command_root = concat (support_srcdir_root,
|
|
|
d8307d |
+ argv[1] + strlen (support_objdir_root),
|
|
|
d8307d |
+ ".root", NULL);
|
|
|
d8307d |
+ command_root = strdup (command_root);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* This cuts off the ".root" we appended above. */
|
|
|
d8307d |
+ command_base = strdup (command_root);
|
|
|
d8307d |
+ command_base[strlen (command_base) - 5] = 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* This is the basename of the test we're running. */
|
|
|
d8307d |
+ command_basename = strrchr (command_base, '/');
|
|
|
d8307d |
+ if (command_basename == NULL)
|
|
|
d8307d |
+ command_basename = command_base;
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ ++command_basename;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Shared object base directory. */
|
|
|
d8307d |
+ so_base = strdup (argv[1]);
|
|
|
d8307d |
+ if (strrchr (so_base, '/') != NULL)
|
|
|
d8307d |
+ strrchr (so_base, '/')[1] = 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (file_exists (concat (command_root, "/postclean.req", NULL)))
|
|
|
d8307d |
+ do_postclean = 1;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ rsync (pristine_root_path, new_root_path,
|
|
|
d8307d |
+ file_exists (concat (command_root, "/preclean.req", NULL)));
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (stat (command_root, &st) >= 0
|
|
|
d8307d |
+ && S_ISDIR (st.st_mode))
|
|
|
d8307d |
+ rsync (command_root, new_root_path, 0);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ new_objdir_path = strdup (concat (new_root_path,
|
|
|
d8307d |
+ support_objdir_root, NULL));
|
|
|
d8307d |
+ new_srcdir_path = strdup (concat (new_root_path,
|
|
|
d8307d |
+ support_srcdir_root, NULL));
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* new_cwd_path starts with '/' so no "/" needed between the two. */
|
|
|
d8307d |
+ xmkdirp (concat (new_root_path, new_cwd_path, NULL), 0755);
|
|
|
d8307d |
+ xmkdirp (new_srcdir_path, 0755);
|
|
|
d8307d |
+ xmkdirp (new_objdir_path, 0755);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ original_uid = getuid ();
|
|
|
d8307d |
+ original_gid = getgid ();
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Handle the cp/mv/rm "script" here. */
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ char *the_line = NULL;
|
|
|
d8307d |
+ size_t line_len = 0;
|
|
|
d8307d |
+ char *fname = concat (command_root, "/",
|
|
|
d8307d |
+ command_basename, ".script", NULL);
|
|
|
d8307d |
+ char *the_words[3];
|
|
|
d8307d |
+ FILE *f = fopen (fname, "r");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (verbose && f)
|
|
|
d8307d |
+ fprintf (stderr, "running %s\n", fname);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (f == NULL)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* Try foo.script instead of foo.root/foo.script, as a shortcut. */
|
|
|
d8307d |
+ fname = concat (command_base, ".script", NULL);
|
|
|
d8307d |
+ f = fopen (fname, "r");
|
|
|
d8307d |
+ if (verbose && f)
|
|
|
d8307d |
+ fprintf (stderr, "running %s\n", fname);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Note that we do NOT look for a Makefile-generated foo.script in
|
|
|
d8307d |
+ the build directory. If that is ever needed, this is the place
|
|
|
d8307d |
+ to add it. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* This is where we "interpret" the mini-script which is <test>.script. */
|
|
|
d8307d |
+ if (f != NULL)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ while (getline (&the_line, &line_len, f) > 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ int nt = tokenize (the_line, the_words, 3);
|
|
|
d8307d |
+ int i;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ for (i = 1; i < nt; ++i)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (memcmp (the_words[i], "$B/", 3) == 0)
|
|
|
d8307d |
+ the_words[i] = concat (support_objdir_root,
|
|
|
d8307d |
+ the_words[i] + 2, NULL);
|
|
|
d8307d |
+ else if (memcmp (the_words[i], "$S/", 3) == 0)
|
|
|
d8307d |
+ the_words[i] = concat (support_srcdir_root,
|
|
|
d8307d |
+ the_words[i] + 2, NULL);
|
|
|
d8307d |
+ else if (memcmp (the_words[i], "$I/", 3) == 0)
|
|
|
d8307d |
+ the_words[i] = concat (new_root_path,
|
|
|
d8307d |
+ support_install_prefix,
|
|
|
d8307d |
+ the_words[i] + 2, NULL);
|
|
|
d8307d |
+ else if (memcmp (the_words[i], "$L/", 3) == 0)
|
|
|
d8307d |
+ the_words[i] = concat (new_root_path,
|
|
|
d8307d |
+ support_libdir_prefix,
|
|
|
d8307d |
+ the_words[i] + 2, NULL);
|
|
|
d8307d |
+ else if (the_words[i][0] == '/')
|
|
|
d8307d |
+ the_words[i] = concat (new_root_path,
|
|
|
d8307d |
+ the_words[i], NULL);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (nt == 3 && the_words[2][strlen (the_words[2]) - 1] == '/')
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ char *r = strrchr (the_words[1], '/');
|
|
|
d8307d |
+ if (r)
|
|
|
d8307d |
+ the_words[2] = concat (the_words[2], r + 1, NULL);
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ the_words[2] = concat (the_words[2], the_words[1], NULL);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (nt == 2 && strcmp (the_words[0], "so") == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ the_words[2] = concat (new_root_path, support_libdir_prefix,
|
|
|
d8307d |
+ "/", the_words[1], NULL);
|
|
|
d8307d |
+ the_words[1] = concat (so_base, the_words[1], NULL);
|
|
|
d8307d |
+ copy_one_file (the_words[1], the_words[2]);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ else if (nt == 3 && strcmp (the_words[0], "cp") == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ copy_one_file (the_words[1], the_words[2]);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ else if (nt == 3 && strcmp (the_words[0], "mv") == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (rename (the_words[1], the_words[2]) < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("rename %s -> %s: %s", the_words[1],
|
|
|
d8307d |
+ the_words[2], strerror (errno));
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ else if (nt == 3 && strcmp (the_words[0], "chmod") == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ long int m;
|
|
|
d8307d |
+ m = strtol (the_words[1], NULL, 0);
|
|
|
d8307d |
+ if (chmod (the_words[2], m) < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("chmod %s: %s\n",
|
|
|
d8307d |
+ the_words[2], strerror (errno));
|
|
|
d8307d |
+
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ else if (nt == 2 && strcmp (the_words[0], "rm") == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ maybe_xunlink (the_words[1]);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ else if (nt > 0 && the_words[0][0] != '#')
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ printf ("\033[31minvalid [%s]\033[0m\n", the_words[0]);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ fclose (f);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+#ifdef CLONE_NEWNS
|
|
|
d8307d |
+ /* The unshare here gives us our own spaces and capabilities. */
|
|
|
d8307d |
+ if (unshare (CLONE_NEWUSER | CLONE_NEWPID | CLONE_NEWNS) < 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* Older kernels may not support all the options, or security
|
|
|
d8307d |
+ policy may block this call. */
|
|
|
d8307d |
+ if (errno == EINVAL || errno == EPERM)
|
|
|
d8307d |
+ FAIL_UNSUPPORTED ("unable to unshare user/fs: %s", strerror (errno));
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ FAIL_EXIT1 ("unable to unshare user/fs: %s", strerror (errno));
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+#else
|
|
|
d8307d |
+ /* Some targets may not support unshare at all. */
|
|
|
d8307d |
+ FAIL_UNSUPPORTED ("unshare support missing");
|
|
|
d8307d |
+#endif
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Some systems, by default, all mounts leak out of the namespace. */
|
|
|
d8307d |
+ if (mount ("none", "/", NULL, MS_REC | MS_PRIVATE, NULL) != 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("could not create a private mount namespace\n");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ trymount (support_srcdir_root, new_srcdir_path);
|
|
|
d8307d |
+ trymount (support_objdir_root, new_objdir_path);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ xmkdirp (concat (new_root_path, "/dev", NULL), 0755);
|
|
|
d8307d |
+ devmount (new_root_path, "null");
|
|
|
d8307d |
+ devmount (new_root_path, "zero");
|
|
|
d8307d |
+ devmount (new_root_path, "urandom");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* We're done with the "old" root, switch to the new one. */
|
|
|
d8307d |
+ if (chroot (new_root_path) < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("Can't chroot to %s - ", new_root_path);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (chdir (new_cwd_path) < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("Can't cd to new %s - ", new_cwd_path);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* To complete the containerization, we need to fork () at least
|
|
|
d8307d |
+ once. We can't exec, nor can we somehow link the new child to
|
|
|
d8307d |
+ our parent. So we run the child and propogate it's exit status
|
|
|
d8307d |
+ up. */
|
|
|
d8307d |
+ child = fork ();
|
|
|
d8307d |
+ if (child < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("Unable to fork");
|
|
|
d8307d |
+ else if (child > 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* Parent. */
|
|
|
d8307d |
+ int status;
|
|
|
d8307d |
+ waitpid (child, &status, 0);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* There's a bit of magic here, since the buildroot is mounted
|
|
|
d8307d |
+ in our space, the paths are still valid, and since the mounts
|
|
|
d8307d |
+ aren't recursive, it sees *only* the built root, not anything
|
|
|
d8307d |
+ we would normally se if we rsync'd to "/" like mounted /dev
|
|
|
d8307d |
+ files. */
|
|
|
d8307d |
+ if (do_postclean)
|
|
|
d8307d |
+ rsync (pristine_root_path, new_root_path, 1);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (WIFEXITED (status))
|
|
|
d8307d |
+ exit (WEXITSTATUS (status));
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (WIFSIGNALED (status))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ printf ("%%SIGNALLED%%\n");
|
|
|
d8307d |
+ exit (77);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ printf ("%%EXITERROR%%\n");
|
|
|
d8307d |
+ exit (78);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* The rest is the child process, which is now PID 1 and "in" the
|
|
|
d8307d |
+ new root. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+ maybe_xmkdir ("/tmp", 0755);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Now that we're pid 1 (effectively "root") we can mount /proc */
|
|
|
d8307d |
+ maybe_xmkdir ("/proc", 0777);
|
|
|
d8307d |
+ if (mount ("proc", "/proc", "proc", 0, NULL) < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("Unable to mount /proc: ");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* We map our original UID to the same UID in the container so we
|
|
|
d8307d |
+ can own our own files normally. */
|
|
|
d8307d |
+ UMAP = open ("/proc/self/uid_map", O_WRONLY);
|
|
|
d8307d |
+ if (UMAP < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("can't write to /proc/self/uid_map\n");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ sprintf (tmp, "%lld %lld 1\n",
|
|
|
d8307d |
+ (long long) original_uid, (long long) original_uid);
|
|
|
d8307d |
+ write (UMAP, tmp, strlen (tmp));
|
|
|
d8307d |
+ xclose (UMAP);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* We must disable setgroups () before we can map our groups, else we
|
|
|
d8307d |
+ get EPERM. */
|
|
|
d8307d |
+ GMAP = open ("/proc/self/setgroups", O_WRONLY);
|
|
|
d8307d |
+ if (GMAP >= 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* We support kernels old enough to not have this. */
|
|
|
d8307d |
+ write (GMAP, "deny\n", 5);
|
|
|
d8307d |
+ xclose (GMAP);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* We map our original GID to the same GID in the container so we
|
|
|
d8307d |
+ can own our own files normally. */
|
|
|
d8307d |
+ GMAP = open ("/proc/self/gid_map", O_WRONLY);
|
|
|
d8307d |
+ if (GMAP < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("can't write to /proc/self/gid_map\n");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ sprintf (tmp, "%lld %lld 1\n",
|
|
|
d8307d |
+ (long long) original_gid, (long long) original_gid);
|
|
|
d8307d |
+ write (GMAP, tmp, strlen (tmp));
|
|
|
d8307d |
+ xclose (GMAP);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Now run the child. */
|
|
|
d8307d |
+ execvp (new_child_proc[0], new_child_proc);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Or don't run the child? */
|
|
|
d8307d |
+ FAIL_EXIT1 ("Unable to exec %s\n", new_child_proc[0]);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Because gcc won't know error () never returns... */
|
|
|
d8307d |
+ exit (EXIT_UNSUPPORTED);
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/true-container.c b/support/true-container.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..57dc57e252a96acc
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/true-container.c
|
|
|
d8307d |
@@ -0,0 +1,26 @@
|
|
|
d8307d |
+/* Minimal /bin/true for in-container use.
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Implements the in-container /bin/true, which always returns true
|
|
|
d8307d |
+ (0). */
|
|
|
d8307d |
+
|
|
|
d8307d |
+int
|
|
|
d8307d |
+main (void)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/tst-support_blob_repeat.c b/support/tst-support_blob_repeat.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..1978c14488106ff2
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/tst-support_blob_repeat.c
|
|
|
d8307d |
@@ -0,0 +1,85 @@
|
|
|
d8307d |
+/* Tests for <support/blob_repeat.h>
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <stdio.h>
|
|
|
d8307d |
+#include <support/blob_repeat.h>
|
|
|
d8307d |
+#include <support/check.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+static int
|
|
|
d8307d |
+do_test (void)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ struct support_blob_repeat repeat
|
|
|
d8307d |
+ = support_blob_repeat_allocate ("5", 1, 5);
|
|
|
d8307d |
+ TEST_COMPARE_BLOB (repeat.start, repeat.size, "55555", 5);
|
|
|
d8307d |
+ support_blob_repeat_free (&repeat);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ repeat = support_blob_repeat_allocate ("ABC", 3, 3);
|
|
|
d8307d |
+ TEST_COMPARE_BLOB (repeat.start, repeat.size, "ABCABCABC", 9);
|
|
|
d8307d |
+ support_blob_repeat_free (&repeat);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ repeat = support_blob_repeat_allocate ("abc", 4, 3);
|
|
|
d8307d |
+ TEST_COMPARE_BLOB (repeat.start, repeat.size, "abc\0abc\0abc", 12);
|
|
|
d8307d |
+ support_blob_repeat_free (&repeat);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ size_t gigabyte = 1U << 30;
|
|
|
d8307d |
+ repeat = support_blob_repeat_allocate ("X", 1, gigabyte + 1);
|
|
|
d8307d |
+ if (repeat.start == NULL)
|
|
|
d8307d |
+ puts ("warning: not enough memory for 1 GiB mapping");
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ TEST_COMPARE (repeat.size, gigabyte + 1);
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ unsigned char *p = repeat.start;
|
|
|
d8307d |
+ for (size_t i = 0; i < gigabyte + 1; ++i)
|
|
|
d8307d |
+ if (p[i] != 'X')
|
|
|
d8307d |
+ FAIL_EXIT1 ("invalid byte 0x%02x at %zu", p[i], i);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Check that there is no sharing across the mapping. */
|
|
|
d8307d |
+ p[0] = 'Y';
|
|
|
d8307d |
+ p[1U << 24] = 'Z';
|
|
|
d8307d |
+ for (size_t i = 0; i < gigabyte + 1; ++i)
|
|
|
d8307d |
+ if (i == 0)
|
|
|
d8307d |
+ TEST_COMPARE (p[i], 'Y');
|
|
|
d8307d |
+ else if (i == 1U << 24)
|
|
|
d8307d |
+ TEST_COMPARE (p[i], 'Z');
|
|
|
d8307d |
+ else if (p[i] != 'X')
|
|
|
d8307d |
+ FAIL_EXIT1 ("invalid byte 0x%02x at %zu", p[i], i);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ support_blob_repeat_free (&repeat);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ repeat = support_blob_repeat_allocate ("012345678", 9, 10 * 1000 * 1000);
|
|
|
d8307d |
+ if (repeat.start == NULL)
|
|
|
d8307d |
+ puts ("warning: not enough memory for large mapping");
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ unsigned char *p = repeat.start;
|
|
|
d8307d |
+ for (int i = 0; i < 10 * 1000 * 1000; ++i)
|
|
|
d8307d |
+ for (int j = 0; j <= 8; ++j)
|
|
|
d8307d |
+ if (p[i * 9 + j] != '0' + j)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ printf ("error: element %d index %d\n", i, j);
|
|
|
d8307d |
+ TEST_COMPARE (p[i * 9 + j], '0' + j);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ support_blob_repeat_free (&repeat);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <support/test-driver.c>
|
|
|
d8307d |
diff --git a/support/tst-test_compare_string.c b/support/tst-test_compare_string.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..2a4b258587a7c8ec
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/tst-test_compare_string.c
|
|
|
d8307d |
@@ -0,0 +1,107 @@
|
|
|
d8307d |
+/* Basic test for the TEST_COMPARE_STRING macro.
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <string.h>
|
|
|
d8307d |
+#include <support/check.h>
|
|
|
d8307d |
+#include <support/capture_subprocess.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+subprocess (void *closure)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ /* These tests should fail. They were chosen to cover differences
|
|
|
d8307d |
+ in length (with the same contents), single-bit mismatches, and
|
|
|
d8307d |
+ mismatching null pointers. */
|
|
|
d8307d |
+ TEST_COMPARE_STRING ("", NULL); /* Line 29. */
|
|
|
d8307d |
+ TEST_COMPARE_STRING ("X", ""); /* Line 30. */
|
|
|
d8307d |
+ TEST_COMPARE_STRING (NULL, "X"); /* Line 31. */
|
|
|
d8307d |
+ TEST_COMPARE_STRING ("abcd", "abcD"); /* Line 32. */
|
|
|
d8307d |
+ TEST_COMPARE_STRING ("abcd", NULL); /* Line 33. */
|
|
|
d8307d |
+ TEST_COMPARE_STRING (NULL, "abcd"); /* Line 34. */
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Same contents, different addresses. */
|
|
|
d8307d |
+char buffer_abc_1[] = "abc";
|
|
|
d8307d |
+char buffer_abc_2[] = "abc";
|
|
|
d8307d |
+
|
|
|
d8307d |
+static int
|
|
|
d8307d |
+do_test (void)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ /* This should succeed. Even if the pointers and array contents are
|
|
|
d8307d |
+ different, zero-length inputs are not different. */
|
|
|
d8307d |
+ TEST_COMPARE_STRING (NULL, NULL);
|
|
|
d8307d |
+ TEST_COMPARE_STRING ("", "");
|
|
|
d8307d |
+ TEST_COMPARE_STRING (buffer_abc_1, buffer_abc_2);
|
|
|
d8307d |
+ TEST_COMPARE_STRING (buffer_abc_1, "abc");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ struct support_capture_subprocess proc = support_capture_subprocess
|
|
|
d8307d |
+ (&subprocess, NULL);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Discard the reported error. */
|
|
|
d8307d |
+ support_record_failure_reset ();
|
|
|
d8307d |
+
|
|
|
d8307d |
+ puts ("info: *** subprocess output starts ***");
|
|
|
d8307d |
+ fputs (proc.out.buffer, stdout);
|
|
|
d8307d |
+ puts ("info: *** subprocess output ends ***");
|
|
|
d8307d |
+
|
|
|
d8307d |
+ TEST_VERIFY
|
|
|
d8307d |
+ (strcmp (proc.out.buffer,
|
|
|
d8307d |
+"tst-test_compare_string.c:29: error: blob comparison failed\n"
|
|
|
d8307d |
+" left string: 0 bytes\n"
|
|
|
d8307d |
+" right string: NULL\n"
|
|
|
d8307d |
+"tst-test_compare_string.c:30: error: blob comparison failed\n"
|
|
|
d8307d |
+" left string: 1 bytes\n"
|
|
|
d8307d |
+" right string: 0 bytes\n"
|
|
|
d8307d |
+" left (evaluated from \"X\"):\n"
|
|
|
d8307d |
+" \"X\"\n"
|
|
|
d8307d |
+" 58\n"
|
|
|
d8307d |
+"tst-test_compare_string.c:31: error: blob comparison failed\n"
|
|
|
d8307d |
+" left string: NULL\n"
|
|
|
d8307d |
+" right string: 1 bytes\n"
|
|
|
d8307d |
+" right (evaluated from \"X\"):\n"
|
|
|
d8307d |
+" \"X\"\n"
|
|
|
d8307d |
+" 58\n"
|
|
|
d8307d |
+"tst-test_compare_string.c:32: error: blob comparison failed\n"
|
|
|
d8307d |
+" string length: 4 bytes\n"
|
|
|
d8307d |
+" left (evaluated from \"abcd\"):\n"
|
|
|
d8307d |
+" \"abcd\"\n"
|
|
|
d8307d |
+" 61 62 63 64\n"
|
|
|
d8307d |
+" right (evaluated from \"abcD\"):\n"
|
|
|
d8307d |
+" \"abcD\"\n"
|
|
|
d8307d |
+" 61 62 63 44\n"
|
|
|
d8307d |
+"tst-test_compare_string.c:33: error: blob comparison failed\n"
|
|
|
d8307d |
+" left string: 4 bytes\n"
|
|
|
d8307d |
+" right string: NULL\n"
|
|
|
d8307d |
+" left (evaluated from \"abcd\"):\n"
|
|
|
d8307d |
+" \"abcd\"\n"
|
|
|
d8307d |
+" 61 62 63 64\n"
|
|
|
d8307d |
+"tst-test_compare_string.c:34: error: blob comparison failed\n"
|
|
|
d8307d |
+" left string: NULL\n"
|
|
|
d8307d |
+" right string: 4 bytes\n"
|
|
|
d8307d |
+" right (evaluated from \"abcd\"):\n"
|
|
|
d8307d |
+" \"abcd\"\n"
|
|
|
d8307d |
+" 61 62 63 64\n"
|
|
|
d8307d |
+ ) == 0);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Check that there is no output on standard error. */
|
|
|
d8307d |
+ support_capture_subprocess_check (&proc, "TEST_COMPARE_STRING",
|
|
|
d8307d |
+ 0, sc_allow_stdout);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <support/test-driver.c>
|
|
|
d8307d |
diff --git a/support/xcopy_file_range.c b/support/xcopy_file_range.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..b3501a4d5ec3fdfd
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/xcopy_file_range.c
|
|
|
d8307d |
@@ -0,0 +1,32 @@
|
|
|
d8307d |
+/* copy_file_range with error checking.
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <support/support.h>
|
|
|
d8307d |
+#include <support/xunistd.h>
|
|
|
d8307d |
+#include <support/check.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+ssize_t
|
|
|
d8307d |
+xcopy_file_range (int infd, off64_t *pinoff, int outfd, off64_t *poutoff,
|
|
|
d8307d |
+ size_t length, unsigned int flags)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ ssize_t status = support_copy_file_range (infd, pinoff, outfd,
|
|
|
d8307d |
+ poutoff, length, flags);
|
|
|
d8307d |
+ if (status == -1)
|
|
|
d8307d |
+ FAIL_EXIT1 ("cannot copy file: %m\n");
|
|
|
d8307d |
+ return status;
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/xmkdirp.c b/support/xmkdirp.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..fada0452eafe269e
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/xmkdirp.c
|
|
|
d8307d |
@@ -0,0 +1,66 @@
|
|
|
d8307d |
+/* Error-checking replacement for "mkdir -p".
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <support/support.h>
|
|
|
d8307d |
+#include <support/check.h>
|
|
|
d8307d |
+#include <support/xunistd.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <stdlib.h>
|
|
|
d8307d |
+#include <string.h>
|
|
|
d8307d |
+#include <errno.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Equivalent of "mkdir -p". Any failures cause FAIL_EXIT1 so no
|
|
|
d8307d |
+ return code is needed. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+void
|
|
|
d8307d |
+xmkdirp (const char *path, mode_t mode)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ struct stat s;
|
|
|
d8307d |
+ const char *slash_p;
|
|
|
d8307d |
+ int rv;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (path[0] == 0)
|
|
|
d8307d |
+ return;
|
|
|
d8307d |
+
|
|
|
d8307d |
+ if (stat (path, &s) == 0)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ if (S_ISDIR (s.st_mode))
|
|
|
d8307d |
+ return;
|
|
|
d8307d |
+ errno = EEXIST;
|
|
|
d8307d |
+ FAIL_EXIT1 ("mkdir_p (\"%s\", 0%o): %m", path, mode);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ slash_p = strrchr (path, '/');
|
|
|
d8307d |
+ if (slash_p != NULL)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ while (slash_p > path && slash_p[-1] == '/')
|
|
|
d8307d |
+ --slash_p;
|
|
|
d8307d |
+ if (slash_p > path)
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ char *parent = xstrndup (path, slash_p - path);
|
|
|
d8307d |
+ xmkdirp (parent, mode);
|
|
|
d8307d |
+ free (parent);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+
|
|
|
d8307d |
+ rv = mkdir (path, mode);
|
|
|
d8307d |
+ if (rv != 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("mkdir_p (\"%s\", 0%o): %m", path, mode);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ return;
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/xsymlink.c b/support/xsymlink.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..0f3edf640a1a99a6
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/support/xsymlink.c
|
|
|
d8307d |
@@ -0,0 +1,29 @@
|
|
|
d8307d |
+/* Error-checking replacement for "symlink".
|
|
|
d8307d |
+ Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <support/support.h>
|
|
|
d8307d |
+#include <support/check.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <unistd.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+void
|
|
|
d8307d |
+xsymlink (const char *target, const char *linkpath)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ if (symlink (target, linkpath) < 0)
|
|
|
d8307d |
+ FAIL_EXIT1 ("symlink (\"%s\", \"%s\")", target, linkpath);
|
|
|
d8307d |
+}
|
|
|
d8307d |
diff --git a/support/xunistd.h b/support/xunistd.h
|
|
|
d8307d |
index 5fe5dae818def4ec..f99f362cb4763c5b 100644
|
|
|
d8307d |
--- a/support/xunistd.h
|
|
|
d8307d |
+++ b/support/xunistd.h
|
|
|
d8307d |
@@ -43,6 +43,10 @@ void xunlink (const char *path);
|
|
|
d8307d |
long xsysconf (int name);
|
|
|
d8307d |
long long xlseek (int fd, long long offset, int whence);
|
|
|
d8307d |
void xftruncate (int fd, long long length);
|
|
|
d8307d |
+void xsymlink (const char *target, const char *linkpath);
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Equivalent of "mkdir -p". */
|
|
|
d8307d |
+void xmkdirp (const char *, mode_t);
|
|
|
d8307d |
|
|
|
d8307d |
/* Read the link at PATH. The caller should free the returned string
|
|
|
d8307d |
with free. */
|
|
|
d8307d |
@@ -60,6 +64,9 @@ void *xmmap (void *addr, size_t length, int prot, int flags, int fd);
|
|
|
d8307d |
void xmprotect (void *addr, size_t length, int prot);
|
|
|
d8307d |
void xmunmap (void *addr, size_t length);
|
|
|
d8307d |
|
|
|
d8307d |
+ssize_t xcopy_file_range(int fd_in, loff_t *off_in, int fd_out,
|
|
|
d8307d |
+ loff_t *off_out, size_t len, unsigned int flags);
|
|
|
d8307d |
+
|
|
|
d8307d |
__END_DECLS
|
|
|
d8307d |
|
|
|
d8307d |
#endif /* SUPPORT_XUNISTD_H */
|