More verbose startup logging for mod_systemd. diff --git a/modules/arch/unix/mod_systemd.c b/modules/arch/unix/mod_systemd.c index 22482fd..b46d3ef 100644 --- a/modules/arch/unix/mod_systemd.c +++ b/modules/arch/unix/mod_systemd.c @@ -34,11 +34,14 @@ #endif #include "systemd/sd-daemon.h" +#include "systemd/sd-journal.h" #if APR_HAVE_UNISTD_H #include #endif +static char describe_listeners[30]; + static int systemd_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp) { @@ -63,6 +66,20 @@ static void log_selinux_context(void) } #endif +static char *dump_listener(ap_listen_rec *lr, apr_pool_t *p) +{ + apr_sockaddr_t *sa = lr->bind_addr; + char addr[128]; + + if (apr_sockaddr_is_wildcard(sa)) { + return apr_pstrcat(p, "port ", apr_itoa(p, sa->port), NULL); + } + + apr_sockaddr_ip_getbuf(addr, sizeof addr, sa); + + return apr_psprintf(p, "%s port %u", addr, sa->port); +} + /* Report the service is ready in post_config, which could be during * startup or after a reload. The server could still hit a fatal * startup error after this point during ap_run_mpm(), so this is @@ -73,23 +90,52 @@ static void log_selinux_context(void) static int systemd_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_server) { + ap_listen_rec *lr; + apr_size_t plen = sizeof describe_listeners; + char *p = describe_listeners; + if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG) return OK; + for (lr = ap_listeners; lr; lr = lr->next) { + char *s = dump_listener(lr, ptemp); + + if (strlen(s) + 3 < plen) { + char *newp = apr_cpystrn(p, s, plen); + if (lr->next) + newp = apr_cpystrn(newp, ", ", 3); + plen -= newp - p; + p = newp; + } + else { + if (plen < 4) { + p = describe_listeners + sizeof describe_listeners - 4; + plen = 4; + } + apr_cpystrn(p, "...", plen); + break; + } + } + #ifdef HAVE_SELINUX log_selinux_context(); #endif sd_notify(0, "READY=1\n" "STATUS=Configuration loaded.\n"); + + sd_journal_print(LOG_INFO, "Server configured, listening on: %s", + describe_listeners); + return OK; } static int systemd_pre_mpm(apr_pool_t *p, ap_scoreboard_e sb_type) { sd_notifyf(0, "READY=1\n" - "STATUS=Processing requests...\n" - "MAINPID=%" APR_PID_T_FMT, getpid()); + "STATUS=Started, listening on: %s\n" + "MAINPID=%" APR_PID_T_FMT, + describe_listeners, getpid()); return OK; }