mirror of
https://github.com/systemd/systemd.git
synced 2026-06-30 19:57:29 +00:00
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.
This commit is contained in:
@@ -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',
|
||||
|
||||
22
src/sysupdate/sysupdate-target.c
Normal file
22
src/sysupdate/sysupdate-target.c
Normal file
@@ -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);
|
||||
}
|
||||
32
src/sysupdate/sysupdate-target.h
Normal file
32
src/sysupdate/sysupdate-target.h
Normal file
@@ -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);
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user