From 691abc5ea83c79ca27cda5a6f15ab151fef424c8 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Thu, 15 May 2025 13:23:54 +0200 Subject: [PATCH] journal-remote: Allow building without microhttpd support systemd-journal-remote is useful even if the microhttpd related features are not enabled so let's not skip it entirely if microhttpd is not available. --- meson.build | 22 +++++++++++----------- src/journal-remote/journal-remote-main.c | 19 +++++++++++++++++++ src/journal-remote/meson.build | 2 -- src/journal-remote/microhttpd-util.c | 4 ++++ src/journal-remote/microhttpd-util.h | 4 ++++ 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/meson.build b/meson.build index 81e494ee044..83442da079a 100644 --- a/meson.build +++ b/meson.build @@ -1569,17 +1569,17 @@ have = have and conf.get('HAVE_PAM') == 1 conf.set10('ENABLE_PAM_HOME', have) feature = get_option('remote') -have_deps = [conf.get('HAVE_MICROHTTPD') == 1, - conf.get('HAVE_LIBCURL') == 1] -# sd-j-remote requires µhttpd, and sd-j-upload requires libcurl, so -# it's possible to build one without the other. Complain only if -# support was explicitly requested. The auxiliary files like sysusers -# config should be installed when any of the programs are built. -if feature.enabled() and not (have_deps[0] and have_deps[1]) - error('remote support was requested, but dependencies are not available') -endif -have = feature.allowed() and (have_deps[0] or have_deps[1]) -conf.set10('ENABLE_REMOTE', have) +if feature.enabled() + if conf.get('HAVE_MICROHTTPD') != 1 + error('remote support was requested, but microhttpd is not available') + endif + if conf.get('HAVE_LIBCURL') != 1 + error('remote support was requested, but libcurl is not available') + endif +endif +# A more minimal version of systemd-journal-remote can always be built, even if neither +# libcurl nor microhttpd are available. +conf.set10('ENABLE_REMOTE', feature.allowed()) feature = get_option('vmspawn').disable_auto_if(conf.get('BUILD_MODE_DEVELOPER') == 0) conf.set10('ENABLE_VMSPAWN', feature.allowed()) diff --git a/src/journal-remote/journal-remote-main.c b/src/journal-remote/journal-remote-main.c index e5ede19e03f..2eb1e07f0eb 100644 --- a/src/journal-remote/journal-remote-main.c +++ b/src/journal-remote/journal-remote-main.c @@ -86,6 +86,8 @@ static const char* const journal_write_split_mode_table[_JOURNAL_WRITE_SPLIT_MAX DEFINE_PRIVATE_STRING_TABLE_LOOKUP(journal_write_split_mode, JournalWriteSplitMode); static DEFINE_CONFIG_PARSE_ENUM(config_parse_write_split_mode, journal_write_split_mode, JournalWriteSplitMode); +#if HAVE_MICROHTTPD + typedef struct MHDDaemonWrapper { uint64_t fd; struct MHD_Daemon *daemon; @@ -114,6 +116,8 @@ DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( uint64_t, uint64_hash_func, uint64_compare_func, MHDDaemonWrapper, MHDDaemonWrapper_free); +#endif + /********************************************************************** ********************************************************************** **********************************************************************/ @@ -184,6 +188,8 @@ static int spawn_getter(const char *getter) { ********************************************************************** **********************************************************************/ +#if HAVE_MICROHTTPD + static int null_timer_event_handler(sd_event_source *s, uint64_t usec, void *userdata); @@ -449,11 +455,15 @@ static mhd_result request_handler( return MHD_YES; } +#endif + static int setup_microhttpd_server(RemoteServer *s, int fd, const char *key, const char *cert, const char *trust) { + +#if HAVE_MICROHTTPD struct MHD_OptionItem opts[] = { { MHD_OPTION_EXTERNAL_LOGGER, (intptr_t) microhttpd_logger}, { MHD_OPTION_NOTIFY_COMPLETED, (intptr_t) request_meta_free}, @@ -564,6 +574,9 @@ static int setup_microhttpd_server(RemoteServer *s, TAKE_PTR(d); s->active++; return 0; +#else + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "microhttpd support not compiled in"); +#endif } static int setup_microhttpd_socket(RemoteServer *s, @@ -580,6 +593,8 @@ static int setup_microhttpd_socket(RemoteServer *s, return setup_microhttpd_server(s, fd, key, cert, trust); } +#if HAVE_MICROHTTPD + static int null_timer_event_handler(sd_event_source *timer_event, uint64_t usec, void *userdata) { @@ -615,6 +630,8 @@ static int dispatch_http_event(sd_event_source *event, return 1; /* work to do */ } +#endif + /********************************************************************** ********************************************************************** **********************************************************************/ @@ -1149,11 +1166,13 @@ static int run(int argc, char **argv) { journal_browse_prepare(); +#if HAVE_MICROHTTPD if (arg_listen_http || arg_listen_https) { r = setup_gnutls_logger(arg_gnutls_log); if (r < 0) return r; } +#endif if (arg_listen_https || https_socket >= 0) { r = load_certificates(&key, &cert, &trust); diff --git a/src/journal-remote/meson.build b/src/journal-remote/meson.build index 7916e9b3134..64cccd23554 100644 --- a/src/journal-remote/meson.build +++ b/src/journal-remote/meson.build @@ -52,7 +52,6 @@ executables += [ libexec_template + { 'name' : 'systemd-journal-remote', 'public' : true, - 'conditions' : ['HAVE_MICROHTTPD'], 'sources' : [systemd_journal_remote_sources, systemd_journal_remote_extract_sources], 'extract' : systemd_journal_remote_extract_sources, 'dependencies' : common_deps + [libmicrohttpd], @@ -71,7 +70,6 @@ executables += [ }, fuzz_template + { 'sources' : files('fuzz-journal-remote.c'), - 'conditions' : ['HAVE_MICROHTTPD'], 'objects' : ['systemd-journal-remote'], 'dependencies' : common_deps + [libmicrohttpd], }, diff --git a/src/journal-remote/microhttpd-util.c b/src/journal-remote/microhttpd-util.c index 9f68cc65ca3..4bf52ad200b 100644 --- a/src/journal-remote/microhttpd-util.c +++ b/src/journal-remote/microhttpd-util.c @@ -15,6 +15,8 @@ #include "string-util.h" #include "strv.h" +#if HAVE_MICROHTTPD + void microhttpd_logger(void *arg, const char *fmt, va_list ap) { char *f; @@ -297,3 +299,5 @@ int setup_gnutls_logger(char **categories) { return 0; } #endif + +#endif diff --git a/src/journal-remote/microhttpd-util.h b/src/journal-remote/microhttpd-util.h index 57396ad9b69..ba466edcd64 100644 --- a/src/journal-remote/microhttpd-util.h +++ b/src/journal-remote/microhttpd-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#if HAVE_MICROHTTPD + #include #include @@ -108,3 +110,5 @@ int setup_gnutls_logger(char **categories); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct MHD_Daemon*, MHD_stop_daemon, NULL); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct MHD_Response*, MHD_destroy_response, NULL); + +#endif -- 2.47.3