Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 00c551e2 authored by sanketk's avatar sanketk Committed by Steve Kondik
Browse files

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
parent 64caba3c
Loading
Loading
Loading
Loading
+22 −15
Original line number Diff line number Diff line
@@ -597,23 +597,26 @@ int ifc_disable(const char *ifname)
int ifc_reset_connections(const char *ifname, const int reset_mask)
{
#ifdef HAVE_ANDROID_OS
    int result, success;
    int result = 0, success;
    in_addr_t myaddr = 0;
    struct ifreq ifr;
    struct in6_ifreq ifr6;
    int ctl_sock = -1;

    if (reset_mask & RESET_IPV4_ADDRESSES) {
        /* IPv4. Clear connections on the IP address. */
        ifc_init();
        ctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
        if (ctl_sock >= 0) {
            if (!(reset_mask & RESET_IGNORE_INTERFACE_ADDRESS)) {
                ifc_get_info(ifname, &myaddr, NULL, NULL);
            }
            ifc_init_ifr(ifname, &ifr);
            init_sockaddr_in(&ifr.ifr_addr, myaddr);
        result = ioctl(ifc_ctl_sock, SIOCKILLADDR,  &ifr);
        ifc_close();
            result = ioctl(ctl_sock, SIOCKILLADDR,  &ifr);
            close(ctl_sock);
        } else {
        result = 0;
            result = -1;
        }
    }

    if (reset_mask & RESET_IPV6_ADDRESSES) {
@@ -623,14 +626,18 @@ int ifc_reset_connections(const char *ifname, const int reset_mask)
         * So we clear all unused IPv6 connections on the device by specifying an
         * empty IPv6 address.
         */
        ifc_init6();
        ctl_sock = socket(AF_INET6, SOCK_DGRAM, 0);
        // This implicitly specifies an address of ::, i.e., kill all IPv6 sockets.
        memset(&ifr6, 0, sizeof(ifr6));
        success = ioctl(ifc_ctl_sock6, SIOCKILLADDR,  &ifr6);
        if (ctl_sock >= 0) {
            success = ioctl(ctl_sock, SIOCKILLADDR,  &ifr6);
            if (result == 0) {
                result = success;
            }
        ifc_close6();
            close(ctl_sock);
        } else {
            result = -1;
        }
    }

    return result;