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

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