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 e928536af794bc38036913df0d642b02e2e4232f..3e1b3f174bc9c4e828a2f01c9dc36b06cb81c19c 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 5016390443902fb5c01e86db5994c49a3f908c4e..88719e043b3eefad0452051673e4328c059a9b9f 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 2d5861c4e9de08fa95cbd538529c8e5ea90eec1d..f71418d9e05fe5df9ed41cddd277bd56410d44db 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 800c61612b799a9b81f0989ae918a415f5cd0154..f9f24954fc559f6dbe2212d8ccee4ebf6c7151bd 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;
        }