Blame SOURCES/0015-RH-fix-output-buffer.patch

f20720
---
f20720
 libmultipath/print.c |   31 +++++++++++++++++++++++++++----
f20720
 1 file changed, 27 insertions(+), 4 deletions(-)
f20720
f20720
Index: multipath-tools-130222/libmultipath/print.c
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/libmultipath/print.c
f20720
+++ multipath-tools-130222/libmultipath/print.c
f20720
@@ -8,6 +8,8 @@
f20720
 #include <sys/stat.h>
f20720
 #include <dirent.h>
f20720
 #include <unistd.h>
f20720
+#include <string.h>
f20720
+#include <errno.h>
f20720
 
f20720
 #include "checkers.h"
f20720
 #include "vector.h"
f20720
@@ -24,6 +26,7 @@
f20720
 #include "switchgroup.h"
f20720
 #include "devmapper.h"
f20720
 #include "uevent.h"
f20720
+#include "debug.h"
f20720
 
f20720
 #define MAX(x,y) (x > y) ? x : y
f20720
 #define TAIL     (line + len - 1 - c)
f20720
@@ -754,12 +757,32 @@ snprint_pathgroup (char * line, int len,
f20720
 extern void
f20720
 print_multipath_topology (struct multipath * mpp, int verbosity)
f20720
 {
f20720
-	char buff[MAX_LINE_LEN * MAX_LINES] = {};
f20720
+	int resize;
f20720
+	char *buff = NULL;
f20720
+	char *old = NULL;
f20720
+	int len, maxlen = MAX_LINE_LEN * MAX_LINES;
f20720
 
f20720
-	memset(&buff[0], 0, MAX_LINE_LEN * MAX_LINES);
f20720
-	snprint_multipath_topology(&buff[0], MAX_LINE_LEN * MAX_LINES,
f20720
-				   mpp, verbosity);
f20720
+	buff = MALLOC(maxlen);
f20720
+	do {
f20720
+		if (!buff) {
f20720
+			if (old)
f20720
+				FREE(old);
f20720
+			condlog(0, "couldn't allocate memory for list: %s\n",
f20720
+				strerror(errno));
f20720
+			return;
f20720
+		}
f20720
+
f20720
+		len = snprint_multipath_topology(buff, maxlen, mpp, verbosity);
f20720
+		resize = (len == maxlen - 1);
f20720
+
f20720
+		if (resize) {
f20720
+			maxlen *= 2;
f20720
+			old = buff;
f20720
+			buff = REALLOC(buff, maxlen);
f20720
+		}
f20720
+	} while (resize);
f20720
 	printf("%s", buff);
f20720
+	FREE(buff);
f20720
 }
f20720
 
f20720
 extern int