]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: move src/import/curl-util.h to src/shared/
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 31 Mar 2026 10:40:47 +0000 (12:40 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 15 Apr 2026 19:27:39 +0000 (21:27 +0200)
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.

src/imds/imdsd.c
src/imds/meson.build
src/import/meson.build
src/journal-remote/journal-upload.c
src/shared/curl-util.c [moved from src/import/curl-util.c with 100% similarity]
src/shared/curl-util.h [moved from src/import/curl-util.h with 69% similarity]
src/shared/meson.build

index c0ab08983035087122011db2727f94aaff4d308b..7831d1c68cb226d5f273faa4a9e03cab2c89b8ea 100644 (file)
@@ -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.:
  *
index f9fa9b5f0fb1a2ed074105f3c97a88f2f9e7b28d..cb919fec615d84b3f6bb5ae68cc321ff64f7fe0f 100644 (file)
@@ -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',
index a98604d4915b8eee019e3be210302a312d20732f..1fab9afd0b00596978e89b73b8b2b5780e20bf28 100644 (file)
@@ -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,
index e2038dd4b6e4e163966fb58751de67b7d0256f6b..88f5cf713985a550546057240b0293f6762ae254 100644 (file)
@@ -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,
similarity index 69%
rename from src/import/curl-util.h
rename to src/shared/curl-util.h
index b48eeb9c436820a2192170394c859bc66ac345f9..6b922d5003697c7735adbe19ec33d94a0486e3df 100644 (file)
@@ -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);
index 22dccf0e2a7dab0ccdfa6df044a59c7e6cd1680b..efa0dc05adf6aafd7534de6ea56a6a0763a45500 100644 (file)
@@ -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',