machine: lookup_machine_by_name_or_pid() may return 1 on error and it is already replied
Follow-ups for 1bd979dddb and later
commits.
Fixes #34764.
This commit is contained in:
@@ -236,6 +236,8 @@ int lookup_machine_by_name_or_pid(sd_varlink *link, Manager *manager, const char
|
||||
assert(manager);
|
||||
assert(ret_machine);
|
||||
|
||||
/* This returns 0 on success, 1 on error and it is replied, and a negative errno otherwise. */
|
||||
|
||||
if (machine_name) {
|
||||
r = lookup_machine_by_name(link, manager, machine_name, &machine);
|
||||
if (r == -EINVAL)
|
||||
@@ -340,7 +342,7 @@ int vl_method_kill(sd_varlink *link, sd_json_variant *parameters, sd_varlink_met
|
||||
r = lookup_machine_by_name_or_pid(link, manager, p.machine_name, p.pid, &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))
|
||||
|
||||
@@ -448,7 +448,7 @@ static int vl_method_list(sd_varlink *link, sd_json_variant *parameters, sd_varl
|
||||
r = lookup_machine_by_name_or_pid(link, m, p.machine_name, p.pid, &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);
|
||||
@@ -496,7 +496,7 @@ static int lookup_machine_and_call_method(sd_varlink *link, sd_json_variant *par
|
||||
r = lookup_machine_by_name_or_pid(link, manager, p.machine_name, p.pid, &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);
|
||||
|
||||
@@ -261,11 +261,11 @@ varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List
|
||||
|
||||
pid=$(varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name":"long-running"}' | jq '.leader.pid')
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user