From: Zbigniew Jędrzejewski-Szmek Date: Tue, 31 Mar 2026 10:40:47 +0000 (+0200) Subject: shared: move src/import/curl-util.h to src/shared/ X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cdc8aadaed7bf0bb8721a0eda5817e5c88a1b48b;p=thirdparty%2Fsystemd.git shared: move src/import/curl-util.h to src/shared/ Move more common definitions in the header file instead of repeating them in bunch of places. src/import/curl-util.[ch] is renamed so that it's shared more naturally with other components. --- diff --git a/src/imds/imdsd.c b/src/imds/imdsd.c index c0ab0898303..7831d1c68cb 100644 --- a/src/imds/imdsd.c +++ b/src/imds/imdsd.c @@ -18,6 +18,7 @@ #include "chase.h" #include "copy.h" #include "creds-util.h" +#include "curl-util.h" #include "device-private.h" #include "dns-rr.h" #include "errno-util.h" @@ -53,8 +54,6 @@ #include "web-util.h" #include "xattr-util.h" -#include "../import/curl-util.h" - /* This implements a client to the AWS' and Azure's "Instance Metadata Service", as well as GCP's "VM * Metadata", i.e.: * diff --git a/src/imds/meson.build b/src/imds/meson.build index f9fa9b5f0fb..cb919fec615 100644 --- a/src/imds/meson.build +++ b/src/imds/meson.build @@ -11,8 +11,8 @@ executables += [ 'sources' : files( 'imdsd.c', 'imds-util.c' - ) + import_curl_util_c, - 'dependencies' : [ libcurl ], + ) + curl_util_c, + 'dependencies' : [libcurl], }, libexec_template + { 'name' : 'systemd-imds', diff --git a/src/import/meson.build b/src/import/meson.build index a98604d4915..1fab9afd0b0 100644 --- a/src/import/meson.build +++ b/src/import/meson.build @@ -1,7 +1,5 @@ # SPDX-License-Identifier: LGPL-2.1-or-later -import_curl_util_c = files('curl-util.c') - if conf.get('ENABLE_IMPORTD') != 1 subdir_done() endif @@ -35,7 +33,7 @@ executables += [ 'pull-oci.c', 'pull-raw.c', 'pull-tar.c', - ) + import_curl_util_c, + ) + curl_util_c, 'objects' : ['systemd-importd'], 'dependencies' : common_deps + [ libopenssl, diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index e2038dd4b6e..88f5cf71398 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -11,6 +11,7 @@ #include "alloc-util.h" #include "build.h" #include "conf-parser.h" +#include "curl-util.h" #include "daemon-util.h" #include "env-file.h" #include "extract-word.h" @@ -81,18 +82,6 @@ static void close_fd_input(Uploader *u); #define STATE_FILE "/var/lib/systemd/journal-upload/state" -#define easy_setopt(curl, log_level, opt, value) ({ \ - CURLcode code = curl_easy_setopt(ASSERT_PTR(curl), opt, value); \ - if (code) \ - log_full(log_level, \ - "curl_easy_setopt %s failed: %s", \ - #opt, curl_easy_strerror(code)); \ - !code; \ -}) - -DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(CURL*, curl_easy_cleanup, NULL); -DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct curl_slist*, curl_slist_free_all, NULL); - static size_t output_callback(char *buf, size_t size, size_t nmemb, diff --git a/src/import/curl-util.c b/src/shared/curl-util.c similarity index 100% rename from src/import/curl-util.c rename to src/shared/curl-util.c diff --git a/src/import/curl-util.h b/src/shared/curl-util.h similarity index 69% rename from src/import/curl-util.h rename to src/shared/curl-util.h index b48eeb9c436..6b922d50036 100644 --- a/src/import/curl-util.h +++ b/src/shared/curl-util.h @@ -5,6 +5,19 @@ #include "shared-forward.h" +#define easy_setopt(curl, log_level, opt, value) ({ \ + CURLcode code = curl_easy_setopt(ASSERT_PTR(curl), opt, value); \ + if (code) \ + log_full(log_level, \ + "curl_easy_setopt %s failed: %s", \ + #opt, curl_easy_strerror(code)); \ + code == CURLE_OK; \ +}) + +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(CURL*, curl_easy_cleanup, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(CURLM*, curl_multi_cleanup, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct curl_slist*, curl_slist_free_all, NULL); + typedef struct CurlGlue CurlGlue; typedef struct CurlGlue { @@ -30,7 +43,3 @@ void curl_glue_remove_and_free(CurlGlue *g, CURL *c); struct curl_slist *curl_slist_new(const char *first, ...) _sentinel_; int curl_header_strdup(const void *contents, size_t sz, const char *field, char **value); int curl_parse_http_time(const char *t, usec_t *ret); - -DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(CURL*, curl_easy_cleanup, NULL); -DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(CURLM*, curl_multi_cleanup, NULL); -DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct curl_slist*, curl_slist_free_all, NULL); diff --git a/src/shared/meson.build b/src/shared/meson.build index 22dccf0e2a7..efa0dc05adf 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -256,6 +256,9 @@ if get_option('tests') != 'false' shared_sources += files('tests.c') endif +# A small shared file that is is linked into a few places +curl_util_c = files('curl-util.c') + syscall_list_inc = custom_target( input : syscall_list_txt, output : 'syscall-list.inc',