From 4c83d994566718043e61e568cc214bdc4587f869 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Tue, 9 Sep 2014 11:15:37 +0200 Subject: udev: event - keep one rtnl per worker, rather than per event Creating the rtnl context is cheap, but freeing it may not be, due to synchronous close(). Also drop some excessive logging. We now log about the changing ifname exactly once. --- src/libsystemd/sd-rtnl/rtnl-util.c | 12 +++++++++--- src/libsystemd/sd-rtnl/rtnl-util.h | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src/libsystemd') diff --git a/src/libsystemd/sd-rtnl/rtnl-util.c b/src/libsystemd/sd-rtnl/rtnl-util.c index 0bc2c9b1f5..fe0f34e125 100644 --- a/src/libsystemd/sd-rtnl/rtnl-util.c +++ b/src/libsystemd/sd-rtnl/rtnl-util.c @@ -26,7 +26,7 @@ #include "rtnl-util.h" #include "rtnl-internal.h" -int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name) { +int rtnl_set_link_name(sd_rtnl **rtnl, int ifindex, const char *name) { _cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL; int r; @@ -34,7 +34,13 @@ int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name) { assert(ifindex > 0); assert(name); - r = sd_rtnl_message_new_link(rtnl, &message, RTM_SETLINK, ifindex); + if (!*rtnl) { + r = sd_rtnl_open(rtnl, 0); + if (r < 0) + return r; + } + + r = sd_rtnl_message_new_link(*rtnl, &message, RTM_SETLINK, ifindex); if (r < 0) return r; @@ -42,7 +48,7 @@ int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name) { if (r < 0) return r; - r = sd_rtnl_call(rtnl, message, 0, NULL); + r = sd_rtnl_call(*rtnl, message, 0, NULL); if (r < 0) return r; diff --git a/src/libsystemd/sd-rtnl/rtnl-util.h b/src/libsystemd/sd-rtnl/rtnl-util.h index 2963f02d3e..94af3b1720 100644 --- a/src/libsystemd/sd-rtnl/rtnl-util.h +++ b/src/libsystemd/sd-rtnl/rtnl-util.h @@ -34,7 +34,7 @@ bool rtnl_message_type_is_link(uint16_t type); bool rtnl_message_type_is_addr(uint16_t type); bool rtnl_message_type_is_route(uint16_t type); -int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name); +int rtnl_set_link_name(sd_rtnl **rtnl, int ifindex, const char *name); int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *alias, const struct ether_addr *mac, unsigned mtu); int rtnl_log_parse_error(int r); -- cgit v1.2.3-54-g00ecf