summaryrefslogtreecommitdiff
path: root/lib/netdev-linux.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2010-01-15 14:06:15 -0800
committerBen Pfaff <blp@nicira.com>2010-01-15 15:35:38 -0800
commit88258e0034cc7ca6ffde0974f1fb92d26289ad6a (patch)
treef1cff1693817e85d2ff5cdb4b33c8f03fdaf8fea /lib/netdev-linux.c
parentf3ac83df5c4fec3f27a9c8f95ef2753a26c65d24 (diff)
downloadopenvswitch-88258e0034cc7ca6ffde0974f1fb92d26289ad6a.tar.gz
netdev-linux: Don't close(0) when closing an ordinary netdev.
Calling close(0) at random points is bad. It means that the next call to socket() or open() returns fd 0. Then the next time a netdev gets closed, that socket or file fd gets closed too, and you end up with weird "Bad file descriptor" errors. Found by installing the following as lib/unistd.h in the source tree: #ifndef UNISTD_H #define UNISTD_H 1 #include <stdlib.h> #include_next <unistd.h> #undef close #define close(fd) rpl_close(fd) static inline int rpl_close(int fd) { if (!fd) { abort(); } return (close)(fd); } #endif
Diffstat (limited to 'lib/netdev-linux.c')
-rw-r--r--lib/netdev-linux.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 4f6b20b27..d45349b29 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -821,7 +821,6 @@ netdev_linux_open(struct netdev_dev *netdev_dev_, int ethertype,
if (!strcmp(netdev_dev_get_type(netdev_dev_), "tap")) {
netdev->fd = netdev_dev->state.tap.fd;
-
} else if (ethertype != NETDEV_ETH_TYPE_NONE) {
struct sockaddr_ll sll;
int protocol;
@@ -869,6 +868,8 @@ netdev_linux_open(struct netdev_dev *netdev_dev_, int ethertype,
if (error) {
goto error;
}
+ } else {
+ netdev->fd = -1;
}
*netdevp = &netdev->netdev;