+2022-04-13 Aaron Merey <amerey@redhat.com>
+
+ * debuginfod-client.c (debuginfod_query_server):
+ Drop st_mode check. Add st_size > 0 check.
+ Save target_mtime before calling
+ debuginfod_config_cache. unlink target_cache_path
+ on EACCESS. Create target_cache_path with DEFFILEMODE.
+
2022-04-03 Frank Ch. Eigler <fche@redhat.com>
* debuginfod.cxx (main): Use single dual-stack daemon setup,
static const long cache_clean_default_interval_s = 86400; /* 1 day */
/* The cache_miss_default_s within the debuginfod cache specifies how
- frequently the 000-permision file should be released.*/
+ frequently the empty file should be released.*/
static const long cache_miss_default_s = 600; /* 10 min */
static const char *cache_miss_filename = "cache_miss_s";
if (rc != 0)
goto out;
- struct stat st;
- /* Check if the file exists and it's of permission 000; must check
- explicitly rather than trying to open it first (PR28240). */
- if (stat(target_cache_path, &st) == 0
- && (st.st_mode & 0777) == 0)
+ /* Check if the target is already in the cache. */
+ int fd = open(target_cache_path, O_RDONLY);
+ if (fd >= 0)
{
- time_t cache_miss;
-
- rc = debuginfod_config_cache(cache_miss_path, cache_miss_default_s, &st);
- if (rc < 0)
- goto out;
+ struct stat st;
+ if (fstat(fd, &st) != 0)
+ {
+ rc = -errno;
+ close (fd);
+ goto out;
+ }
- cache_miss = (time_t)rc;
- if (time(NULL) - st.st_mtime <= cache_miss)
+ /* If the file is non-empty, then we are done. */
+ if (st.st_size > 0)
{
- rc = -ENOENT;
- goto out;
- }
+ if (path != NULL)
+ {
+ *path = strdup(target_cache_path);
+ if (*path == NULL)
+ {
+ rc = -errno;
+ close (fd);
+ goto out;
+ }
+ }
+ /* Success!!!! */
+ rc = fd;
+ goto out;
+ }
else
- /* TOCTOU non-problem: if another task races, puts a working
- download or a 000 file in its place, unlinking here just
- means WE will try to download again as uncached. */
- unlink(target_cache_path);
- }
-
- /* If the target is already in the cache (known not-000 - PR28240),
- then we are done. */
- int fd = open (target_cache_path, O_RDONLY);
- if (fd >= 0)
- {
- /* Success!!!! */
- if (path != NULL)
- *path = strdup(target_cache_path);
- rc = fd;
- goto out;
+ {
+ /* The file is empty. Attempt to download only if enough time
+ has passed since the last attempt. */
+ time_t cache_miss;
+ time_t target_mtime = st.st_mtime;
+ rc = debuginfod_config_cache(cache_miss_path,
+ cache_miss_default_s, &st);
+ if (rc < 0)
+ {
+ close(fd);
+ goto out;
+ }
+
+ cache_miss = (time_t)rc;
+ if (time(NULL) - target_mtime <= cache_miss)
+ {
+ close(fd);
+ rc = -ENOENT;
+ goto out;
+ }
+ else
+ /* TOCTOU non-problem: if another task races, puts a working
+ download or an empty file in its place, unlinking here just
+ means WE will try to download again as uncached. */
+ unlink(target_cache_path);
+ }
}
+ else if (errno == EACCES)
+ /* Ensure old 000-permission files are not lingering in the cache. */
+ unlink(target_cache_path);
long timeout = default_timeout;
const char* timeout_envvar = getenv(DEBUGINFOD_TIMEOUT_ENV_VAR);
}
} while (num_msg > 0);
- /* Create a 000-permission file named as $HOME/.cache if the query
- fails with ENOENT.*/
+ /* Create an empty file named as $HOME/.cache if the query fails
+ with ENOENT.*/
if (rc == -ENOENT)
{
- int efd = open (target_cache_path, O_CREAT|O_EXCL, 0000);
+ int efd = open (target_cache_path, O_CREAT|O_EXCL, DEFFILEMODE);
if (efd >= 0)
close(efd);
}
+2022-04-13 Aaron Merey <amerey@redhat.com>
+
+ * Makefile.am (TESTS): Remove run-debuginfod-000-permission.sh
+ and add run-debuginfod-negative-cache.sh.
+ (EXTRA_DIST): Likewise.
+ * run-debuginfod-federation-link.sh: Update comments about
+ negative-hit file.
+ * run-debuginfod-federation-metrics.sh: Likewise.
+ * run-debuginfod-federation-sqlite.sh: Likewise.
+ * run-debuginfod-tmp-home.sh: Likewise.
+
2022-03-20 Mark Wielaard <mark@klomp.org>
* run-large-elf-file.sh: Check elf class of addsections binary.
run-debuginfod-file.sh \
run-debuginfod-sizetime.sh \
run-debuginfod-malformed.sh \
- run-debuginfod-000-permission.sh \
+ run-debuginfod-negative-cache.sh \
run-debuginfod-tmp-home.sh \
run-debuginfod-writable.sh \
run-debuginfod-no-urls.sh \
run-debuginfod-sizetime.sh \
run-debuginfod-dlopen.sh \
run-debuginfod-malformed.sh \
- run-debuginfod-000-permission.sh \
+ run-debuginfod-negative-cache.sh \
run-debuginfod-tmp-home.sh \
run-debuginfod-writable.sh \
run-debuginfod-no-urls.sh \
export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
rm -rf $DEBUGINFOD_CACHE_PATH
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
-rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop 000-perm negative-hit file
+rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
export DEBUGINFOD_URLS=127.0.0.1:$PORT1
rm -rf $DEBUGINFOD_CACHE_PATH
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
-rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop 000-perm negative-hit file
+rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
export DEBUGINFOD_URLS=127.0.0.1:$PORT2
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
rm -rf $DEBUGINFOD_CACHE_PATH
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
-rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop 000-perm negative-hit file
+rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
export DEBUGINFOD_URLS=127.0.0.1:$PORT1
rm -rf $DEBUGINFOD_CACHE_PATH
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
-rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop 000-perm negative-hit file
+rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
export DEBUGINFOD_URLS=127.0.0.1:$PORT2
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
# test parallel queries in client
export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
rm -rf $DEBUGINFOD_CACHE_PATH
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
-rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop 000-perm negative-hit file
+rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
export DEBUGINFOD_URLS=127.0.0.1:$PORT1
rm -rf $DEBUGINFOD_CACHE_PATH
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
-rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop 000-perm negative-hit file
+rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
export DEBUGINFOD_URLS=127.0.0.1:$PORT2
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
# test parallel queries in client
# PR25628
rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
-# The query is designed to fail, while the 000-permission file should be created.
+# The query is designed to fail, while the empty file should be created.
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
if [ ! -f $DEBUGINFOD_CACHE_PATH/01234567/debuginfo ]; then
echo "could not find cache in $DEBUGINFOD_CACHE_PATH"
err
fi
-if [ `stat -c "%A" $DEBUGINFOD_CACHE_PATH/01234567/debuginfo` != "----------" ]; then
- echo "The cache $DEBUGINFOD_CACHE_PATH/01234567/debuginfo is readable"
+if [ `stat -c "%s" $DEBUGINFOD_CACHE_PATH/01234567/debuginfo` != 0 ]; then
+ echo "The cache $DEBUGINFOD_CACHE_PATH/01234567/debuginfo is not empty"
err
fi
# priority over $HOME/.cache, $XDG_CACHE_HOME.
cp -vr $DEBUGINFOD_CACHE_PATH tmphome/.debuginfod_client_cache || true
# ||true is for tolerating errors, such a valgrind or something else
-# leaving 000-perm files in there
+# leaving negative-hit files in there
# Add a file that doesn't exist in $HOME/.cache, $XDG_CACHE_HOME.
mkdir tmphome/.debuginfod_client_cache/deadbeef