d9ddc5d
diff --git a/acinclude.m4 b/acinclude.m4
d9ddc5d
index 05abe18..97484c9 100644
d9ddc5d
--- a/acinclude.m4
d9ddc5d
+++ b/acinclude.m4
d9ddc5d
@@ -631,7 +631,6 @@ case $host in
d9ddc5d
       if test "${ac_cv_header_systemd_sd_daemon_h}" = "no" || test -z "${SYSTEMD_LIBS}"; then
d9ddc5d
         AC_MSG_WARN([Your system does not support systemd.])
d9ddc5d
       else
d9ddc5d
-        APR_ADDTO(HTTPD_LIBS, [$SYSTEMD_LIBS])
d9ddc5d
         AC_DEFINE(HAVE_SYSTEMD, 1, [Define if systemd is supported])
d9ddc5d
       fi
d9ddc5d
    fi
72f0748
diff --git a/include/ap_listen.h b/include/ap_listen.h
72f0748
index 58c2574..d5ed968 100644
72f0748
--- a/include/ap_listen.h
72f0748
+++ b/include/ap_listen.h
72f0748
@@ -29,6 +29,7 @@
72f0748
 #include "apr_network_io.h"
72f0748
 #include "httpd.h"
72f0748
 #include "http_config.h"
72f0748
+#include "apr_optional.h"
72f0748
 
72f0748
 #ifdef __cplusplus
72f0748
 extern "C" {
72f0748
@@ -143,6 +144,15 @@ AP_DECLARE_NONSTD(const char *) ap_set_receive_buffer_size(cmd_parms *cmd,
72f0748
                                                            void *dummy,
72f0748
                                                            const char *arg);
72f0748
 
72f0748
+#ifdef HAVE_SYSTEMD
72f0748
+APR_DECLARE_OPTIONAL_FN(int,
72f0748
+                        ap_find_systemd_socket, (process_rec *, apr_port_t));
72f0748
+
72f0748
+APR_DECLARE_OPTIONAL_FN(int,
72f0748
+                        ap_systemd_listen_fds, (int));
72f0748
+#endif
72f0748
+
72f0748
+
72f0748
 #define LISTEN_COMMANDS \
72f0748
 AP_INIT_TAKE1("ListenBacklog", ap_set_listenbacklog, NULL, RSRC_CONF, \
72f0748
   "Maximum length of the queue of pending connections, as used by listen(2)"), \
d9ddc5d
diff --git a/modules/arch/unix/mod_systemd.c b/modules/arch/unix/mod_systemd.c
d9ddc5d
index eda1272..fc059fc 100644
d9ddc5d
--- a/modules/arch/unix/mod_systemd.c
d9ddc5d
+++ b/modules/arch/unix/mod_systemd.c
d9ddc5d
@@ -35,6 +35,15 @@
d9ddc5d
 #include <unistd.h>
d9ddc5d
 #endif
d9ddc5d
 
d9ddc5d
+APR_DECLARE_OPTIONAL_FN(int,
d9ddc5d
+                        ap_find_systemd_socket, (process_rec *, apr_port_t));
d9ddc5d
+
d9ddc5d
+APR_DECLARE_OPTIONAL_FN(int,
d9ddc5d
+                        ap_systemd_listen_fds, (int));
d9ddc5d
+
d9ddc5d
+APR_DECLARE_OPTIONAL_FN(int,
d9ddc5d
+                        ap_systemd_journal_stream_fd, (const char *, int, int));
d9ddc5d
+
d9ddc5d
 static char describe_listeners[30];
d9ddc5d
 
d9ddc5d
 static int systemd_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
d9ddc5d
@@ -145,8 +154,47 @@ static int systemd_monitor(apr_pool_t *p, server_rec *s)
d9ddc5d
     return DECLINED;
d9ddc5d
 }
d9ddc5d
 
d9ddc5d
+static int ap_find_systemd_socket(process_rec * process, apr_port_t port) {
d9ddc5d
+    int fdcount, fd;
d9ddc5d
+    int sdc = sd_listen_fds(0);
d9ddc5d
+
d9ddc5d
+    if (sdc < 0) {
d9ddc5d
+        ap_log_perror(APLOG_MARK, APLOG_CRIT, sdc, process->pool, APLOGNO(02486)
d9ddc5d
+                      "find_systemd_socket: Error parsing enviroment, sd_listen_fds returned %d",
d9ddc5d
+                      sdc);
d9ddc5d
+        return -1;
d9ddc5d
+    }
d9ddc5d
+
d9ddc5d
+    if (sdc == 0) {
d9ddc5d
+        ap_log_perror(APLOG_MARK, APLOG_CRIT, sdc, process->pool, APLOGNO(02487)
d9ddc5d
+                      "find_systemd_socket: At least one socket must be set.");
d9ddc5d
+        return -1;
d9ddc5d
+    }
d9ddc5d
+
d9ddc5d
+    fdcount = atoi(getenv("LISTEN_FDS"));
d9ddc5d
+    for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + fdcount; fd++) {
d9ddc5d
+        if (sd_is_socket_inet(fd, 0, 0, -1, port) > 0) {
d9ddc5d
+            return fd;
d9ddc5d
+        }
d9ddc5d
+    }
d9ddc5d
+
d9ddc5d
+    return -1;
d9ddc5d
+}
d9ddc5d
+
d9ddc5d
+static int ap_systemd_listen_fds(int unset_environment){
d9ddc5d
+    return sd_listen_fds(unset_environment);
d9ddc5d
+}
d9ddc5d
+
d9ddc5d
+static int ap_systemd_journal_stream_fd(const char *identifier, int priority, int level_prefix){
d9ddc5d
+    return sd_journal_stream_fd("httpd", priority, 0);
d9ddc5d
+}
d9ddc5d
+
d9ddc5d
 static void systemd_register_hooks(apr_pool_t *p)
d9ddc5d
 {
d9ddc5d
+    APR_REGISTER_OPTIONAL_FN(ap_systemd_listen_fds);
d9ddc5d
+    APR_REGISTER_OPTIONAL_FN(ap_find_systemd_socket);
d9ddc5d
+    APR_REGISTER_OPTIONAL_FN(ap_systemd_journal_stream_fd);
d9ddc5d
+
d9ddc5d
     /* Enable ap_extended_status. */
d9ddc5d
     ap_hook_pre_config(systemd_pre_config, NULL, NULL, APR_HOOK_LAST);
d9ddc5d
     /* Signal service is ready. */
d9ddc5d
diff --git a/modules/loggers/config.m4 b/modules/loggers/config.m4
d9ddc5d
index 0848d2e..8af2299 100644
d9ddc5d
--- a/modules/loggers/config.m4
d9ddc5d
+++ b/modules/loggers/config.m4
d9ddc5d
@@ -5,7 +5,6 @@ dnl APACHE_MODULE(name, helptext[, objects[, structname[, default[, config]]]])
d9ddc5d
 APACHE_MODPATH_INIT(loggers)
d9ddc5d
 	
d9ddc5d
 APACHE_MODULE(log_config, logging configuration.  You won't be able to log requests to the server without this module., , , yes)
d9ddc5d
-APR_ADDTO(MOD_LOG_CONFIG_LDADD, [$SYSTEMD_LIBS])
d9ddc5d
 
d9ddc5d
 APACHE_MODULE(log_debug, configurable debug logging, , , most)
d9ddc5d
 APACHE_MODULE(log_forensic, forensic logging)
d9ddc5d
diff --git a/modules/loggers/mod_log_config.c b/modules/loggers/mod_log_config.c
72f0748
index 0b11f60..c3f0a51 100644
d9ddc5d
--- a/modules/loggers/mod_log_config.c
d9ddc5d
+++ b/modules/loggers/mod_log_config.c
72f0748
@@ -172,10 +172,6 @@
d9ddc5d
 #include <limits.h>
d9ddc5d
 #endif
d9ddc5d
 
d9ddc5d
-#ifdef HAVE_SYSTEMD
d9ddc5d
-#include <systemd/sd-journal.h>
d9ddc5d
-#endif
d9ddc5d
-
d9ddc5d
 #define DEFAULT_LOG_FORMAT "%h %l %u %t \"%r\" %>s %b"
d9ddc5d
 
d9ddc5d
 module AP_MODULE_DECLARE_DATA log_config_module;
72f0748
@@ -1640,8 +1636,15 @@ static apr_status_t wrap_journal_stream(apr_pool_t *p, apr_file_t **outfd,
d9ddc5d
 {
d9ddc5d
 #ifdef HAVE_SYSTEMD
d9ddc5d
     int fd;
d9ddc5d
+    APR_OPTIONAL_FN_TYPE(ap_systemd_journal_stream_fd) *systemd_journal_stream_fd;
d9ddc5d
+    
d9ddc5d
+    systemd_journal_stream_fd = APR_RETRIEVE_OPTIONAL_FN(ap_systemd_journal_stream_fd);
d9ddc5d
+    if (systemd_journal_stream_fd == NULL) {
d9ddc5d
+        return APR_ENOTIMPL;
d9ddc5d
+    }
d9ddc5d
 
d9ddc5d
-    fd = sd_journal_stream_fd("httpd", priority, 0);
d9ddc5d
+    fd = systemd_journal_stream_fd("httpd", priority, 0);
d9ddc5d
+    
d9ddc5d
     if (fd < 0) return fd;
d9ddc5d
 
d9ddc5d
     /* This is an AF_UNIX socket fd so is more pipe-like than
72f0748
diff --git a/modules/loggers/mod_log_config.h b/modules/loggers/mod_log_config.h
72f0748
index 877a593..bd52a98 100644
72f0748
--- a/modules/loggers/mod_log_config.h
72f0748
+++ b/modules/loggers/mod_log_config.h
72f0748
@@ -69,6 +69,10 @@ APR_DECLARE_OPTIONAL_FN(ap_log_writer_init*, ap_log_set_writer_init,(ap_log_writ
72f0748
  */
72f0748
 APR_DECLARE_OPTIONAL_FN(ap_log_writer*, ap_log_set_writer, (ap_log_writer* func));
72f0748
 
72f0748
+#ifdef HAVE_SYSTEMD
72f0748
+APR_DECLARE_OPTIONAL_FN(int, ap_systemd_journal_stream_fd, (const char *, int, int));
72f0748
+#endif
72f0748
+
72f0748
 #endif /* MOD_LOG_CONFIG */
72f0748
 /** @} */
72f0748
 
d9ddc5d
diff --git a/server/listen.c b/server/listen.c
ee221cb
index e2e028a..5d1c0e1 100644
d9ddc5d
--- a/server/listen.c
d9ddc5d
+++ b/server/listen.c
d9ddc5d
@@ -34,10 +34,6 @@
d9ddc5d
 #include <unistd.h>
d9ddc5d
 #endif
d9ddc5d
 
d9ddc5d
-#ifdef HAVE_SYSTEMD
d9ddc5d
-#include <systemd/sd-daemon.h>
d9ddc5d
-#endif
d9ddc5d
-
d9ddc5d
 /* we know core's module_index is 0 */
d9ddc5d
 #undef APLOG_MODULE_INDEX
d9ddc5d
 #define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
72f0748
@@ -325,34 +321,6 @@ static int find_listeners(ap_listen_rec **from, ap_listen_rec **to,
d9ddc5d
 }
d9ddc5d
 
d9ddc5d
 #ifdef HAVE_SYSTEMD
d9ddc5d
-
d9ddc5d
-static int find_systemd_socket(process_rec * process, apr_port_t port) {
d9ddc5d
-    int fdcount, fd;
d9ddc5d
-    int sdc = sd_listen_fds(0);
d9ddc5d
-
d9ddc5d
-    if (sdc < 0) {
d9ddc5d
-        ap_log_perror(APLOG_MARK, APLOG_CRIT, sdc, process->pool, APLOGNO(02486)
d9ddc5d
-                      "find_systemd_socket: Error parsing enviroment, sd_listen_fds returned %d",
d9ddc5d
-                      sdc);
d9ddc5d
-        return -1;
d9ddc5d
-    }
d9ddc5d
-
d9ddc5d
-    if (sdc == 0) {
d9ddc5d
-        ap_log_perror(APLOG_MARK, APLOG_CRIT, sdc, process->pool, APLOGNO(02487)
d9ddc5d
-                      "find_systemd_socket: At least one socket must be set.");
d9ddc5d
-        return -1;
d9ddc5d
-    }
d9ddc5d
-
d9ddc5d
-    fdcount = atoi(getenv("LISTEN_FDS"));
d9ddc5d
-    for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + fdcount; fd++) {
d9ddc5d
-        if (sd_is_socket_inet(fd, 0, 0, -1, port) > 0) {
d9ddc5d
-            return fd;
d9ddc5d
-        }
d9ddc5d
-    }
d9ddc5d
-
d9ddc5d
-    return -1;
d9ddc5d
-}
d9ddc5d
-
d9ddc5d
 static apr_status_t alloc_systemd_listener(process_rec * process,
d9ddc5d
                                            int fd, const char *proto,
d9ddc5d
                                            ap_listen_rec **out_rec)
72f0748
@@ -412,6 +380,14 @@ static const char *set_systemd_listener(process_rec *process, apr_port_t port,
d9ddc5d
 {
d9ddc5d
     ap_listen_rec *last, *new;
d9ddc5d
     apr_status_t rv;
d9ddc5d
+    APR_OPTIONAL_FN_TYPE(ap_find_systemd_socket) *find_systemd_socket;
d9ddc5d
+
d9ddc5d
+    find_systemd_socket = APR_RETRIEVE_OPTIONAL_FN(ap_find_systemd_socket);
d9ddc5d
+
d9ddc5d
+    if (!find_systemd_socket)
ee221cb
+       return "Systemd socket activation is used, but mod_systemd is probably "
d9ddc5d
+               "not loaded";
d9ddc5d
+
d9ddc5d
     int fd = find_systemd_socket(process, port);
d9ddc5d
     if (fd < 0) {
d9ddc5d
         return "Systemd socket activation is used, but this port is not "
72f0748
@@ -438,7 +414,6 @@ static const char *set_systemd_listener(process_rec *process, apr_port_t port,
d9ddc5d
 
d9ddc5d
     return NULL;
d9ddc5d
 }
d9ddc5d
-
d9ddc5d
 #endif /* HAVE_SYSTEMD */
d9ddc5d
 
d9ddc5d
 static const char *alloc_listener(process_rec *process, const char *addr,
72f0748
@@ -707,6 +682,9 @@ AP_DECLARE(int) ap_setup_listeners(server_rec *s)
d9ddc5d
     int num_listeners = 0;
d9ddc5d
     const char* proto;
d9ddc5d
     int found;
d9ddc5d
+#ifdef HAVE_SYSTEMD
d9ddc5d
+    APR_OPTIONAL_FN_TYPE(ap_systemd_listen_fds) *systemd_listen_fds;
d9ddc5d
+#endif
d9ddc5d
 
d9ddc5d
     for (ls = s; ls; ls = ls->next) {
d9ddc5d
         proto = ap_get_server_protocol(ls);
72f0748
@@ -746,7 +724,10 @@ AP_DECLARE(int) ap_setup_listeners(server_rec *s)
d9ddc5d
                                 apr_pool_cleanup_null, s->process->pool);
d9ddc5d
         }
d9ddc5d
         else {
d9ddc5d
-            sd_listen_fds(1);
d9ddc5d
+            systemd_listen_fds = APR_RETRIEVE_OPTIONAL_FN(ap_systemd_listen_fds);
d9ddc5d
+            if (systemd_listen_fds != NULL) {
d9ddc5d
+                systemd_listen_fds(1);
d9ddc5d
+            }
d9ddc5d
         }
d9ddc5d
     }
d9ddc5d
     else
72f0748
@@ -963,6 +944,9 @@ AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy,
d9ddc5d
     apr_port_t port;
d9ddc5d
     apr_status_t rv;
d9ddc5d
     const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
d9ddc5d
+#ifdef HAVE_SYSTEMD
d9ddc5d
+    APR_OPTIONAL_FN_TYPE(ap_systemd_listen_fds) *systemd_listen_fds;
d9ddc5d
+#endif
d9ddc5d
 
d9ddc5d
     if (err != NULL) {
d9ddc5d
         return err;
ee221cb
@@ -973,7 +957,12 @@ AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy,
d9ddc5d
     }
d9ddc5d
 #ifdef HAVE_SYSTEMD
d9ddc5d
     if (use_systemd == -1) {
d9ddc5d
-        use_systemd = sd_listen_fds(0) > 0;
d9ddc5d
+        systemd_listen_fds = APR_RETRIEVE_OPTIONAL_FN(ap_systemd_listen_fds);
d9ddc5d
+        if (systemd_listen_fds != NULL) {
d9ddc5d
+            use_systemd = systemd_listen_fds(0) > 0;
ee221cb
+        } else {
ee221cb
+            use_systemd = 0;
d9ddc5d
+        }
d9ddc5d
     }
d9ddc5d
 #endif
d9ddc5d