summaryrefslogtreecommitdiff
path: root/src/udev/net/link-config.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2013-10-29 17:48:58 +0100
committerTom Gundersen <teg@jklm.no>2013-10-29 17:57:21 +0100
commit977085794d2996320e345433403de75f662b0622 (patch)
tree707ed237ba75befb82b0efa15203684e7e299271 /src/udev/net/link-config.c
parentadf412b9ec7292e0c83aaf9ab93e08c2c8bd524a (diff)
udev: link-config - split connection to sockets from loading of configs
We want to load the config in _init, but not connect to the sockets before we are forked.
Diffstat (limited to 'src/udev/net/link-config.c')
-rw-r--r--src/udev/net/link-config.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 9d6c96b5a5..f93a4d835d 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -54,7 +54,6 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(link_config_ctx*, link_config_ctx_free);
int link_config_ctx_new(link_config_ctx **ret) {
_cleanup_link_config_ctx_free_ link_config_ctx *ctx = NULL;
- int r;
if (!ret)
return -EINVAL;
@@ -63,16 +62,10 @@ int link_config_ctx_new(link_config_ctx **ret) {
if (!ctx)
return -ENOMEM;
- r = ethtool_connect(&ctx->ethtool_fd);
- if (r < 0)
- return r;
-
- r = sd_rtnl_open(0, &ctx->rtnl);
- if (r < 0)
- return r;
-
LIST_HEAD_INIT(ctx->links);
+ ctx->ethtool_fd = -1;
+
ctx->link_dirs = strv_new("/etc/systemd/network",
"/run/systemd/network",
"/usr/lib/systemd/network",
@@ -93,6 +86,23 @@ int link_config_ctx_new(link_config_ctx **ret) {
return 0;
}
+static int link_config_ctx_connect(link_config_ctx *ctx) {
+ int r;
+
+ if (ctx->ethtool_fd >= 0 && ctx->rtnl)
+ return 0;
+
+ r = ethtool_connect(&ctx->ethtool_fd);
+ if (r < 0)
+ return r;
+
+ r = sd_rtnl_open(0, &ctx->rtnl);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
static void link_configs_free(link_config_ctx *ctx) {
link_config *link, *link_next;
@@ -406,6 +416,10 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_dev
struct ether_addr *mac = NULL;
int r, ifindex;
+ r = link_config_ctx_connect(ctx);
+ if (r < 0)
+ return r;
+
name = udev_device_get_sysname(device);
if (!name)
return -EINVAL;