Hi Martin,
On Thu, Dec 4, 2025 at 8:26 AM Martin Cermak <[email protected]> wrote:
>
> I'm attaching patch for PR33635. Please review and consider merging.
Overall the patch looks good. I have a couple small comments but
please go ahead and merge the patch once you've addressed them.
> static struct MHD_Response*
> handle_root (off_t* size)
> {
> + MHD_Response* r;
> + if (cust_homepage_file != "")
> + try
> + {
> + int fd = open (cust_homepage_file.c_str(), O_RDONLY);
> + if (fd != -1) {
> + struct stat buf;
> + stat (cust_homepage_file.c_str(), &buf);
> + r = MHD_create_response_from_fd(buf.st_size, fd);
> + // NB: MHD owns and handles the fd from now. Must not close()!
> + if (r != NULL)
> + add_mhd_response_header (r, "Content-Type", "text/html");
> + } else {
> + throw libc_exception (errno, "cannot open file " +
> cust_homepage_file);
> + }
> + return r;
*size isn't set when r successfully returns here.
> + }
> + catch (const reportable_exception& e)
> + {
> + e.report(clog);
> + }
> --- /dev/null
> +++ b/tests/run-debuginfod-homesite.sh
> @@ -0,0 +1,68 @@
> +#!/usr/bin/env bash
> +#
> +# Copyright (C) 2022 Red Hat, Inc.
> +# This file is part of elfutils.
> +#
> +# This file is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# elfutils 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 General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +type socat 2>/dev/null || exit 77
> +
> +. $srcdir/debuginfod-subr.sh # includes set -e
> +
> +# for test case debugging, uncomment:
> +set -x
set should be commented out.
> +
> +# This variable is essential and ensures no time-race for claiming ports
> occurs
> +# set base to a unique multiple of 100 not used in any other
> 'run-debuginfod-*' test
> +base=10200
> +get_ports
> +
> +tempfiles vlog$PORT1
> +errfiles vlog$PORT1
> +
> +# Test 1: Make sure attempt to open non-existent --home-html is handled
> gracefully
> +rurl="https://sourceware.org/elfutils/Debuginfod.html"
> +env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS=
> ${abs_builddir}/../debuginfod/debuginfod \
> + $VERBOSE -p $PORT1 --home-html=non-existent.html --home-redirect=$rurl >
> vlog$PORT1 2>&1 &
> +PID1=$!
> +# Server must become ready
> +wait_ready $PORT1 'ready' 1
> +echo -e 'GET / HTTP/1.1\nHost: localhost\n' | socat - TCP:127.0.0.1:$PORT1 >
> response.txt
> +tempfiles response.txt
> +# If non-existent --home-html is passed, server should only send headers
> +# incl. the --home-redirect in this case ...
> +grep -F "Location: $rurl" response.txt
> +# ... followed by the version id.
> +tail -1 response.txt | grep -F 'debuginfod' response.txt
I'm not sure if this affects the outcome of the test but `grep -F
'debuginfod' response.txt` will ignore the output of tail that you're
trying to pipe due to the presence of `response.txt` in the grep
command.
Aaron