]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysupdate: Factor some Target handling code out of sysupdated
authorPhilip Withnall <pwithnall@gnome.org>
Thu, 4 Jun 2026 15:06:15 +0000 (16:06 +0100)
committerPhilip Withnall <pwithnall@gnome.org>
Fri, 26 Jun 2026 12:01:18 +0000 (13:01 +0100)
This will be used in upcoming commits to varlinkify `systemd-sysupdate`;
it will need a way to identify targets over varlink, and the existing
way with a `Target` over D-Bus seems to work quite well.

src/sysupdate/meson.build
src/sysupdate/sysupdate-target.c [new file with mode: 0644]
src/sysupdate/sysupdate-target.h [new file with mode: 0644]
src/sysupdate/sysupdated.c

index ce1f4c14e753ac2ecad31434284847791b1cb51e..b6f94366065681979962bbfb1c78cfc59e1e824f 100644 (file)
@@ -8,6 +8,7 @@ systemd_sysupdate_sources = files(
         'sysupdate-partition.c',
         'sysupdate-pattern.c',
         'sysupdate-resource.c',
+        'sysupdate-target.c',
         'sysupdate-transfer.c',
         'sysupdate-update-set.c',
         'sysupdate.c',
@@ -37,7 +38,7 @@ executables += [
                 'name' : 'systemd-sysupdated',
                 'dbus' : true,
                 'conditions' : ['ENABLE_SYSUPDATED'],
-                'sources' : files('sysupdated.c'),
+                'sources' : files('sysupdated.c', 'sysupdate-target.c'),
         },
         executable_template + {
                 'name' : 'updatectl',
diff --git a/src/sysupdate/sysupdate-target.c b/src/sysupdate/sysupdate-target.c
new file mode 100644 (file)
index 0000000..ef13296
--- /dev/null
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "string-table.h"
+#include "sysupdate-target.h"
+
+static const char* const target_class_table[_TARGET_CLASS_MAX] = {
+        [TARGET_MACHINE]   = "machine",
+        [TARGET_PORTABLE]  = "portable",
+        [TARGET_SYSEXT]    = "sysext",
+        [TARGET_CONFEXT]   = "confext",
+        [TARGET_COMPONENT] = "component",
+        [TARGET_HOST]      = "host",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(target_class, TargetClass);
+
+void target_identifier_done(TargetIdentifier *t) {
+        assert(t);
+
+        t->class = _TARGET_CLASS_INVALID;
+        t->name = mfree(t->name);
+}
diff --git a/src/sysupdate/sysupdate-target.h b/src/sysupdate/sysupdate-target.h
new file mode 100644 (file)
index 0000000..9c0a13b
--- /dev/null
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include "os-util.h"
+
+typedef enum TargetClass {
+        /* These should try to match ImageClass from src/basic/os-util.h */
+        TARGET_MACHINE  = IMAGE_MACHINE,
+        TARGET_PORTABLE = IMAGE_PORTABLE,
+        TARGET_SYSEXT   = IMAGE_SYSEXT,
+        TARGET_CONFEXT  = IMAGE_CONFEXT,
+        _TARGET_CLASS_IS_IMAGE_CLASS_MAX,
+
+        /* sysupdate-specific classes */
+        TARGET_HOST = _TARGET_CLASS_IS_IMAGE_CLASS_MAX,
+        TARGET_COMPONENT,
+
+        _TARGET_CLASS_MAX,
+        _TARGET_CLASS_INVALID = -EINVAL,
+} TargetClass;
+
+/* Let's ensure when the number of classes is updated things are updated here too */
+assert_cc((int) _IMAGE_CLASS_MAX == (int) _TARGET_CLASS_IS_IMAGE_CLASS_MAX);
+
+DECLARE_STRING_TABLE_LOOKUP(target_class, TargetClass);
+
+typedef struct TargetIdentifier {
+        TargetClass class;
+        char *name;
+} TargetIdentifier;
+
+void target_identifier_done(TargetIdentifier *t);
index 359fb50b91657512a2eefea61aa9937e2c0635ea..8022fde77eb6ff075669a7ddc2e840f9414f1ffc 100644 (file)
@@ -40,6 +40,7 @@
 #include "signal-util.h"
 #include "string-table.h"
 #include "strv.h"
+#include "sysupdate-target.h"
 #include "sysupdate-util.h"
 #include "utf8.h"
 
@@ -64,25 +65,6 @@ typedef struct Manager {
 /* Forward declare so that jobs can call it on exit */
 static void manager_check_idle(Manager *m);
 
-typedef enum TargetClass {
-        /* These should try to match ImageClass from src/basic/os-util.h */
-        TARGET_MACHINE  = IMAGE_MACHINE,
-        TARGET_PORTABLE = IMAGE_PORTABLE,
-        TARGET_SYSEXT   = IMAGE_SYSEXT,
-        TARGET_CONFEXT  = IMAGE_CONFEXT,
-        _TARGET_CLASS_IS_IMAGE_CLASS_MAX,
-
-        /* sysupdate-specific classes */
-        TARGET_HOST = _TARGET_CLASS_IS_IMAGE_CLASS_MAX,
-        TARGET_COMPONENT,
-
-        _TARGET_CLASS_MAX,
-        _TARGET_CLASS_INVALID = -EINVAL,
-} TargetClass;
-
-/* Let's ensure when the number of classes is updated things are updated here too */
-assert_cc((int) _IMAGE_CLASS_MAX == (int) _TARGET_CLASS_IS_IMAGE_CLASS_MAX);
-
 typedef struct Target {
         Manager *manager;
 
@@ -138,17 +120,6 @@ struct Job {
         JobReady detach_cb; /* Callback called when job has started.  Detaches the job to run in the background */
 };
 
-static const char* const target_class_table[_TARGET_CLASS_MAX] = {
-        [TARGET_MACHINE]   = "machine",
-        [TARGET_PORTABLE]  = "portable",
-        [TARGET_SYSEXT]    = "sysext",
-        [TARGET_CONFEXT]   = "confext",
-        [TARGET_COMPONENT] = "component",
-        [TARGET_HOST]      = "host",
-};
-
-DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(target_class, TargetClass);
-
 static const char* const job_type_table[_JOB_TYPE_MAX] = {
         [JOB_LIST]             = "list",
         [JOB_DESCRIBE]         = "describe",