dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0011-tests-break-up-large-strings-for-PySys_WriteStdout.patch

069435
From c2b650ebe33a001b3bf19912b136dbbff5495600 Mon Sep 17 00:00:00 2001
069435
From: Frank Schaefer <kelledin@gmail.com>
069435
Date: Tue, 10 Jul 2018 20:21:02 -0500
069435
Subject: [PATCH 11/14] tests: break up large strings for PySys_WriteStdout()
069435
069435
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1656437
069435
Upstream: http://github.com/karelzak/util-linux/commit/8a12ab57755afc36546834f175ef0b9e9376ba59
069435
Signed-off-by: Karel Zak <kzak@redhat.com>
069435
---
069435
 libmount/python/fs.c | 56 ++++++++++++++++++++++++++++++++++----------
069435
 1 file changed, 43 insertions(+), 13 deletions(-)
069435
069435
diff --git a/libmount/python/fs.c b/libmount/python/fs.c
069435
index d6490d248..634a914ef 100644
069435
--- a/libmount/python/fs.c
069435
+++ b/libmount/python/fs.c
069435
@@ -63,32 +63,62 @@ static PyObject *Fs_get_devno(FsObject *self)
069435
 	return PyObjectResultInt(mnt_fs_get_devno(self->fs));
069435
 }
069435
 
069435
+static void _dump_debug_string(const char *lead, const char *s, char quote)
069435
+{
069435
+	/* PySys_WriteStdout() will automatically truncate any '%s' token
069435
+	 * longer than a certain length (documented as 1000 bytes, but we
069435
+	 * give ourselves some margin here just in case).  The only way I
069435
+	 * know to get around this is to print such strings in bite-sized
069435
+	 * chunks.
069435
+	 */
069435
+	static const unsigned int _PY_MAX_LEN = 900;
069435
+	static const char *_PY_MAX_LEN_FMT = "%.900s";
069435
+	unsigned int len;
069435
+
069435
+	if (lead != NULL)
069435
+		PySys_WriteStdout("%s", lead);
069435
+
069435
+	if (quote != 0)
069435
+		PySys_WriteStdout("%c", quote);
069435
+
069435
+	for (len = strlen(s); len > _PY_MAX_LEN; len -= _PY_MAX_LEN, s += _PY_MAX_LEN) 
069435
+		PySys_WriteStdout(_PY_MAX_LEN_FMT, s);
069435
+
069435
+	if (len > 0)
069435
+		PySys_WriteStdout(_PY_MAX_LEN_FMT, s);
069435
+
069435
+	if (quote != 0)
069435
+		PySys_WriteStdout("%c\n", quote);
069435
+	else
069435
+		PySys_WriteStdout("\n");
069435
+}
069435
+
069435
 #define Fs_print_debug_HELP "print_debug()\n\n"
069435
 static PyObject *Fs_print_debug(FsObject *self)
069435
 {
069435
 	PySys_WriteStdout("------ fs: %p\n", self->fs);
069435
-	PySys_WriteStdout("source: %s\n", mnt_fs_get_source(self->fs));
069435
-	PySys_WriteStdout("target: %s\n", mnt_fs_get_target(self->fs));
069435
-	PySys_WriteStdout("fstype: %s\n", mnt_fs_get_fstype(self->fs));
069435
+	_dump_debug_string("source: ", mnt_fs_get_source(self->fs), 0);
069435
+	_dump_debug_string("target: ", mnt_fs_get_target(self->fs), 0);
069435
+	_dump_debug_string("fstype: ", mnt_fs_get_fstype(self->fs), 0);
069435
 
069435
 	if (mnt_fs_get_options(self->fs))
069435
-		PySys_WriteStdout("optstr: %s\n", mnt_fs_get_options(self->fs));
069435
+		_dump_debug_string("optstr: ", mnt_fs_get_options(self->fs), 0);
069435
 	if (mnt_fs_get_vfs_options(self->fs))
069435
-		PySys_WriteStdout("VFS-optstr: %s\n", mnt_fs_get_vfs_options(self->fs));
069435
+		_dump_debug_string("VFS-optstr: ", mnt_fs_get_vfs_options(self->fs), 0);
069435
 	if (mnt_fs_get_fs_options(self->fs))
069435
-		PySys_WriteStdout("FS-opstr: %s\n", mnt_fs_get_fs_options(self->fs));
069435
+		_dump_debug_string("FS-opstr: ", mnt_fs_get_fs_options(self->fs), 0);
069435
 	if (mnt_fs_get_user_options(self->fs))
069435
-		PySys_WriteStdout("user-optstr: %s\n", mnt_fs_get_user_options(self->fs));
069435
+		_dump_debug_string("user-optstr: ", mnt_fs_get_user_options(self->fs), 0);
069435
 	if (mnt_fs_get_optional_fields(self->fs))
069435
-		PySys_WriteStdout("optional-fields: '%s'\n", mnt_fs_get_optional_fields(self->fs));
069435
+		_dump_debug_string("optional-fields: ", mnt_fs_get_optional_fields(self->fs), '\'');
069435
 	if (mnt_fs_get_attributes(self->fs))
069435
-		PySys_WriteStdout("attributes: %s\n", mnt_fs_get_attributes(self->fs));
069435
+		_dump_debug_string("attributes: ", mnt_fs_get_attributes(self->fs), 0);
069435
 
069435
 	if (mnt_fs_get_root(self->fs))
069435
-		PySys_WriteStdout("root:   %s\n", mnt_fs_get_root(self->fs));
069435
+		_dump_debug_string("root:   ", mnt_fs_get_root(self->fs), 0);
069435
 
069435
 	if (mnt_fs_get_swaptype(self->fs))
069435
-		PySys_WriteStdout("swaptype: %s\n", mnt_fs_get_swaptype(self->fs));
069435
+		_dump_debug_string("swaptype: ", mnt_fs_get_swaptype(self->fs), 0);
069435
 	if (mnt_fs_get_size(self->fs))
069435
 		PySys_WriteStdout("size: %jd\n", mnt_fs_get_size(self->fs));
069435
 	if (mnt_fs_get_usedsize(self->fs))
069435
@@ -97,7 +127,7 @@ static PyObject *Fs_print_debug(FsObject *self)
069435
 		PySys_WriteStdout("priority: %d\n", mnt_fs_get_priority(self->fs));
069435
 
069435
 	if (mnt_fs_get_bindsrc(self->fs))
069435
-		PySys_WriteStdout("bindsrc: %s\n", mnt_fs_get_bindsrc(self->fs));
069435
+		_dump_debug_string("bindsrc: ", mnt_fs_get_bindsrc(self->fs), 0);
069435
 	if (mnt_fs_get_freq(self->fs))
069435
 		PySys_WriteStdout("freq:   %d\n", mnt_fs_get_freq(self->fs));
069435
 	if (mnt_fs_get_passno(self->fs))
069435
@@ -112,7 +142,7 @@ static PyObject *Fs_print_debug(FsObject *self)
069435
 	if (mnt_fs_get_tid(self->fs))
069435
 		PySys_WriteStdout("tid:    %d\n", mnt_fs_get_tid(self->fs));
069435
 	if (mnt_fs_get_comment(self->fs))
069435
-		PySys_WriteStdout("comment: '%s'\n", mnt_fs_get_comment(self->fs));
069435
+		_dump_debug_string("comment: ", mnt_fs_get_comment(self->fs), '\'');
069435
 	return UL_IncRef(self);
069435
 }
069435
 /*
069435
-- 
069435
2.17.2
069435