treewide: initialize properly file descriptors
authorHans Dedecker <dedeckeh@gmail.com>
Thu, 4 Apr 2019 10:01:46 +0000 (12:01 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Thu, 4 Apr 2019 13:36:15 +0000 (15:36 +0200)
Initialzie properly the dhcpv6, dhcpv4 and ndp ffile descriptors
when creating an interface.
As such the check for a valid descriptor can be done correct now
in the different modules

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/config.c
src/dhcpv4.c
src/dhcpv6.c
src/ndp.c

index e928536..3e1b3f1 100644 (file)
@@ -430,6 +430,9 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
 
                iface->name = strcpy(new_name, name);
                iface->avl.key = iface->name;
+               iface->dhcpv6_event.uloop.fd = -1;
+               iface->ndp_event.uloop.fd = -1;
+               iface->dhcpv4_event.uloop.fd = -1;
                set_interface_defaults(iface);
 
                avl_insert(&interfaces, &iface->avl);
index 5016390..88719e0 100644 (file)
@@ -73,7 +73,7 @@ int dhcpv4_setup_interface(struct interface *iface, bool enable)
 {
        int ret = 0;
 
-       if (iface->dhcpv4_event.uloop.fd > 0) {
+       if (iface->dhcpv4_event.uloop.fd >= 0) {
                uloop_fd_delete(&iface->dhcpv4_event.uloop);
                close(iface->dhcpv4_event.uloop.fd);
                iface->dhcpv4_event.uloop.fd = -1;
@@ -163,7 +163,7 @@ int dhcpv4_setup_interface(struct interface *iface, bool enable)
        }
 
 out:
-       if (ret < 0 && iface->dhcpv4_event.uloop.fd > 0) {
+       if (ret < 0 && iface->dhcpv4_event.uloop.fd >= 0) {
                close(iface->dhcpv4_event.uloop.fd);
                iface->dhcpv4_event.uloop.fd = -1;
        }
index 2d5861c..f71418d 100644 (file)
@@ -47,7 +47,7 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable)
 {
        int ret = 0;
 
-       if (iface->dhcpv6_event.uloop.fd > 0) {
+       if (iface->dhcpv6_event.uloop.fd >= 0) {
                uloop_fd_delete(&iface->dhcpv6_event.uloop);
                close(iface->dhcpv6_event.uloop.fd);
                iface->dhcpv6_event.uloop.fd = -1;
@@ -150,7 +150,7 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable)
        ret = dhcpv6_ia_setup_interface(iface, enable);
 
 out:
-       if (ret < 0 && iface->dhcpv6_event.uloop.fd > 0) {
+       if (ret < 0 && iface->dhcpv6_event.uloop.fd >= 0) {
                close(iface->dhcpv6_event.uloop.fd);
                iface->dhcpv6_event.uloop.fd = -1;
        }
index 800c616..f9f2495 100644 (file)
--- a/src/ndp.c
+++ b/src/ndp.c
@@ -103,7 +103,7 @@ int ndp_init(void)
        netlink_add_netevent_handler(&ndp_netevent_handler);
 
 out:
-       if (ret < 0 && ping_socket > 0) {
+       if (ret < 0 && ping_socket >= 0) {
                close(ping_socket);
                ping_socket = -1;
        }
@@ -125,7 +125,7 @@ int ndp_setup_interface(struct interface *iface, bool enable)
                goto out;
        }
 
-       if (iface->ndp_event.uloop.fd > 0) {
+       if (iface->ndp_event.uloop.fd >= 0) {
                uloop_fd_delete(&iface->ndp_event.uloop);
                close(iface->ndp_event.uloop.fd);
                iface->ndp_event.uloop.fd = -1;
@@ -203,7 +203,7 @@ int ndp_setup_interface(struct interface *iface, bool enable)
                netlink_dump_neigh_table(true);
 
  out:
-       if (ret < 0 && iface->ndp_event.uloop.fd > 0) {
+       if (ret < 0 && iface->ndp_event.uloop.fd >= 0) {
                close(iface->ndp_event.uloop.fd);
                iface->ndp_event.uloop.fd = -1;
        }