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

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