From: Philip Withnall Date: Thu, 4 Jun 2026 15:06:15 +0000 (+0100) Subject: sysupdate: Factor some Target handling code out of sysupdated X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28b9b5712ae80e11b17ae8d616ffbbea741b0c33;p=thirdparty%2Fsystemd.git sysupdate: Factor some Target handling code out of sysupdated 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. --- diff --git a/src/sysupdate/meson.build b/src/sysupdate/meson.build index ce1f4c14e75..b6f94366065 100644 --- a/src/sysupdate/meson.build +++ b/src/sysupdate/meson.build @@ -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 index 00000000000..ef132960f33 --- /dev/null +++ b/src/sysupdate/sysupdate-target.c @@ -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 index 00000000000..9c0a13bf4ad --- /dev/null +++ b/src/sysupdate/sysupdate-target.h @@ -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); diff --git a/src/sysupdate/sysupdated.c b/src/sysupdate/sysupdated.c index 359fb50b916..8022fde77eb 100644 --- a/src/sysupdate/sysupdated.c +++ b/src/sysupdate/sysupdated.c @@ -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",