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.
This commit is contained in:
Daan De Meyer
2025-05-15 13:23:54 +02:00
parent 791847ea64
commit 691abc5ea8
5 changed files with 37 additions and 12 deletions

View File

@@ -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')
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
have = feature.allowed() and (have_deps[0] or have_deps[1])
conf.set10('ENABLE_REMOTE', have)
# 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())

View File

@@ -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);

View File

@@ -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],
},

View File

@@ -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

View File

@@ -1,6 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#if HAVE_MICROHTTPD
#include <microhttpd.h>
#include <stdarg.h>
@@ -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