hostnamed: add Varlink equivalents for the hostname/machine-info setters

Add SetHostname(), SetStaticHostname(), SetPrettyHostname(), SetIconName(),
SetChassis(), SetDeployment() and SetLocation() to the io.systemd.Hostname
Varlink interface, mirroring the existing D-Bus methods of the same names.

Each takes a single nullable string "newValue" (null clears/resets the
value; the method name itself makes clear what the value is) plus the usual
allowInteractiveAuthentication polkit input, and applies the same
validation, polkit actions and /etc/hostname resp. /etc/machine-info
persistence as its D-Bus counterpart. The five machine-info setters share
a common helper. The hostname validator is reused from the D-Bus path,
translating its INVALID_ARGS error into a Varlink invalid-parameter error.

Being reachable over the socket-activated Varlink socket, these work in
early boot before the system bus is up.
This commit is contained in:
Lennart Poettering
2026-06-01 10:56:16 +02:00
parent 0f790ea87f
commit e3f453b3e9
2 changed files with 330 additions and 9 deletions
+56
View File
@@ -44,6 +44,48 @@ static SD_VARLINK_DEFINE_METHOD(
SD_VARLINK_DEFINE_OUTPUT(ProductUUID, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
SD_VARLINK_DEFINE_OUTPUT(VSockCID, SD_VARLINK_INT, SD_VARLINK_NULLABLE));
static SD_VARLINK_DEFINE_METHOD(
SetHostname,
SD_VARLINK_FIELD_COMMENT("The transient (runtime) hostname to set. If null the transient hostname is reset, so that the static hostname is used again."),
SD_VARLINK_DEFINE_INPUT(newValue, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
VARLINK_DEFINE_POLKIT_INPUT);
static SD_VARLINK_DEFINE_METHOD(
SetStaticHostname,
SD_VARLINK_FIELD_COMMENT("The static hostname to set, stored in /etc/hostname. If null the static hostname is removed."),
SD_VARLINK_DEFINE_INPUT(newValue, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
VARLINK_DEFINE_POLKIT_INPUT);
static SD_VARLINK_DEFINE_METHOD(
SetPrettyHostname,
SD_VARLINK_FIELD_COMMENT("The pretty (free-form, UTF-8) hostname to set. If null the pretty hostname is removed."),
SD_VARLINK_DEFINE_INPUT(newValue, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
VARLINK_DEFINE_POLKIT_INPUT);
static SD_VARLINK_DEFINE_METHOD(
SetIconName,
SD_VARLINK_FIELD_COMMENT("The icon name to set. If null the icon name is removed."),
SD_VARLINK_DEFINE_INPUT(newValue, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
VARLINK_DEFINE_POLKIT_INPUT);
static SD_VARLINK_DEFINE_METHOD(
SetChassis,
SD_VARLINK_FIELD_COMMENT("The chassis type to set. If null the chassis type is removed."),
SD_VARLINK_DEFINE_INPUT(newValue, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
VARLINK_DEFINE_POLKIT_INPUT);
static SD_VARLINK_DEFINE_METHOD(
SetDeployment,
SD_VARLINK_FIELD_COMMENT("The deployment environment to set. If null the deployment is removed."),
SD_VARLINK_DEFINE_INPUT(newValue, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
VARLINK_DEFINE_POLKIT_INPUT);
static SD_VARLINK_DEFINE_METHOD(
SetLocation,
SD_VARLINK_FIELD_COMMENT("The physical location to set. If null the location is removed."),
SD_VARLINK_DEFINE_INPUT(newValue, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
VARLINK_DEFINE_POLKIT_INPUT);
static SD_VARLINK_DEFINE_METHOD(
SetTags,
SD_VARLINK_FIELD_COMMENT("If specified, the machine tag list is first reset to exactly these tags, before the 'add' and 'remove' fields are applied. If null, the current tag list is used as basis instead."),
@@ -58,5 +100,19 @@ SD_VARLINK_DEFINE_INTERFACE(
io_systemd_Hostname,
"io.systemd.Hostname",
&vl_method_Describe,
SD_VARLINK_SYMBOL_COMMENT("Sets the transient (runtime) hostname."),
&vl_method_SetHostname,
SD_VARLINK_SYMBOL_COMMENT("Sets the static hostname, stored in /etc/hostname."),
&vl_method_SetStaticHostname,
SD_VARLINK_SYMBOL_COMMENT("Sets the pretty (free-form, UTF-8) hostname."),
&vl_method_SetPrettyHostname,
SD_VARLINK_SYMBOL_COMMENT("Sets the icon name representing this system."),
&vl_method_SetIconName,
SD_VARLINK_SYMBOL_COMMENT("Sets the chassis type of this system."),
&vl_method_SetChassis,
SD_VARLINK_SYMBOL_COMMENT("Sets the deployment environment of this system."),
&vl_method_SetDeployment,
SD_VARLINK_SYMBOL_COMMENT("Sets the physical location of this system."),
&vl_method_SetLocation,
SD_VARLINK_SYMBOL_COMMENT("Edits the machine tag list: optionally resets it to 'set', then adds 'add' and removes 'remove'."),
&vl_method_SetTags);