efi-boot-shim/errlog.c
Hans de Goede 1fe31ee1b4 console: Add console_print and console_print_at helpers
This is a preparation commit for removing the setup_console(1) calls from
MokManager and shim so that we don't force the EFI console to switch to
text-mode.

This commit replaces all direct calls to Print / PrintAt with calls to
the new helpers (no functional changes) so that we can delay calling
setup_console(1) till the first Print call in a follow-up patch.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2018-03-12 18:00:41 -04:00

87 lines
1.6 KiB
C

/*
* errlog.c
* Copyright 2017 Peter Jones <pjones@redhat.com>
*
* Distributed under terms of the GPLv3 license.
*/
#include "shim.h"
static CHAR16 **errs = NULL;
static UINTN nerrs = 0;
EFI_STATUS
VLogError(const char *file, int line, const char *func, CHAR16 *fmt, va_list args)
{
va_list args2;
UINTN size = 0, size2;
CHAR16 **newerrs;
size = SPrint(NULL, 0, L"%a:%d %a() ", file, line, func);
va_copy(args2, args);
size2 = VSPrint(NULL, 0, fmt, args2);
va_end(args2);
newerrs = ReallocatePool(errs, (nerrs + 1) * sizeof(*errs),
(nerrs + 3) * sizeof(*errs));
if (!newerrs)
return EFI_OUT_OF_RESOURCES;
newerrs[nerrs] = AllocatePool(size*2+2);
if (!newerrs[nerrs])
return EFI_OUT_OF_RESOURCES;
newerrs[nerrs+1] = AllocatePool(size2*2+2);
if (!newerrs[nerrs+1])
return EFI_OUT_OF_RESOURCES;
SPrint(newerrs[nerrs], size*2+2, L"%a:%d %a() ", file, line, func);
va_copy(args2, args);
VSPrint(newerrs[nerrs+1], size2*2+2, fmt, args2);
va_end(args2);
nerrs += 2;
newerrs[nerrs] = NULL;
errs = newerrs;
return EFI_SUCCESS;
}
EFI_STATUS
LogError_(const char *file, int line, const char *func, CHAR16 *fmt, ...)
{
va_list args;
EFI_STATUS efi_status;
va_start(args, fmt);
efi_status = VLogError(file, line, func, fmt, args);
va_end(args);
return efi_status;
}
VOID
PrintErrors(VOID)
{
UINTN i;
if (!verbose)
return;
for (i = 0; i < nerrs; i++)
console_print(L"%s", errs[i]);
}
VOID
ClearErrors(VOID)
{
UINTN i;
for (i = 0; i < nerrs; i++)
FreePool(errs[i]);
FreePool(errs);
nerrs = 0;
errs = NULL;
}
// vim:fenc=utf-8:tw=75