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

Merge pull request #409 from teg/networkd-enslave-segfault

fix segfault when cancelling enslaving of links by netdevs
This commit is contained in:
Daniel Mack 2015-07-01 19:26:01 -04:00
commit 138879ccad
2 changed files with 13 additions and 3 deletions

View File

@ -1360,8 +1360,7 @@ static int link_joined(Link *link) {
return link_enter_set_addresses(link); return link_enter_set_addresses(link);
} }
static int netdev_join_handler(sd_netlink *rtnl, sd_netlink_message *m, static int netdev_join_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
void *userdata) {
_cleanup_link_unref_ Link *link = userdata; _cleanup_link_unref_ Link *link = userdata;
int r; int r;

View File

@ -92,10 +92,11 @@ static void netdev_cancel_callbacks(NetDev *netdev) {
assert(netdev->manager); assert(netdev->manager);
assert(netdev->manager->rtnl); assert(netdev->manager->rtnl);
callback->callback(netdev->manager->rtnl, m, link); callback->callback(netdev->manager->rtnl, m, callback->link);
} }
LIST_REMOVE(callbacks, netdev->callbacks, callback); LIST_REMOVE(callbacks, netdev->callbacks, callback);
link_unref(callback->link);
free(callback); free(callback);
} }
} }
@ -177,6 +178,8 @@ int netdev_get(Manager *manager, const char *name, NetDev **ret) {
static int netdev_enter_failed(NetDev *netdev) { static int netdev_enter_failed(NetDev *netdev) {
netdev->state = NETDEV_STATE_FAILED; netdev->state = NETDEV_STATE_FAILED;
netdev_cancel_callbacks(netdev);
return 0; return 0;
} }
@ -266,12 +269,20 @@ int netdev_enslave(NetDev *netdev, Link *link, sd_netlink_message_handler_t call
int r; int r;
assert(netdev); assert(netdev);
assert(netdev->manager);
assert(netdev->manager->rtnl);
assert(IN_SET(netdev->kind, NETDEV_KIND_BRIDGE, NETDEV_KIND_BOND)); assert(IN_SET(netdev->kind, NETDEV_KIND_BRIDGE, NETDEV_KIND_BOND));
if (netdev->state == NETDEV_STATE_READY) { if (netdev->state == NETDEV_STATE_READY) {
r = netdev_enslave_ready(netdev, link, callback); r = netdev_enslave_ready(netdev, link, callback);
if (r < 0) if (r < 0)
return r; return r;
} else if (IN_SET(netdev->state, NETDEV_STATE_LINGER, NETDEV_STATE_FAILED)) {
_cleanup_netlink_message_unref_ sd_netlink_message *m = NULL;
r = rtnl_message_new_synthetic_error(-ENODEV, 0, &m);
if (r >= 0)
callback(netdev->manager->rtnl, m, link);
} else { } else {
/* the netdev is not yet read, save this request for when it is */ /* the netdev is not yet read, save this request for when it is */
netdev_join_callback *cb; netdev_join_callback *cb;