mirror of
https://github.com/systemd/systemd.git
synced 2025-03-02 12:58:35 +03:00
machine: split operation initialization into two steps
This commit is contained in:
parent
ee71079aba
commit
347a1105a4
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 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 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) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user