diff options
author | Joe Orton <jorton@apache.org> | 2022-04-12 17:43:04 +0200 |
---|---|---|
committer | Joe Orton <jorton@apache.org> | 2022-04-12 17:43:04 +0200 |
commit | db0631ed09566c81d651b4a51401ea0d61b1e986 (patch) | |
tree | a4bba0ba7e30cbf3a9de152c861db20637d25445 /modules/arch | |
parent | mpm_event: Fix accounting of active/total processes on ungraceful restart. (diff) | |
download | apache2-db0631ed09566c81d651b4a51401ea0d61b1e986.tar.xz apache2-db0631ed09566c81d651b4a51401ea0d61b1e986.zip |
Remove libsystemd dependency from main httpd binary
Until this change httpd was linking libsystemd to the main httpd binary. If you want to run lightweight version of httpd in container, sometimes you just want to install
httpd binary with as little dependencies as possible to make container small in size and do not pull uncencessary dependencies and libraries.
This change will move all systemd library calls from listen.c to mod_systemd module and remove systemd linking from the main httpd bin.
Fixed mixed declaration and wrongly declared variable.
Submitted by: Luboš Uhliarik <luhliari redhat.com>
Github: closes #312
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1899784 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules/arch')
-rw-r--r-- | modules/arch/unix/mod_systemd.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/modules/arch/unix/mod_systemd.c b/modules/arch/unix/mod_systemd.c index c3e7082df1..6439a5c8ef 100644 --- a/modules/arch/unix/mod_systemd.c +++ b/modules/arch/unix/mod_systemd.c @@ -34,6 +34,12 @@ #include <unistd.h> #endif +APR_DECLARE_OPTIONAL_FN(int, + ap_find_systemd_socket, (process_rec *, apr_port_t)); + +APR_DECLARE_OPTIONAL_FN(int, + ap_systemd_listen_fds, (int)); + static int systemd_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp) { @@ -96,8 +102,42 @@ static int systemd_monitor(apr_pool_t *p, server_rec *s) return DECLINED; } +static int ap_find_systemd_socket(process_rec * process, apr_port_t port) { + int fdcount, fd; + int sdc = sd_listen_fds(0); + + if (sdc < 0) { + ap_log_perror(APLOG_MARK, APLOG_CRIT, sdc, process->pool, APLOGNO(02486) + "find_systemd_socket: Error parsing enviroment, sd_listen_fds returned %d", + sdc); + return -1; + } + + if (sdc == 0) { + ap_log_perror(APLOG_MARK, APLOG_CRIT, sdc, process->pool, APLOGNO(02487) + "find_systemd_socket: At least one socket must be set."); + return -1; + } + + fdcount = atoi(getenv("LISTEN_FDS")); + for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + fdcount; fd++) { + if (sd_is_socket_inet(fd, 0, 0, -1, port) > 0) { + return fd; + } + } + + return -1; +} + +static int ap_systemd_listen_fds(int unset_environment){ + return sd_listen_fds(unset_environment); +} + static void systemd_register_hooks(apr_pool_t *p) { + APR_REGISTER_OPTIONAL_FN(ap_systemd_listen_fds); + APR_REGISTER_OPTIONAL_FN(ap_find_systemd_socket); + /* Enable ap_extended_status. */ ap_hook_pre_config(systemd_pre_config, NULL, NULL, APR_HOOK_LAST); /* Signal service is ready. */ |