system/corennnnn
修订版 | c8ffed3a5bd7e27bccd0dd041c6cb6e9f909797c (tree) |
---|---|
时间 | 2016-08-24 23:11:33 |
作者 | Devi Sandeep Endluri V V <dendluri@code...> |
Commiter | Linux Build Service Account |
Don't use global variable in libnetutils.
In netd, both CommandListener and NetlinkHandler thread will use
libnetutils' function. Original implementation will use a global
file descriptor in mutiple functions. It will cause problems when
these functions are invoked from different thread.
This change will make NetlinkHandler thread use local file
descriptor instead of global one.
CRs-fixed: 853158
Change-Id: I66458e99e48197e7a56cbb212344423290db12bd
@@ -625,23 +625,26 @@ int ifc_disable(const char *ifname) | ||
625 | 625 | int ifc_reset_connections(const char *ifname, const int reset_mask) |
626 | 626 | { |
627 | 627 | #if defined(__ANDROID__) |
628 | - int result, success; | |
628 | + int result = 0, success; | |
629 | 629 | in_addr_t myaddr = 0; |
630 | 630 | struct ifreq ifr; |
631 | 631 | struct in6_ifreq ifr6; |
632 | + int ctl_sock = -1; | |
632 | 633 | |
633 | 634 | if (reset_mask & RESET_IPV4_ADDRESSES) { |
634 | 635 | /* IPv4. Clear connections on the IP address. */ |
635 | - ifc_init(); | |
636 | - if (!(reset_mask & RESET_IGNORE_INTERFACE_ADDRESS)) { | |
637 | - ifc_get_info(ifname, &myaddr, NULL, NULL); | |
636 | + ctl_sock = socket(AF_INET, SOCK_DGRAM, 0); | |
637 | + if (ctl_sock >= 0) { | |
638 | + if (!(reset_mask & RESET_IGNORE_INTERFACE_ADDRESS)) { | |
639 | + ifc_get_info(ifname, &myaddr, NULL, NULL); | |
640 | + } | |
641 | + ifc_init_ifr(ifname, &ifr); | |
642 | + init_sockaddr_in(&ifr.ifr_addr, myaddr); | |
643 | + result = ioctl(ctl_sock, SIOCKILLADDR, &ifr); | |
644 | + close(ctl_sock); | |
645 | + } else { | |
646 | + result = -1; | |
638 | 647 | } |
639 | - ifc_init_ifr(ifname, &ifr); | |
640 | - init_sockaddr_in(&ifr.ifr_addr, myaddr); | |
641 | - result = ioctl(ifc_ctl_sock, SIOCKILLADDR, &ifr); | |
642 | - ifc_close(); | |
643 | - } else { | |
644 | - result = 0; | |
645 | 648 | } |
646 | 649 | |
647 | 650 | if (reset_mask & RESET_IPV6_ADDRESSES) { |
@@ -651,14 +654,18 @@ int ifc_reset_connections(const char *ifname, const int reset_mask) | ||
651 | 654 | * So we clear all unused IPv6 connections on the device by specifying an |
652 | 655 | * empty IPv6 address. |
653 | 656 | */ |
654 | - ifc_init6(); | |
657 | + ctl_sock = socket(AF_INET6, SOCK_DGRAM, 0); | |
655 | 658 | // This implicitly specifies an address of ::, i.e., kill all IPv6 sockets. |
656 | 659 | memset(&ifr6, 0, sizeof(ifr6)); |
657 | - success = ioctl(ifc_ctl_sock6, SIOCKILLADDR, &ifr6); | |
658 | - if (result == 0) { | |
659 | - result = success; | |
660 | + if (ctl_sock >= 0) { | |
661 | + success = ioctl(ctl_sock, SIOCKILLADDR, &ifr6); | |
662 | + if (result == 0) { | |
663 | + result = success; | |
664 | + } | |
665 | + close(ctl_sock); | |
666 | + } else { | |
667 | + result = -1; | |
660 | 668 | } |
661 | - ifc_close6(); | |
662 | 669 | } |
663 | 670 | |
664 | 671 | return result; |