]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-remote: Allow building without microhttpd support
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 15 May 2025 11:23:54 +0000 (13:23 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 20 May 2025 08:29:58 +0000 (10:29 +0200)
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
src/journal-remote/journal-remote-main.c
src/journal-remote/meson.build
src/journal-remote/microhttpd-util.c
src/journal-remote/microhttpd-util.h

index 81e494ee0448462907a1ab91a5fcd9e0d94f99d2..83442da079a9ca7fb1d773ac12e5144e1526e7ca 100644 (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')
-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())
index e5ede19e03f748b969635ef3b0663d076c41db0a..2eb1e07f0eb76ee934f73e5ce5d2f224dd4c194d 100644 (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);
index 7916e9b31343120f6dd41b8f9dea9b6b5898ca9b..64cccd23554b7bf56428f84f2873ba93fec64c97 100644 (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],
         },
index 9f68cc65ca3e16cae69e3f1ff424971285affc34..4bf52ad200ba404b57cf606c19510070d48f93c1 100644 (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
index 57396ad9b6968cf57ca85c797fb99b18440052b1..ba466edcd64c8221fab860d98cbd0cc62b213e61 100644 (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