Blame SOURCES/0051-debug-don-t-write-newlines-to-memfd.patch

d5c737
From f9797c91e190fc53ce997beb1e7c2a140abfd665 Mon Sep 17 00:00:00 2001
d5c737
From: Peter Jones <pjones@redhat.com>
d5c737
Date: Tue, 15 Oct 2019 16:27:39 -0400
d5c737
Subject: [PATCH 51/63] debug(): don't write newlines to memfd
d5c737
d5c737
If we know our log will only be seen by strace, the newlines don't add
d5c737
anything to the strings but clutter.
d5c737
d5c737
Signed-off-by: Peter Jones <pjones@redhat.com>
d5c737
---
d5c737
 src/error.c | 16 ++++++++++++++--
d5c737
 1 file changed, 14 insertions(+), 2 deletions(-)
d5c737
d5c737
diff --git a/src/error.c b/src/error.c
d5c737
index 083de15e984..8ceba31dd55 100644
d5c737
--- a/src/error.c
d5c737
+++ b/src/error.c
d5c737
@@ -27,6 +27,7 @@
d5c737
 #include <stdio.h>
d5c737
 #include <string.h>
d5c737
 #include <sys/mman.h>
d5c737
+#include <sys/random.h>
d5c737
 #include <unistd.h>
d5c737
 
d5c737
 #include "efiboot.h"
d5c737
@@ -166,6 +167,7 @@ efi_error_pop(void)
d5c737
 static int efi_verbose;
d5c737
 static FILE *efi_errlog, *efi_dbglog;
d5c737
 static int efi_dbglog_fd = -1;
d5c737
+static intptr_t efi_dbglog_cookie;
d5c737
 static int log_level;
d5c737
 static char efi_dbglog_buf[4096];
d5c737
 
d5c737
@@ -176,7 +178,7 @@ efi_set_loglevel(int level)
d5c737
 }
d5c737
 
d5c737
 static ssize_t
d5c737
-dbglog_write(void *cookie UNUSED, const char *buf, size_t size)
d5c737
+dbglog_write(void *cookie, const char *buf, size_t size)
d5c737
 {
d5c737
 	FILE *log = efi_errlog ? efi_errlog : stderr;
d5c737
 	ssize_t ret = size;
d5c737
@@ -185,6 +187,11 @@ dbglog_write(void *cookie UNUSED, const char *buf, size_t size)
d5c737
 		ret = fwrite(buf, 1, size, log);
d5c737
 	} else if (efi_dbglog_fd >= 0) {
d5c737
 		lseek(efi_dbglog_fd, 0, SEEK_SET);
d5c737
+		if ((intptr_t)cookie != 0 &&
d5c737
+		    (intptr_t)cookie == efi_dbglog_cookie &&
d5c737
+		    size > 0 &&
d5c737
+		    buf[size-1] == '\n')
d5c737
+			size -= 1;
d5c737
 		ret = write(efi_dbglog_fd, buf, size);
d5c737
 	}
d5c737
 	return ret;
d5c737
@@ -248,6 +255,7 @@ efi_error_fini(void)
d5c737
 static void CONSTRUCTOR
d5c737
 efi_error_init(void)
d5c737
 {
d5c737
+	ssize_t bytes;
d5c737
 	cookie_io_functions_t io_funcs = {
d5c737
 		.write = dbglog_write,
d5c737
 		.seek = dbglog_seek,
d5c737
@@ -258,7 +266,11 @@ efi_error_init(void)
d5c737
 	if (efi_dbglog_fd == -1)
d5c737
 		return;
d5c737
 
d5c737
-	efi_dbglog = fopencookie(NULL, "a", io_funcs);
d5c737
+	bytes = getrandom(&efi_dbglog_cookie, sizeof(efi_dbglog_cookie), 0);
d5c737
+	if (bytes < (ssize_t)sizeof(efi_dbglog_cookie))
d5c737
+		efi_dbglog_cookie = 0;
d5c737
+
d5c737
+	efi_dbglog = fopencookie((void *)efi_dbglog_cookie, "a", io_funcs);
d5c737
 	if (efi_dbglog)
d5c737
 		setvbuf(efi_dbglog, efi_dbglog_buf, _IOLBF,
d5c737
 			sizeof(efi_dbglog_buf));
d5c737
-- 
d5c737
2.26.2
d5c737