From 5b5cd144f3187f4208c6c9430c9752a4c5cdd415 Mon Sep 17 00:00:00 2001 From: Chris Phillips Date: Tue, 29 Oct 2013 16:30:25 +0000 Subject: [PATCH] =?utf8?q?ShellPkg:=20Properly=20set=20lasterror=20environ?= =?utf8?q?ment=20variable=20-=20Set=20lasterror=20value=20based=20on=20pla?= =?utf8?q?tform=20width=20-=20Use=20=E2=80=9Clasterror=E2=80=9D=20rather?= =?utf8?q?=20than=20=E2=80=9CLasterror=E2=80=9D=20for=20variable=20name=20?= =?utf8?q?to=20match=20Shell=20Specification=20-=20Set=20lasterror=20value?= =?utf8?q?=20when=20a=20binary=20or=20script=20file=20is=20not=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Chris Phillips Reviewed-by: Jaben Carsey git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14816 6f19259b-4bc3-4df7-8a09-765794883524 --- ShellPkg/Application/Shell/Shell.c | 38 +++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index e5a648833d..0ce1665d84 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -1593,10 +1593,15 @@ RunCommand( if (!EFI_ERROR(Status)) { Status = ShellCommandRunCommandHandler(ShellInfoObject.NewShellParametersProtocol->Argv[0], &ShellStatus, &LastError); ASSERT_EFI_ERROR(Status); - UnicodeSPrint(LeString, sizeof(LeString), L"0x%08Lx", ShellStatus); - DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE);); + + if (sizeof(EFI_STATUS) == sizeof(UINT64)) { + UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellStatus); + } else { + UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", ShellStatus); + } + DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE);); if (LastError) { - InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE); + InternalEfiShellSetEnv(L"lasterror", LeString, TRUE); } // // Pass thru the exitcode from the app. @@ -1622,6 +1627,14 @@ RunCommand( } if (CommandWithPath == NULL || ShellIsDirectory(CommandWithPath) == EFI_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, ShellInfoObject.NewShellParametersProtocol->Argv[0]); + + if (sizeof(EFI_STATUS) == sizeof(UINT64)) { + UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", EFI_NOT_FOUND); + } else { + UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", EFI_NOT_FOUND); + } + DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE);); + InternalEfiShellSetEnv(L"lasterror", LeString, TRUE); } else { // // Check if it's a NSH (script) file. @@ -1642,11 +1655,15 @@ RunCommand( ); // - // Updatet last error status. + // Update last error status. // - UnicodeSPrint(LeString, sizeof(LeString), L"0x%08Lx", StatusCode); - DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE);); - InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE); + if (sizeof(EFI_STATUS) == sizeof(UINT64)) { + UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", StatusCode); + } else { + UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", StatusCode); + } + DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE);); + InternalEfiShellSetEnv(L"lasterror", LeString, TRUE); } } } @@ -1952,9 +1969,12 @@ RunScriptFileHandle ( } if (ShellCommandGetScriptExit()) { + // + // ShellCommandGetExitCode() always returns a UINT64 + // UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode()); - DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE);); - InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE); + DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE);); + InternalEfiShellSetEnv(L"lasterror", LeString, TRUE); ShellCommandRegisterExit(FALSE, 0); Status = EFI_SUCCESS; -- 2.39.2