diff options
author | Ivan Kruglov <mail@ikruglov.com> | 2024-12-17 12:24:51 +0100 |
---|---|---|
committer | Ivan Kruglov <mail@ikruglov.com> | 2025-01-06 14:41:49 +0100 |
commit | 347a1105a49396356c6c2e98974ce7acd0b14eb7 (patch) | |
tree | b4aecdf07985dc96d41228d6ca46fa16cc681829 /src/machine | |
parent | machine: adjust operation callback logic for varlink (diff) | |
download | systemd-347a1105a49396356c6c2e98974ce7acd0b14eb7.tar.xz systemd-347a1105a49396356c6c2e98974ce7acd0b14eb7.zip |
machine: split operation initialization into two steps
Diffstat (limited to 'src/machine')
-rw-r--r-- | src/machine/operation.c | 22 | ||||
-rw-r--r-- | src/machine/operation.h | 68 |
2 files changed, 72 insertions, 18 deletions
diff --git a/src/machine/operation.c b/src/machine/operation.c index 00b9e09249..9e4e7e3dce 100644 --- a/src/machine/operation.c +++ b/src/machine/operation.c @@ -88,21 +88,24 @@ static int operation_done(sd_event_source *s, const siginfo_t *si, void *userdat return 0; } -int operation_new(Manager *manager, Machine *machine, pid_t child, sd_bus_message *message, sd_varlink *link, int errno_fd, Operation **ret) { +int operation_new(Manager *manager, Machine *machine, pid_t child, int errno_fd, Operation **ret) { Operation *o; int r; assert(manager); assert(child > 1); assert(errno_fd >= 0); - assert(message || link); - assert(!(message && link)); + assert(ret); - o = new0(Operation, 1); + o = new(Operation, 1); if (!o) return -ENOMEM; - o->extra_fd = -EBADF; + *o = (Operation) { + .pid = child, + .errno_fd = errno_fd, + .extra_fd = -EBADF + }; r = sd_event_add_child(manager->event, &o->event_source, child, WEXITED, operation_done, o); if (r < 0) { @@ -110,11 +113,6 @@ int operation_new(Manager *manager, Machine *machine, pid_t child, sd_bus_messag return r; } - o->pid = child; - o->message = sd_bus_message_ref(message); - o->link = sd_varlink_ref(link); - o->errno_fd = errno_fd; - LIST_PREPEND(operations, manager->operations, o); manager->n_operations++; o->manager = manager; @@ -128,9 +126,7 @@ int operation_new(Manager *manager, Machine *machine, pid_t child, sd_bus_messag /* At this point we took ownership of both the child and the errno file descriptor! */ - if (ret) - *ret = o; - + *ret = o; return 0; } diff --git a/src/machine/operation.h b/src/machine/operation.h index 75bf918c2b..1a92847b80 100644 --- a/src/machine/operation.h +++ b/src/machine/operation.h @@ -31,11 +31,69 @@ struct Operation { LIST_FIELDS(Operation, operations_by_machine); }; -int operation_new(Manager *manager, Machine *machine, pid_t child, sd_bus_message *message, sd_varlink *link, int errno_fd, Operation **ret); +int operation_new(Manager *manager, Machine *machine, pid_t child, int errno_fd, Operation **ret); Operation *operation_free(Operation *o); -static inline int operation_new_with_bus_reply(Manager *manager, Machine *machine, pid_t child, sd_bus_message *message, int errno_fd, Operation **ret) { - return operation_new(manager, machine, child, message, /* link = */ NULL, errno_fd, ret); + +static inline void operation_attach_bus_reply(Operation *op, sd_bus_message *message) { + assert(op); + assert(!op->message); + assert(!op->link); + assert(message); + + op->message = sd_bus_message_ref(message); +} + +static inline void operation_attach_varlink_reply(Operation *op, sd_varlink *link) { + assert(op); + assert(!op->message); + assert(!op->link); + assert(link); + + op->link = sd_varlink_ref(link); +} + +static inline int operation_new_with_bus_reply( + Manager *manager, + Machine *machine, + pid_t child, + sd_bus_message *message, + int errno_fd, + Operation **ret) { + + Operation *op; + int r; + + r = operation_new(manager, machine, child, errno_fd, &op); + if (r < 0) + return r; + + operation_attach_bus_reply(op, message); + + if (ret) + *ret = op; + + return 0; } -static inline int operation_new_with_varlink_reply(Manager *manager, Machine *machine, pid_t child, sd_varlink *link, int errno_fd, Operation **ret) { - return operation_new(manager, machine, child, /* message = */ NULL, link, errno_fd, ret); + +static inline int operation_new_with_varlink_reply( + Manager *manager, + Machine *machine, + pid_t child, + sd_varlink *link, + int errno_fd, + Operation **ret) { + + Operation *op; + int r; + + r = operation_new(manager, machine, child, errno_fd, &op); + if (r < 0) + return r; + + operation_attach_varlink_reply(op, link); + + if (ret) + *ret = op; + + return 0; } |