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

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