mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
machined: add UnregisterMachine method
This is the opposite of RegisterMachine: machined knows that the machine is "gone", but doesn't do anything on its own. We already had TerminateMachine, but that would stop the unit, which isn't always wanted.
This commit is contained in:
parent
ebc57b89c6
commit
ef8ff92e8a
@ -62,6 +62,34 @@ static int property_get_netif(
|
||||
return sd_bus_message_append_array(reply, 'i', m->netif, m->n_netif * sizeof(int));
|
||||
}
|
||||
|
||||
int bus_machine_method_unregister(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
Machine *m = userdata;
|
||||
int r;
|
||||
|
||||
assert(message);
|
||||
assert(m);
|
||||
|
||||
r = bus_verify_polkit_async(
|
||||
message,
|
||||
CAP_KILL,
|
||||
"org.freedesktop.machine1.manage-machines",
|
||||
NULL,
|
||||
false,
|
||||
UID_INVALID,
|
||||
&m->manager->polkit_registry,
|
||||
error);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
return 1; /* Will call us back */
|
||||
|
||||
r = machine_finalize(m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return sd_bus_reply_method_return(message, NULL);
|
||||
}
|
||||
|
||||
int bus_machine_method_terminate(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
Machine *m = userdata;
|
||||
int r;
|
||||
|
@ -11,6 +11,7 @@ char *machine_bus_path(Machine *s);
|
||||
int machine_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
|
||||
int machine_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
|
||||
|
||||
int bus_machine_method_unregister(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
||||
int bus_machine_method_terminate(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
||||
int bus_machine_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
||||
int bus_machine_method_get_addresses(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
||||
|
@ -449,13 +449,16 @@ int machine_stop(Machine *m) {
|
||||
int machine_finalize(Machine *m) {
|
||||
assert(m);
|
||||
|
||||
if (m->started)
|
||||
if (m->started) {
|
||||
log_struct(LOG_INFO,
|
||||
"MESSAGE_ID=" SD_MESSAGE_MACHINE_STOP_STR,
|
||||
"NAME=%s", m->name,
|
||||
"LEADER="PID_FMT, m->leader,
|
||||
LOG_MESSAGE("Machine %s terminated.", m->name));
|
||||
|
||||
m->stopping = true; /* The machine is supposed to be going away. Don't try to kill it. */
|
||||
}
|
||||
|
||||
machine_unlink(m);
|
||||
machine_add_to_gc_queue(m);
|
||||
|
||||
|
@ -448,6 +448,10 @@ static int redirect_method_to_machine(sd_bus_message *message, Manager *m, sd_bu
|
||||
return method(message, machine, error);
|
||||
}
|
||||
|
||||
static int method_unregister_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
return redirect_method_to_machine(message, userdata, error, bus_machine_method_unregister);
|
||||
}
|
||||
|
||||
static int method_terminate_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
return redirect_method_to_machine(message, userdata, error, bus_machine_method_terminate);
|
||||
}
|
||||
@ -1137,6 +1141,7 @@ const sd_bus_vtable manager_vtable[] = {
|
||||
SD_BUS_METHOD("CreateMachineWithNetwork", "sayssusaia(sv)", "o", method_create_machine_with_network, 0),
|
||||
SD_BUS_METHOD("RegisterMachine", "sayssus", "o", method_register_machine, 0),
|
||||
SD_BUS_METHOD("RegisterMachineWithNetwork", "sayssusai", "o", method_register_machine_with_network, 0),
|
||||
SD_BUS_METHOD("UnregisterMachine", "s", NULL, method_unregister_machine, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("TerminateMachine", "s", NULL, method_terminate_machine, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("KillMachine", "ssi", NULL, method_kill_machine, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("GetMachineAddresses", "s", "a(iay)", method_get_machine_addresses, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
|
@ -76,6 +76,10 @@
|
||||
send_interface="org.freedesktop.machine1.Manager"
|
||||
send_member="OpenMachineShell"/>
|
||||
|
||||
<allow send_destination="org.freedesktop.machine1"
|
||||
send_interface="org.freedesktop.machine1.Manager"
|
||||
send_member="UnregisterMachine"/>
|
||||
|
||||
<allow send_destination="org.freedesktop.machine1"
|
||||
send_interface="org.freedesktop.machine1.Manager"
|
||||
send_member="TerminateMachine"/>
|
||||
|
Loading…
Reference in New Issue
Block a user