Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 130701790bf2d95e902edf16031ff596 > files > 276

autofs-5.0.1-0.rc2.164.el5_8.src.rpm

autofs-5.0.3 - fix ifc buff size fix 2

From: Ian Kent <raven@themaw.net>

For the case of a large number of interfaces there can be
a lot of malloc(3)s for every mount which could slow things
down. So we remember the maximum allocation size and use it
in subsequent allocations.
---

 modules/replicated.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)


diff --git a/modules/replicated.c b/modules/replicated.c
index 35a6675..b435f4b 100644
--- a/modules/replicated.c
+++ b/modules/replicated.c
@@ -62,7 +62,10 @@
 #ifndef MAX_ERR_BUF
 #define MAX_ERR_BUF		512
 #endif
+
 #define MAX_IFC_BUF		2048
+static int volatile ifc_buf_len = MAX_IFC_BUF;
+static int volatile ifc_last_len = 0;
 
 #define MASK_A  0x7F000000
 #define MASK_B  0xBFFF0000
@@ -97,7 +100,7 @@ void seed_random(void)
 
 static int alloc_ifreq(struct ifconf *ifc, int sock)
 {
-	int ret, lastlen = 0, len = MAX_IFC_BUF;
+	int ret, lastlen = ifc_last_len, len = ifc_buf_len;
 	char err_buf[MAX_ERR_BUF], *buf;
 
 	while (1) {
@@ -119,7 +122,7 @@ static int alloc_ifreq(struct ifconf *ifc, int sock)
 			return 0;
 		}
 
-		if (ifc->ifc_len == lastlen)
+		if (ifc->ifc_len <= lastlen)
 			break;
 
 		lastlen = ifc->ifc_len;
@@ -127,6 +130,11 @@ static int alloc_ifreq(struct ifconf *ifc, int sock)
 		free(buf);
 	}
 
+	if (lastlen != ifc_last_len) {
+		ifc_last_len = lastlen;
+		ifc_buf_len = len;
+	}
+
 	return 1;
 }