mirror of
https://github.com/systemd/systemd.git
synced 2025-03-08 08:58:27 +03:00
machine: split operation initialization into two steps
This commit is contained in:
parent
bf4066ece0
commit
22cd741ff1
@ -88,15 +88,14 @@ 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);
|
||||
if (!o)
|
||||
@ -111,8 +110,8 @@ int operation_new(Manager *manager, Machine *machine, pid_t child, sd_bus_messag
|
||||
}
|
||||
|
||||
o->pid = child;
|
||||
o->message = sd_bus_message_ref(message);
|
||||
o->link = sd_varlink_ref(link);
|
||||
o->message = NULL;
|
||||
o->link = NULL;
|
||||
o->errno_fd = errno_fd;
|
||||
|
||||
LIST_PREPEND(operations, manager->operations, o);
|
||||
@ -128,9 +127,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,53 @@ 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 void operation_with_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_with_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) {
|
||||
return operation_new(manager, machine, child, message, /* link = */ NULL, errno_fd, ret);
|
||||
Operation *op;
|
||||
int r;
|
||||
|
||||
r = operation_new(manager, machine, child, errno_fd, &op);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
operation_with_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);
|
||||
Operation *op;
|
||||
int r;
|
||||
|
||||
r = operation_new(manager, machine, child, errno_fd, &op);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
operation_with_varlink_reply(op, link);
|
||||
|
||||
if (ret)
|
||||
*ret = op;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user