chiark / gitweb /
networkd: netdev - introduce LINGER state and netdev_drop()
authorTom Gundersen <teg@jklm.no>
Thu, 8 May 2014 18:42:22 +0000 (20:42 +0200)
committerTom Gundersen <teg@jklm.no>
Fri, 9 May 2014 12:41:27 +0000 (14:41 +0200)
We need the LINGER state in case we still have references to the netdev after it has been dropped.

src/network/networkd-netdev.c
src/network/networkd.h

index ed4bc191f35e580862eaa8218feaa6897eeb0d51..c7bec74aa36fd5a8a875eb259bd30ea53767312b 100644 (file)
@@ -108,6 +108,19 @@ NetDev *netdev_ref(NetDev *netdev) {
         return netdev;
 }
 
+void netdev_drop(NetDev *netdev) {
+        if (!netdev || netdev->state == NETDEV_STATE_LINGER)
+                return;
+
+        netdev->state = NETDEV_STATE_LINGER;
+
+        netdev_cancel_callbacks(netdev);
+
+        netdev_unref(netdev);
+
+        return;
+}
+
 int netdev_get(Manager *manager, const char *name, NetDev **ret) {
         NetDev *netdev;
 
index cff0136bcce176ccddfc464d3506494d7b3cb682..bdf9808721625f4763cfcf7b1316baf6f05cf163 100644 (file)
@@ -76,6 +76,7 @@ typedef enum NetDevState {
         NETDEV_STATE_FAILED,
         NETDEV_STATE_CREATING,
         NETDEV_STATE_READY,
+        NETDEV_STATE_LINGER,
         _NETDEV_STATE_MAX,
         _NETDEV_STATE_INVALID = -1,
 } NetDevState;
@@ -271,6 +272,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
 /* NetDev */
 
 int netdev_load(Manager *manager);
+void netdev_drop(NetDev *netdev);
 
 NetDev *netdev_unref(NetDev *netdev);
 NetDev *netdev_ref(NetDev *netdev);