Remove readdir-rand
authorColin Walters <walters@verbum.org>
Mon, 31 Oct 2022 13:00:28 +0000 (09:00 -0400)
committerColin Walters <walters@verbum.org>
Tue, 1 Nov 2022 20:29:17 +0000 (16:29 -0400)
This was only there to reproduce a bug we hit long ago
with bootloader file ordering.  We're extremely unlikely
to reintroduce such a bug, and it's not worth carrying around
this code.

Makefile-tests.am
tests/libtest.sh
tests/readdir-rand.c [deleted file]
tests/test-commit-timestamp.sh

index 1ad660bf42d7c9438cbaf37e237458eaf4d09949..470eec25513963dc64c7ee8e81c6e7e0363771ee 100644 (file)
@@ -255,18 +255,6 @@ else
 EXTRA_DIST += $(js_installed_tests)
 endif
 
-test_ltlibraries = libreaddir-rand.la
-libreaddir_rand_la_SOURCES = tests/readdir-rand.c
-libreaddir_rand_la_CFLAGS = $(AM_CFLAGS) $(OT_INTERNAL_GIO_UNIX_CFLAGS)
-libreaddir_rand_la_LIBADD = \
-       -ldl \
-       $(OT_INTERNAL_GIO_UNIX_LIBS) \
-       $(NULL)
-libreaddir_rand_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
-if !ENABLE_INSTALLED_TESTS
-libreaddir_rand_la_LDFLAGS += -rpath $(abs_builddir)
-endif
-
 _installed_or_uninstalled_test_programs = tests/test-varint tests/test-ot-unix-utils tests/test-bsdiff tests/test-mutable-tree \
        tests/test-keyfile-utils tests/test-ot-opt-utils tests/test-ot-tool-util \
        tests/test-checksum tests/test-lzma tests/test-rollsum \
@@ -415,11 +403,7 @@ EXTRA_DIST += \
        tests/libtest.sh \
        $(NULL)
 
-tests/libreaddir-rand.so: Makefile
-       mkdir -p tests/
-       $(AM_V_GEN) ln -fns ../.libs/libreaddir-rand.so tests/
-ALL_LOCAL_RULES += tests/libreaddir-rand.so
-CLEANFILES += tests/libreaddir-rand.so tests/ostree-symlink-stamp \
+CLEANFILES += tests/ostree-symlink-stamp \
                tests/ostree-prepare-root-symlink-stamp tests/ostree-remount-symlink-stamp \
                tests/rofiles-fuse-symlink-stamp tests/ostree
 CLEANFILES += tests/ostree-prepare-root tests/ostree-remount tests/rofiles-fuse
index 5830f210e052f27d6829bd44ece311084bfcb779..af0003631b96c90c717a77f78b5c52b68c2073f9 100755 (executable)
@@ -172,17 +172,9 @@ if test -n "${ASAN_OPTIONS:-}"; then
     BUILT_WITH_ASAN=1
 fi
 
+CMD_PREFIX=""
 if test -n "${OT_TESTS_VALGRIND:-}"; then
     CMD_PREFIX="env G_SLICE=always-malloc OSTREE_SUPPRESS_SYNCFS=1 valgrind -q --error-exitcode=1 --leak-check=full --num-callers=30 --suppressions=${test_srcdir}/glib.supp --suppressions=${test_srcdir}/ostree.supp"
-else
-    # In some cases the LD_PRELOAD may cause obscure problems,
-    # e.g. right now it breaks for me with -fsanitize=address, so
-    # let's allow users to skip it.
-    if test -z "${OT_SKIP_READDIR_RAND:-}" && test -z "${BUILT_WITH_ASAN:-}"; then
-       CMD_PREFIX="env LD_PRELOAD=${test_builddir}/libreaddir-rand.so"
-    else
-       CMD_PREFIX=""
-    fi
 fi
 
 if test -n "${OSTREE_UNINSTALLED:-}"; then
diff --git a/tests/readdir-rand.c b/tests/readdir-rand.c
deleted file mode 100644 (file)
index cd3b3b0..0000000
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Copyright (C) 2015 Colin Walters <walters@verbum.org>.
- *
- * SPDX-License-Identifier: LGPL-2.0+
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <https://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include <dirent.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <dlfcn.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <glib.h>
-
-/* Glibc uses readdir64 when _FILE_OFFSET_BITS == 64 as set by
- * AC_SYS_LARGEFILE on 32 bit systems.
- */
-#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
-# define READDIR "readdir64"
-# define READDIR_R "readdir64_r"
-#else
-# define READDIR "readdir"
-# define READDIR_R "readdir_r"
-#endif
-
-/*
- * copy_dirent:
- * @other: Another struct dirent
- *
- * Returns: a copy of @other. Free with g_free().
- */
-static struct dirent *
-copy_dirent (const struct dirent *other)
-{
-  struct dirent *self;
-  size_t len;
-
-  /* We can't just use sizeof (struct dirent) for the length to copy,
-   * because filenames are allowed to be longer than NAME_MAX bytes. */
-  len = G_STRUCT_OFFSET (struct dirent, d_name) + strlen (other->d_name) + 1;
-
-  if (len < other->d_reclen)
-    len = other->d_reclen;
-
-  if (len < sizeof (struct dirent))
-    len = sizeof (struct dirent);
-
-  self = g_malloc0 (len);
-  memcpy (self, other, len);
-  return self;
-}
-
-static GHashTable *direntcache;
-static GMutex direntcache_lock;
-static gsize initialized;
-
-typedef struct {
-  GPtrArray *entries;
-  guint offset;
-} DirEntries;
-
-static void
-dir_entries_free (gpointer data)
-{
-  DirEntries *d = data;
-  g_ptr_array_unref (d->entries);
-  g_free (d);
-}
-
-static DirEntries *
-dir_entries_new (void)
-{
-  DirEntries *d = g_new0 (DirEntries, 1);
-  d->entries = g_ptr_array_new_with_free_func (g_free);
-  return d;
-}
-
-static void
-ensure_initialized (void)
-{
-  if (g_once_init_enter (&initialized))
-    {
-      direntcache = g_hash_table_new_full (NULL, NULL, NULL, dir_entries_free);
-      g_mutex_init (&direntcache_lock);
-      g_once_init_leave (&initialized, 1);
-    }
-}
-
-struct dirent *
-readdir (DIR *dirp)
-{
-  struct dirent *(*real_readdir)(DIR *dirp) = dlsym (RTLD_NEXT, READDIR);
-  struct dirent *ret;
-  gboolean cache_another = TRUE;
-
-  ensure_initialized ();
-
-  /* The core idea here is that each time through the loop, we read a
-   * directory entry.  If there is one, we choose whether to cache it
-   * or to return it.  Because multiple entries can be cached,
-   * ordering is randomized.  Statistically, the order will still be
-   * *weighted* towards the ordering returned from the
-   * kernel/filesystem, but the goal here is just to provide some
-   * randomness in order to trigger bugs, not to be perfectly random.
-   */
-  while (cache_another)
-    {
-      DirEntries *de;
-
-      errno = 0;
-      ret = real_readdir (dirp);
-      if (ret == NULL && errno != 0)
-        goto out;
-
-      g_mutex_lock (&direntcache_lock);
-      de = g_hash_table_lookup (direntcache, dirp);
-      if (ret)
-        {
-          if (g_random_boolean ())
-            {
-              struct dirent *copy;
-              if (!de)
-                {
-                  de = dir_entries_new ();
-                  g_hash_table_insert (direntcache, dirp, de);
-                }
-              copy = copy_dirent (ret);
-              g_ptr_array_add (de->entries, copy);
-            }
-          else
-            {
-              cache_another = FALSE;
-            }
-        }
-      else
-        {
-          if (de && de->offset < de->entries->len)
-            {
-              ret = de->entries->pdata[de->offset];
-              de->offset++;
-            }
-          cache_another = FALSE;
-        }
-      g_mutex_unlock (&direntcache_lock);
-    }
-
- out:
-  return ret;
-}
-
-int
-closedir (DIR *dirp)
-{
-  int (*real_closedir)(DIR *dirp) = dlsym (RTLD_NEXT, "closedir");
-
-  ensure_initialized ();
-
-  g_mutex_lock (&direntcache_lock);
-  g_hash_table_remove (direntcache, dirp);
-  g_mutex_unlock (&direntcache_lock);
-
-  return real_closedir (dirp);
-}
-
-static void
-assert_no_cached_entries (DIR *dirp)
-{
-  DirEntries *de;
-  g_mutex_lock (&direntcache_lock);
-  de = g_hash_table_lookup (direntcache, dirp);
-  g_assert (!de || de->entries->len == 0);
-  g_mutex_unlock (&direntcache_lock);
-}
-
-void
-seekdir (DIR *dirp, long loc)
-{
-  void (*real_seekdir)(DIR *dirp, long loc) = dlsym (RTLD_NEXT, "seekdir");
-
-  ensure_initialized ();
-
-  /* For now, crash if seekdir is called when we have cached entries.
-   * If some app wants to use this and seekdir() we can implement it.
-   */
-  assert_no_cached_entries (dirp);
-
-  real_seekdir (dirp, loc);
-}
-
-void
-rewinddir (DIR *dirp)
-{
-  void (*real_rewinddir)(DIR *dirp) = dlsym (RTLD_NEXT, "rewinddir");
-
-  ensure_initialized ();
-
-  /* Blow away the cache */
-  g_mutex_lock (&direntcache_lock);
-  g_hash_table_remove (direntcache, dirp);
-  g_mutex_unlock (&direntcache_lock);
-
-  real_rewinddir (dirp);
-}
-
-int
-readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result)
-{
-  int (*real_readdir_r)(DIR *dirp, struct dirent *entry, struct dirent **result) = dlsym (RTLD_NEXT, READDIR_R);
-
-  ensure_initialized ();
-
-  /* For now, assert that no one is mixing readdir_r() with readdir().
-   * It'd be broken to do so, and very few programs use readdir_r()
-   * anyways. */
-  assert_no_cached_entries (dirp);
-
-  return real_readdir_r (dirp, entry, result);
-}
index 7dbdbdfc757a58f44ce8f5ded36b90fa61078dc7..0688c63a4bdb49ddb4c0016f0adfa8a1cd5fe852 100755 (executable)
@@ -30,11 +30,11 @@ mkdir testrepo-files
 cd testrepo-files
 echo first > firstfile
 cd ..
-${CMD_PREFIX} SOURCE_DATE_EPOCH='1234567890' ostree --repo=./testrepo commit -b env -s "env timestamp"
-if (${CMD_PREFIX} SOURCE_DATE_EPOCH='invalid' ostree --repo=./testrepo commit -b env -s "invalid timestamp") 2> commit-invalid.txt; then
+${CMD_PREFIX} env SOURCE_DATE_EPOCH='1234567890' ostree --repo=./testrepo commit -b env -s "env timestamp"
+if (${CMD_PREFIX} env SOURCE_DATE_EPOCH='invalid' ostree --repo=./testrepo commit -b env -s "invalid timestamp") 2> commit-invalid.txt; then
     assert_not_reached "commit with invalid timestamp succeeded"
 fi
-if (${CMD_PREFIX} SOURCE_DATE_EPOCH='12345678901234567890' ostree --repo=./testrepo commit -b env -s "overflowing timestamp") 2> commit-overflowing.txt; then
+if (${CMD_PREFIX} env SOURCE_DATE_EPOCH='12345678901234567890' ostree --repo=./testrepo commit -b env -s "overflowing timestamp") 2> commit-overflowing.txt; then
     assert_not_reached "commit with overflowing timestamp succeeded"
 fi
 ${CMD_PREFIX} ostree --repo=./testrepo show env > show-env.txt