]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #34723 from poettering/machined-pidref-more
authorLennart Poettering <lennart@poettering.net>
Tue, 15 Oct 2024 09:37:39 +0000 (11:37 +0200)
committerGitHub <noreply@github.com>
Tue, 15 Oct 2024 09:37:39 +0000 (11:37 +0200)
machined: switch remaining Varlink overs over to use json_dispatch_pidref() and friends

1  2 
src/machine/machine-varlink.c
src/machine/machined-varlink.c
test/units/TEST-13-NSPAWN.machined.sh

index 3affc5265c2512b95c8d7a7a4f8091aa588a865b,bfa4095a3b0d36a53d14e61e02925a5adc635c6c..c9f44f20ab21500792a5e8556d819bd25558caf0
@@@ -339,10 -345,10 +347,10 @@@ int vl_method_kill(sd_varlink *link, sd
                  return r;
  
          Machine *machine;
-         r = lookup_machine_by_name_or_pid(link, manager, p.machine_name, p.pid, &machine);
+         r = lookup_machine_by_name_or_pidref(link, manager, p.name, &p.pidref, &machine);
          if (r == -ESRCH)
                  return sd_varlink_error(link, "io.systemd.Machine.NoSuchMachine", NULL);
 -        if (r < 0)
 +        if (r != 0)
                  return r;
  
          if (isempty(p.swhom))
index 536aee507d8c7204fadc97ea025aba0b05989217,43be4a0f3c25e4998c8885114ab13779d8c6da82..5932d5edabadca70143ffd5083f87b51208e1b0f
@@@ -444,11 -450,11 +452,11 @@@ static int vl_method_list(sd_varlink *l
          if (r != 0)
                  return r;
  
-         if (p.machine_name || pid_is_valid_or_automatic(p.pid)) {
-                 r = lookup_machine_by_name_or_pid(link, m, p.machine_name, p.pid, &machine);
+         if (p.name || pidref_is_set(&p.pidref) || pidref_is_automatic(&p.pidref)) {
+                 r = lookup_machine_by_name_or_pidref(link, m, p.name, &p.pidref, &machine);
                  if (r == -ESRCH)
                          return sd_varlink_error(link, "io.systemd.Machine.NoSuchMachine", NULL);
 -                if (r < 0)
 +                if (r != 0)
                          return r;
  
                  return list_machine_one(link, machine, /* more= */ false);
@@@ -493,10 -501,10 +503,10 @@@ static int lookup_machine_and_call_meth
          if (r != 0)
                  return r;
  
-         r = lookup_machine_by_name_or_pid(link, manager, p.machine_name, p.pid, &machine);
+         r = lookup_machine_by_name_or_pidref(link, manager, p.name, &p.pidref, &machine);
          if (r == -ESRCH)
                  return sd_varlink_error(link, "io.systemd.Machine.NoSuchMachine", NULL);
 -        if (r < 0)
 +        if (r != 0)
                  return r;
  
          return method(link, parameters, flags, machine);
index 987ecfee90192a0fab6862de265f24c608cb70bd,b54f6e80d35a561519f9da4c760966b6a4d6360c..176fe6fb69a2be3d9f7b7d14d5c105b733d4e7dd
@@@ -261,13 -251,13 +261,13 @@@ varlinkctl --more call /run/systemd/mac
  varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{}' | grep '.host'
  varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name":"long-running"}'
  
- pid=$(varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name":"long-running"}' | jq '.leader.pid')
+ pid=$(varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name":"long-running"}' | jq '.leader')
  varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name":"long-running"}' >/tmp/expected
 -varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List "{\"pid\":$pid}" >/tmp/got
 -diff -u /tmp/expected /tmp/got
 -
 -varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List "{\"name\":\"long-running\", \"pid\":$pid}"
 +varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List "{\"pid\":$pid}" | diff /tmp/expected -
 +varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List "{\"name\":\"long-running\", \"pid\":$pid}" | diff /tmp/expected -
  (! varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List "{\"name\":\"non-existent\", \"pid\":$pid}")
 +(! varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name":""}')
 +(! varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name":"ah@??.hmm"}')
  
  # test io.systemd.Machine.Kill
  # sending TRAP signal