summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVijay Bellur <vijay@gluster.com>2010-12-07 06:53:49 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-12-07 04:33:06 -0800
commit64cdcbe39bcb8d52d0c6aa88ce5cd5f3d6062a9e (patch)
tree8089e6a8c12d60a610f79731c270259ac0a0864a
parente3232db35a20e5cfd68ab3fb0b7d0931c4cfb67d (diff)
mgmt/glusterd: Use a static buffer to perform ioctl with SIOCGIFCONF
Signed-off-by: Vijay Bellur <vijay@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 2163 (Can't create volume using 3.1.1qa11 on OpenSolaris 2009.6) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2163
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index e675581ed2c..e0dc706b2aa 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -128,8 +128,10 @@ glusterd_is_local_addr (char *hostname)
struct ifconf buf = {0,};
int sd = -1;
struct ifreq *ifr = NULL;
+ struct ifreq *ifr_end = NULL;
int32_t size = 0;
- int32_t num_req = 0;
+ char buff[1024] = {0,};
+ gf_boolean_t need_free = _gf_false;
ret = getaddrinfo (hostname, NULL, NULL, &result);
@@ -146,13 +148,12 @@ glusterd_is_local_addr (char *hostname)
}
- sd = socket (PF_UNIX, SOCK_DGRAM, 0);
+ sd = socket (AF_INET, SOCK_DGRAM, 0);
if (sd == -1)
goto out;
- buf.ifc_len = sizeof (struct ifreq);
- buf.ifc_req = GF_CALLOC (1, sizeof (struct ifreq),
- gf_gld_mt_ifreq);
+ buf.ifc_len = sizeof (buff);
+ buf.ifc_buf = buff;
size = buf.ifc_len;
ret = ioctl (sd, SIOCGIFCONF, &buf);
@@ -163,18 +164,21 @@ glusterd_is_local_addr (char *hostname)
while (size <= buf.ifc_len) {
size += sizeof (struct ifreq);
buf.ifc_len = size;
- buf.ifc_req = GF_REALLOC (buf.ifc_req, size);
+ if (need_free)
+ GF_FREE (buf.ifc_req);
+ buf.ifc_req = GF_CALLOC (1, size, gf_gld_mt_ifreq);
+ need_free = 1;
ret = ioctl (sd, SIOCGIFCONF, &buf);
if (ret) {
goto out;
}
}
+ ifr_end = (struct ifreq *)&buf.ifc_buf[buf.ifc_len];
+
for (res = result; res != NULL; res = res->ai_next) {
ifr = buf.ifc_req;
- num_req = size / sizeof (struct ifreq) - 1;
-
- while (num_req--) {
+ while (ifr < ifr_end) {
if ((ifr->ifr_addr.sa_family == res->ai_addr->sa_family)
&& (memcmp (&ifr->ifr_addr, res->ai_addr,
res->ai_addrlen) == 0)) {
@@ -192,7 +196,7 @@ out:
if (result)
freeaddrinfo (result);
- if (buf.ifc_req)
+ if (need_free)
GF_FREE (buf.ifc_req);
if (found)