From b519908cace83fc57b7258c24f7f59919ae77837 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 1 Apr 2019 00:24:25 +0900 Subject: [PATCH] network: do not abort execution when NetDev.Name= conflicts This also changes that .netdev files are loaded in ascending order. Otherwise, when NetDev.ifname= setting conflicts with other .netdev file, then .netdev file with large prefix number wins. --- src/network/netdev/netdev.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index f6d3ef81537..df05cb465bd 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -738,6 +738,19 @@ int netdev_load_one(Manager *manager, const char *filename) { return r; r = hashmap_put(netdev->manager->netdevs, netdev->ifname, netdev); + if (r == -EEXIST) { + NetDev *n = hashmap_get(netdev->manager->netdevs, netdev->ifname); + + assert(n); + log_netdev_warning_errno(netdev, r, + "The setting Name=%s in %s conflicts with the one in %s, ignoring", + netdev->ifname, netdev->filename, n->filename); + + /* Clear ifname before netdev_free() is called. Otherwise, the NetDev object 'n' is + * removed from the hashmap 'manager->netdevs'. */ + netdev->ifname = mfree(netdev->ifname); + return 0; + } if (r < 0) return r; @@ -810,7 +823,7 @@ int netdev_load(Manager *manager) { if (r < 0) return log_error_errno(r, "Failed to enumerate netdev files: %m"); - STRV_FOREACH_BACKWARDS(f, files) { + STRV_FOREACH(f, files) { r = netdev_load_one(manager, *f); if (r < 0) return r;