• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

修订版c8ffed3a5bd7e27bccd0dd041c6cb6e9f909797c (tree)
时间2016-08-24 23:11:33
作者Devi Sandeep Endluri V V <dendluri@code...>
CommiterLinux Build Service Account

Log Message

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

更改概述

差异

--- a/libnetutils/ifc_utils.c
+++ b/libnetutils/ifc_utils.c
@@ -625,23 +625,26 @@ int ifc_disable(const char *ifname)
625625 int ifc_reset_connections(const char *ifname, const int reset_mask)
626626 {
627627 #if defined(__ANDROID__)
628- int result, success;
628+ int result = 0, success;
629629 in_addr_t myaddr = 0;
630630 struct ifreq ifr;
631631 struct in6_ifreq ifr6;
632+ int ctl_sock = -1;
632633
633634 if (reset_mask & RESET_IPV4_ADDRESSES) {
634635 /* 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;
638647 }
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;
645648 }
646649
647650 if (reset_mask & RESET_IPV6_ADDRESSES) {
@@ -651,14 +654,18 @@ int ifc_reset_connections(const char *ifname, const int reset_mask)
651654 * So we clear all unused IPv6 connections on the device by specifying an
652655 * empty IPv6 address.
653656 */
654- ifc_init6();
657+ ctl_sock = socket(AF_INET6, SOCK_DGRAM, 0);
655658 // This implicitly specifies an address of ::, i.e., kill all IPv6 sockets.
656659 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;
660668 }
661- ifc_close6();
662669 }
663670
664671 return result;