]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Properly set lasterror environment variable
authorChris Phillips <chrisp@hp.com>
Tue, 29 Oct 2013 16:30:25 +0000 (16:30 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 29 Oct 2013 16:30:25 +0000 (16:30 +0000)
- Set lasterror value based on platform width
- Use “lasterror” rather than “Lasterror” for variable name to match Shell Specification
- Set lasterror value when a binary or script file is not found

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chris Phillips <chrisp@hp.com>
Reviewed-by: Jaben Carsey <Jaben.Carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14816 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/Shell/Shell.c

index e5a648833d4d635fa6a3126708811ed03b2340ae..0ce1665d84577f6c4b443ac7c941fa9be0078783 100644 (file)
@@ -1593,10 +1593,15 @@ RunCommand(
         if (!EFI_ERROR(Status))  {\r
           Status = ShellCommandRunCommandHandler(ShellInfoObject.NewShellParametersProtocol->Argv[0], &ShellStatus, &LastError);\r
           ASSERT_EFI_ERROR(Status);\r
-          UnicodeSPrint(LeString, sizeof(LeString), L"0x%08Lx", ShellStatus);\r
-          DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE););\r
+\r
+          if (sizeof(EFI_STATUS) == sizeof(UINT64)) {\r
+            UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellStatus);\r
+          } else {\r
+            UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", ShellStatus);\r
+          }\r
+          DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r
           if (LastError) {\r
-            InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);\r
+            InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r
           }\r
           //\r
           // Pass thru the exitcode from the app.\r
@@ -1622,6 +1627,14 @@ RunCommand(
         }\r
         if (CommandWithPath == NULL || ShellIsDirectory(CommandWithPath) == EFI_SUCCESS) {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, ShellInfoObject.NewShellParametersProtocol->Argv[0]);\r
+\r
+          if (sizeof(EFI_STATUS) == sizeof(UINT64)) {\r
+            UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", EFI_NOT_FOUND);\r
+          } else {\r
+            UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", EFI_NOT_FOUND);\r
+          }\r
+          DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r
+          InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r
         } else {\r
           //\r
           // Check if it's a NSH (script) file.\r
@@ -1642,11 +1655,15 @@ RunCommand(
              );\r
 \r
             //\r
-            // Updatet last error status.\r
+            // Update last error status.\r
             //\r
-            UnicodeSPrint(LeString, sizeof(LeString), L"0x%08Lx", StatusCode);\r
-            DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE););\r
-            InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);\r
+            if (sizeof(EFI_STATUS) == sizeof(UINT64)) {\r
+              UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", StatusCode);\r
+            } else {\r
+              UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", StatusCode);\r
+            }\r
+            DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r
+            InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r
           }\r
         }\r
       }\r
@@ -1952,9 +1969,12 @@ RunScriptFileHandle (
         }\r
 \r
         if (ShellCommandGetScriptExit()) {\r
+          //\r
+          // ShellCommandGetExitCode() always returns a UINT64\r
+          //\r
           UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode());\r
-          DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE););\r
-          InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);\r
+          DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r
+          InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r
 \r
           ShellCommandRegisterExit(FALSE, 0);\r
           Status = EFI_SUCCESS;\r