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

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