1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

sd-netlink: set destroy_callback only if asynchronous call succeeds

This commit is contained in:
Yu Watanabe 2018-12-14 10:26:36 +09:00 committed by Zbigniew Jędrzejewski-Szmek
parent 40d70ca07c
commit 5cd6711621
3 changed files with 8 additions and 5 deletions

View File

@ -14,7 +14,6 @@ int netlink_slot_allocate(
bool floating,
NetlinkSlotType type,
size_t extra,
sd_netlink_destroy_t destroy_callback,
void *userdata,
const char *description,
sd_netlink_slot **ret) {
@ -31,7 +30,6 @@ int netlink_slot_allocate(
slot->n_ref = 1;
slot->netlink = nl;
slot->userdata = userdata;
slot->destroy_callback = destroy_callback;
slot->type = type;
slot->floating = floating;

View File

@ -8,7 +8,6 @@ int netlink_slot_allocate(
bool floating,
NetlinkSlotType type,
size_t extra,
sd_netlink_destroy_t destroy_callback,
void *userdata,
const char *description,
sd_netlink_slot **ret);

View File

@ -550,7 +550,7 @@ int sd_netlink_call_async(
return r;
}
r = netlink_slot_allocate(nl, !ret_slot, NETLINK_REPLY_CALLBACK, sizeof(struct reply_callback), destroy_callback, userdata, description, &slot);
r = netlink_slot_allocate(nl, !ret_slot, NETLINK_REPLY_CALLBACK, sizeof(struct reply_callback), userdata, description, &slot);
if (r < 0)
return r;
@ -575,6 +575,9 @@ int sd_netlink_call_async(
}
}
/* Set this at last. Otherwise, some failures in above call the destroy callback but some do not. */
slot->destroy_callback = destroy_callback;
if (ret_slot)
*ret_slot = slot;
@ -840,7 +843,7 @@ int sd_netlink_add_match(
assert_return(callback, -EINVAL);
assert_return(!rtnl_pid_changed(rtnl), -ECHILD);
r = netlink_slot_allocate(rtnl, !ret_slot, NETLINK_MATCH_CALLBACK, sizeof(struct match_callback), destroy_callback, userdata, description, &slot);
r = netlink_slot_allocate(rtnl, !ret_slot, NETLINK_MATCH_CALLBACK, sizeof(struct match_callback), userdata, description, &slot);
if (r < 0)
return r;
@ -892,6 +895,9 @@ int sd_netlink_add_match(
LIST_PREPEND(match_callbacks, rtnl->match_callbacks, &slot->match_callback);
/* Set this at last. Otherwise, some failures in above call the destroy callback but some do not. */
slot->destroy_callback = destroy_callback;
if (ret_slot)
*ret_slot = slot;