]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machined: return recognizable error when we try to register the same machine name...
authorLennart Poettering <lennart@poettering.net>
Sat, 11 May 2024 17:54:54 +0000 (19:54 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 13 May 2024 18:25:22 +0000 (12:25 -0600)
src/machine/machine-varlink.c
src/shared/varlink-io.systemd.Machine.c
src/vmspawn/vmspawn-register.c

index 60792d76b1d52d33fa94922fbf10e50bd54e71a5..968da3cfb597004607ebfa0eed2b2d8eeb96fbde 100644 (file)
@@ -153,6 +153,8 @@ int vl_method_register(Varlink *link, JsonVariant *parameters, VarlinkMethodFlag
         }
 
         r = machine_link(manager, machine);
+        if (r == -EEXIST)
+                return varlink_error(link, "io.systemd.Machine.MachineExists", NULL);
         if (r < 0)
                 return r;
 
index 6675492076337c807d6053175ff7eb0f78d48240..2d25a345d7979b92e1fff86737996260ed953d6c 100644 (file)
@@ -16,7 +16,10 @@ static VARLINK_DEFINE_METHOD(
                 VARLINK_DEFINE_INPUT(sshAddress,        VARLINK_STRING, VARLINK_NULLABLE),
                 VARLINK_DEFINE_INPUT(sshPrivateKeyPath, VARLINK_STRING, VARLINK_NULLABLE));
 
+static VARLINK_DEFINE_ERROR(MachineExists);
+
 VARLINK_DEFINE_INTERFACE(
                 io_systemd_Machine,
                 "io.systemd.Machine",
-                &vl_method_Register);
+                &vl_method_Register,
+                &vl_error_MachineExists);
index ed70df5fb83f68751a9b592b23b6fab1bfa7335d..42650b82c004849102dccc67ad69e6045162d0fc 100644 (file)
@@ -58,7 +58,6 @@ int register_machine(
         if (r < 0)
                 return log_error_errno(r, "Failed to connect to machined on /run/systemd/machine/io.systemd.Machine: %m");
 
-
         return varlink_callb_and_log(vl,
                         "io.systemd.Machine.Register",
                         NULL,