Message ID | 1438856324-24231-1-git-send-email-stuart.haslam@linaro.org |
---|---|
State | Accepted |
Commit | b81c7d800ac35866553779743ec766f69cc9f8c2 |
Headers | show |
Merged, Maxim. On 08/06/15 13:18, Stuart Haslam wrote: > errno must be stored immediately after the failure to avoid it being > overwritten by the ODP_ERR() call. > > Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org> > --- > platform/linux-generic/pktio/socket.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c > index 202608a..55c3594 100644 > --- a/platform/linux-generic/pktio/socket.c > +++ b/platform/linux-generic/pktio/socket.c > @@ -207,6 +207,7 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, > > sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); > if (sockfd == -1) { > + __odp_errno = errno; > ODP_ERR("socket(): %s\n", strerror(errno)); > goto error; > } > @@ -217,6 +218,7 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, > snprintf(ethreq.ifr_name, IF_NAMESIZE, "%s", netdev); > err = ioctl(sockfd, SIOCGIFINDEX, ðreq); > if (err != 0) { > + __odp_errno = errno; > ODP_ERR("ioctl(SIOCGIFINDEX): %s: \"%s\".\n", strerror(errno), > ethreq.ifr_name); > goto error; > @@ -228,6 +230,7 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, > snprintf(ethreq.ifr_name, IF_NAMESIZE, "%s", netdev); > err = ioctl(sockfd, SIOCGIFHWADDR, ðreq); > if (err != 0) { > + __odp_errno = errno; > ODP_ERR("ioctl(SIOCGIFHWADDR): %s\n", strerror(errno)); > goto error; > } > @@ -240,6 +243,7 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, > sa_ll.sll_ifindex = if_idx; > sa_ll.sll_protocol = htons(ETH_P_ALL); > if (bind(sockfd, (struct sockaddr *)&sa_ll, sizeof(sa_ll)) < 0) { > + __odp_errno = errno; > ODP_ERR("bind(to IF): %s\n", strerror(errno)); > goto error; > } > @@ -247,7 +251,6 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, > return 0; > > error: > - __odp_errno = errno; > sock_close(pktio_entry); > > return -1;
diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index 202608a..55c3594 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -207,6 +207,7 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); if (sockfd == -1) { + __odp_errno = errno; ODP_ERR("socket(): %s\n", strerror(errno)); goto error; } @@ -217,6 +218,7 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, snprintf(ethreq.ifr_name, IF_NAMESIZE, "%s", netdev); err = ioctl(sockfd, SIOCGIFINDEX, ðreq); if (err != 0) { + __odp_errno = errno; ODP_ERR("ioctl(SIOCGIFINDEX): %s: \"%s\".\n", strerror(errno), ethreq.ifr_name); goto error; @@ -228,6 +230,7 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, snprintf(ethreq.ifr_name, IF_NAMESIZE, "%s", netdev); err = ioctl(sockfd, SIOCGIFHWADDR, ðreq); if (err != 0) { + __odp_errno = errno; ODP_ERR("ioctl(SIOCGIFHWADDR): %s\n", strerror(errno)); goto error; } @@ -240,6 +243,7 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, sa_ll.sll_ifindex = if_idx; sa_ll.sll_protocol = htons(ETH_P_ALL); if (bind(sockfd, (struct sockaddr *)&sa_ll, sizeof(sa_ll)) < 0) { + __odp_errno = errno; ODP_ERR("bind(to IF): %s\n", strerror(errno)); goto error; } @@ -247,7 +251,6 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, return 0; error: - __odp_errno = errno; sock_close(pktio_entry); return -1;
errno must be stored immediately after the failure to avoid it being overwritten by the ODP_ERR() call. Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org> --- platform/linux-generic/pktio/socket.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)