X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd-rtnl%2Fsd-rtnl.c;h=08b82ab2a94f3f6dca6bb5e21934d90cbb48cfcc;hb=b9eaf3d1ebc839dc30dbbee9ce080855b3f002c0;hp=57d0b766f2c63158d795bd5c70a3048f5219a911;hpb=8cec01b9e9b7264639fd1fc0fe373ef4d5baaf49;p=elogind.git diff --git a/src/libsystemd-rtnl/sd-rtnl.c b/src/libsystemd-rtnl/sd-rtnl.c index 57d0b766f..08b82ab2a 100644 --- a/src/libsystemd-rtnl/sd-rtnl.c +++ b/src/libsystemd-rtnl/sd-rtnl.c @@ -75,6 +75,8 @@ int sd_rtnl_open(uint32_t groups, sd_rtnl **ret) { socklen_t addrlen; int r; + assert_return(ret, -EINVAL); + r = sd_rtnl_new(&rtnl); if (r < 0) return r; @@ -302,7 +304,7 @@ static int process_match(sd_rtnl *rtnl, sd_rtnl_message *m) { return r; LIST_FOREACH(match_callbacks, c, rtnl->match_callbacks) { - if (type & c->types) { + if (type == c->type) { r = c->callback(rtnl, m, c->userdata); if (r != 0) return r; @@ -316,6 +318,8 @@ static int process_running(sd_rtnl *rtnl, sd_rtnl_message **ret) { _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *m = NULL; int r; + assert(rtnl); + r = process_timeout(rtnl); if (r != 0) goto null_message; @@ -743,7 +747,7 @@ static int prepare_callback(sd_event_source *s, void *userdata) { return 1; } -static int quit_callback(sd_event_source *event, void *userdata) { +static int exit_callback(sd_event_source *event, void *userdata) { sd_rtnl *rtnl = userdata; assert(event); @@ -790,7 +794,7 @@ int sd_rtnl_attach_event(sd_rtnl *rtnl, sd_event *event, int priority) { if (r < 0) goto fail; - r = sd_event_add_quit(rtnl->event, quit_callback, rtnl, &rtnl->quit_event_source); + r = sd_event_add_exit(rtnl->event, exit_callback, rtnl, &rtnl->exit_event_source); if (r < 0) goto fail; @@ -811,8 +815,8 @@ int sd_rtnl_detach_event(sd_rtnl *rtnl) { if (rtnl->time_event_source) rtnl->time_event_source = sd_event_source_unref(rtnl->time_event_source); - if (rtnl->quit_event_source) - rtnl->quit_event_source = sd_event_source_unref(rtnl->quit_event_source); + if (rtnl->exit_event_source) + rtnl->exit_event_source = sd_event_source_unref(rtnl->exit_event_source); if (rtnl->event) rtnl->event = sd_event_unref(rtnl->event); @@ -821,22 +825,22 @@ int sd_rtnl_detach_event(sd_rtnl *rtnl) { } int sd_rtnl_add_match(sd_rtnl *rtnl, - uint16_t types, + uint16_t type, sd_rtnl_message_handler_t callback, void *userdata) { struct match_callback *c; assert_return(rtnl, -EINVAL); assert_return(callback, -EINVAL); - assert_return(types, -EINVAL); assert_return(!rtnl_pid_changed(rtnl), -ECHILD); + assert_return(message_type_is_link(type) || message_type_is_addr(type) || message_type_is_route(type), -ENOTSUP); c = new0(struct match_callback, 1); if (!c) return -ENOMEM; c->callback = callback; - c->types = types; + c->type = type; c->userdata = userdata; LIST_PREPEND(match_callbacks, rtnl->match_callbacks, c); @@ -845,7 +849,7 @@ int sd_rtnl_add_match(sd_rtnl *rtnl, } int sd_rtnl_remove_match(sd_rtnl *rtnl, - uint16_t types, + uint16_t type, sd_rtnl_message_handler_t callback, void *userdata) { struct match_callback *c; @@ -855,7 +859,7 @@ int sd_rtnl_remove_match(sd_rtnl *rtnl, assert_return(!rtnl_pid_changed(rtnl), -ECHILD); LIST_FOREACH(match_callbacks, c, rtnl->match_callbacks) - if (c->callback == callback && c->types == types && c->userdata == userdata) { + if (c->callback == callback && c->type == type && c->userdata == userdata) { LIST_REMOVE(match_callbacks, rtnl->match_callbacks, c); free(c);