Skip to content

Commit 7d05974

Browse files
pks-tgitster
authored andcommitted
t/lib-httpd: dynamically detect httpd and modules path
In order to set up the Apache httpd server, we need to locate both the httpd binary and its default module path. This is done with a hardcoded list of locations that we scan. While this works okayish with distros that more-or-less follow the Filesystem Hierarchy Standard, it falls apart on others like NixOS that don't. While it is possible to specify these paths via `LIB_HTTPD_PATH` and `LIB_HTTPD_MODULE_PATH`, it is not a nice experience for the developer to figure out how to set those up. And in fact we can do better by dynamically detecting both httpd and its module path at runtime: - The httpd binary can be located via PATH. - The module directory can (in many cases) be derived via the `HTTPD_ROOT` compile-time variable. Amend the code to do so. Note that the new runtime-detected paths will only be used as a fallback in case none of the hardcoded paths are usable. For the PATH lookup this is because httpd is typically installed into "/usr/sbin", which is often not included in the user's PATH variable. And the module path detection relies on a configured httpd installation and may thus not work in all cases, either. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dadef80 commit 7d05974

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

t/lib-httpd.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,30 @@ fi
5555

5656
HTTPD_PARA=""
5757

58-
for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' '/usr/sbin/apache2'
58+
for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' \
59+
'/usr/sbin/apache2' \
60+
"$(command -v httpd)" \
61+
"$(command -v apache2)"
5962
do
60-
if test -x "$DEFAULT_HTTPD_PATH"
63+
if test -n "$DEFAULT_HTTPD_PATH" && test -x "$DEFAULT_HTTPD_PATH"
6164
then
6265
break
6366
fi
6467
done
6568

69+
if test -x "$DEFAULT_HTTPD_PATH"
70+
then
71+
DETECTED_HTTPD_ROOT="$("$DEFAULT_HTTPD_PATH" -V 2>/dev/null | sed -n 's/^ -D HTTPD_ROOT="\(.*\)"$/\1/p')"
72+
fi
73+
6674
for DEFAULT_HTTPD_MODULE_PATH in '/usr/libexec/apache2' \
6775
'/usr/lib/apache2/modules' \
6876
'/usr/lib64/httpd/modules' \
6977
'/usr/lib/httpd/modules' \
70-
'/usr/libexec/httpd'
78+
'/usr/libexec/httpd' \
79+
"${DETECTED_HTTPD_ROOT:+${DETECTED_HTTPD_ROOT}/modules}"
7180
do
72-
if test -d "$DEFAULT_HTTPD_MODULE_PATH"
81+
if test -n "$DEFAULT_HTTPD_MODULE_PATH" && test -d "$DEFAULT_HTTPD_MODULE_PATH"
7382
then
7483
break
7584
fi

0 commit comments

Comments
 (0)