Roll back check in r15180 which caused the shell always returns EFI_ABORTED no matter what exit-code is specified for "exit" command.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Carsey Jaben <jaben.carsey@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16127 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Ruiyu Ni 2014-09-18 01:58:03 +00:00 committed by niruiyu
parent 4b6b543e77
commit a308e0588b
4 changed files with 59 additions and 242 deletions

View File

@ -244,9 +244,6 @@ UefiMain (
UINTN Size; UINTN Size;
EFI_HANDLE ConInHandle; EFI_HANDLE ConInHandle;
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *OldConIn; EFI_SIMPLE_TEXT_INPUT_PROTOCOL *OldConIn;
UINTN ExitDataSize;
CHAR16 *ExitData;
SHELL_STATUS ExitStatus;
if (PcdGet8(PcdShellSupportLevel) > 3) { if (PcdGet8(PcdShellSupportLevel) > 3) {
return (EFI_UNSUPPORTED); return (EFI_UNSUPPORTED);
@ -300,12 +297,6 @@ UefiMain (
// install our console logger. This will keep a log of the output for back-browsing // install our console logger. This will keep a log of the output for back-browsing
// //
Status = ConsoleLoggerInstall(ShellInfoObject.LogScreenCount, &ShellInfoObject.ConsoleInfo); Status = ConsoleLoggerInstall(ShellInfoObject.LogScreenCount, &ShellInfoObject.ConsoleInfo);
if(EFI_ERROR (Status)) {
ExitStatus = (SHELL_STATUS) (Status & (~MAX_BIT));
} else {
ExitStatus = SHELL_SUCCESS;
}
if (!EFI_ERROR(Status)) { if (!EFI_ERROR(Status)) {
// //
// Enable the cursor to be visible // Enable the cursor to be visible
@ -419,7 +410,7 @@ UefiMain (
// Display the mapping // Display the mapping
// //
if (PcdGet8(PcdShellSupportLevel) >= 2 && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) { if (PcdGet8(PcdShellSupportLevel) >= 2 && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) {
Status = RunCommand(L"map", NULL); Status = RunCommand(L"map");
ASSERT_EFI_ERROR(Status); ASSERT_EFI_ERROR(Status);
} }
@ -485,11 +476,7 @@ UefiMain (
// //
// process the startup script or launch the called app. // process the startup script or launch the called app.
// //
Status = DoStartupScript( Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);
ShellInfoObject.ImageDevPath,
ShellInfoObject.FileDevPath,
&ExitStatus
);
} }
if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit && !ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) { if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit && !ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {
@ -523,7 +510,6 @@ UefiMain (
// //
Status = DoShellPrompt(); Status = DoShellPrompt();
} while (!ShellCommandGetExit()); } while (!ShellCommandGetExit());
ExitStatus = (SHELL_STATUS) ShellCommandGetExitCode();
} }
if (OldConIn != NULL && ConInHandle != NULL) { if (OldConIn != NULL && ConInHandle != NULL) {
CloseSimpleTextInOnFile (gST->ConIn); CloseSimpleTextInOnFile (gST->ConIn);
@ -595,33 +581,10 @@ FreeResources:
DEBUG_CODE(ShellInfoObject.ConsoleInfo = NULL;); DEBUG_CODE(ShellInfoObject.ConsoleInfo = NULL;);
} }
if (!EFI_ERROR (Status)) { if (ShellCommandGetExit()) {
// If the command exited with an error, we pass this error out in the ExitData return ((EFI_STATUS)ShellCommandGetExitCode());
// so that it can be retrieved by the EfiShellExecute function (which may
// start the shell with gBS->StartImage)
if (ExitStatus != SHELL_SUCCESS) {
// Allocate a buffer for exit data to pass to gBS->Exit().
// This buffer will contain the empty string immediately followed by
// the shell's exit status. (The empty string is required by the UEFI spec)
ExitDataSize = (sizeof (CHAR16) + sizeof (SHELL_STATUS));
ExitData = AllocatePool (ExitDataSize);
if (ExitData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
ExitData[0] = '\0';
// Use CopyMem to avoid alignment faults
CopyMem ((ExitData + 1), &ExitStatus, sizeof (ExitStatus));
gBS->Exit (ImageHandle, EFI_ABORTED, ExitDataSize, ExitData);
ASSERT (FALSE);
return EFI_SUCCESS;
} else {
return EFI_SUCCESS;
}
} else {
return Status;
} }
return (Status);
} }
/** /**
@ -986,16 +949,13 @@ ProcessCommandLine(
@param ImagePath the path to the image for shell. first place to look for the startup script @param ImagePath the path to the image for shell. first place to look for the startup script
@param FilePath the path to the file for shell. second place to look for the startup script. @param FilePath the path to the file for shell. second place to look for the startup script.
@param[out] ExitStatus The exit code of the script. Ignored if NULL.
@retval EFI_SUCCESS the variable is initialized. @retval EFI_SUCCESS the variable is initialized.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
DoStartupScript( DoStartupScript(
IN EFI_DEVICE_PATH_PROTOCOL *ImagePath, IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,
IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN EFI_DEVICE_PATH_PROTOCOL *FilePath
OUT SHELL_STATUS *ExitStatus
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -1030,7 +990,7 @@ DoStartupScript(
StrnCat(FileStringPath, L" ", NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1); StrnCat(FileStringPath, L" ", NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);
StrnCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1); StrnCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);
} }
Status = RunCommand(FileStringPath, ExitStatus); Status = RunCommand(FileStringPath);
FreePool(FileStringPath); FreePool(FileStringPath);
return (Status); return (Status);
@ -1107,13 +1067,7 @@ DoStartupScript(
// If we got a file, run it // If we got a file, run it
// //
if (!EFI_ERROR(Status) && FileHandle != NULL) { if (!EFI_ERROR(Status) && FileHandle != NULL) {
Status = RunScriptFile ( Status = RunScriptFile (mStartupScript, FileHandle, L"", ShellInfoObject.NewShellParametersProtocol);
mStartupScript,
FileHandle,
L"",
ShellInfoObject.NewShellParametersProtocol,
ExitStatus
);
ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle); ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);
} else { } else {
FileStringPath = ShellFindFilePath(mStartupScript); FileStringPath = ShellFindFilePath(mStartupScript);
@ -1124,13 +1078,7 @@ DoStartupScript(
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
ASSERT(FileHandle == NULL); ASSERT(FileHandle == NULL);
} else { } else {
Status = RunScriptFile( Status = RunScriptFile(FileStringPath, NULL, L"", ShellInfoObject.NewShellParametersProtocol);
FileStringPath,
NULL,
L"",
ShellInfoObject.NewShellParametersProtocol,
ExitStatus
);
FreePool(FileStringPath); FreePool(FileStringPath);
} }
} }
@ -1195,7 +1143,7 @@ DoShellPrompt (
// //
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
CmdLine[BufferSize / sizeof (CHAR16)] = CHAR_NULL; CmdLine[BufferSize / sizeof (CHAR16)] = CHAR_NULL;
Status = RunCommand(CmdLine, NULL); Status = RunCommand(CmdLine);
} }
// //
@ -1526,9 +1474,6 @@ ShellConvertVariables (
@param[in] StdIn The pointer to the Standard input. @param[in] StdIn The pointer to the Standard input.
@param[in] StdOut The pointer to the Standard output. @param[in] StdOut The pointer to the Standard output.
@param[out] ExitStatus The exit code of the last command in the pipeline.
Ignored if NULL.
@retval EFI_SUCCESS The split command is executed successfully. @retval EFI_SUCCESS The split command is executed successfully.
@retval other Some error occurs when executing the split command. @retval other Some error occurs when executing the split command.
**/ **/
@ -1537,8 +1482,7 @@ EFIAPI
RunSplitCommand( RunSplitCommand(
IN CONST CHAR16 *CmdLine, IN CONST CHAR16 *CmdLine,
IN SHELL_FILE_HANDLE *StdIn, IN SHELL_FILE_HANDLE *StdIn,
IN SHELL_FILE_HANDLE *StdOut, IN SHELL_FILE_HANDLE *StdOut
OUT SHELL_STATUS *ExitStatus
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -1592,7 +1536,7 @@ RunSplitCommand(
ASSERT(Split->SplitStdOut != NULL); ASSERT(Split->SplitStdOut != NULL);
InsertHeadList(&ShellInfoObject.SplitList.Link, &Split->Link); InsertHeadList(&ShellInfoObject.SplitList.Link, &Split->Link);
Status = RunCommand(OurCommandLine, NULL); Status = RunCommand(OurCommandLine);
// //
// move the output from the first to the in to the second. // move the output from the first to the in to the second.
@ -1607,7 +1551,7 @@ RunSplitCommand(
ShellInfoObject.NewEfiShellProtocol->SetFilePosition(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn), 0); ShellInfoObject.NewEfiShellProtocol->SetFilePosition(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn), 0);
if (!EFI_ERROR(Status)) { if (!EFI_ERROR(Status)) {
Status = RunCommand(NextCommandLine, ExitStatus); Status = RunCommand(NextCommandLine);
} }
// //
@ -1901,9 +1845,7 @@ VerifySplit(
/** /**
Process a split based operation. Process a split based operation.
@param[in] CmdLine Pointer to the command line to process @param[in] CmdLine pointer to the command line to process
@param[out] ExitStatus The exit status of the command. Ignored if NULL.
Invalid if this function returns an error.
@retval EFI_SUCCESS The operation was successful @retval EFI_SUCCESS The operation was successful
@return an error occured. @return an error occured.
@ -1911,8 +1853,7 @@ VerifySplit(
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
ProcessNewSplitCommandLine( ProcessNewSplitCommandLine(
IN CONST CHAR16 *CmdLine, IN CONST CHAR16 *CmdLine
OUT SHELL_STATUS *ExitStatus
) )
{ {
SPLIT_LIST *Split; SPLIT_LIST *Split;
@ -1933,14 +1874,9 @@ ProcessNewSplitCommandLine(
} }
if (Split == NULL) { if (Split == NULL) {
Status = RunSplitCommand(CmdLine, NULL, NULL, ExitStatus); Status = RunSplitCommand(CmdLine, NULL, NULL);
} else { } else {
Status = RunSplitCommand( Status = RunSplitCommand(CmdLine, Split->SplitStdIn, Split->SplitStdOut);
CmdLine,
Split->SplitStdIn,
Split->SplitStdOut,
ExitStatus
);
} }
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, CmdLine); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, CmdLine);
@ -2120,8 +2056,6 @@ ProcessCommandLineToFinal(
@param[in] FirstParameter the first parameter on the command line @param[in] FirstParameter the first parameter on the command line
@param[in] ParamProtocol the shell parameters protocol pointer @param[in] ParamProtocol the shell parameters protocol pointer
@param[out] ExitStatus The exit code of the command. Ignored if NULL.
@retval EFI_SUCCESS The command was completed. @retval EFI_SUCCESS The command was completed.
@retval EFI_ABORTED The command's operation was aborted. @retval EFI_ABORTED The command's operation was aborted.
**/ **/
@ -2130,8 +2064,7 @@ EFIAPI
RunInternalCommand( RunInternalCommand(
IN CONST CHAR16 *CmdLine, IN CONST CHAR16 *CmdLine,
IN CHAR16 *FirstParameter, IN CHAR16 *FirstParameter,
IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol, IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol
OUT SHELL_STATUS *ExitStatus OPTIONAL
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -2171,9 +2104,6 @@ RunInternalCommand(
if (LastError) { if (LastError) {
SetLastError(CommandReturnedStatus); SetLastError(CommandReturnedStatus);
} }
if (ExitStatus != NULL) {
*ExitStatus = CommandReturnedStatus;
}
// //
// Pass thru the exitcode from the app. // Pass thru the exitcode from the app.
@ -2229,9 +2159,6 @@ RunInternalCommand(
@param[in] FirstParameter the first parameter on the command line @param[in] FirstParameter the first parameter on the command line
@param[in] ParamProtocol the shell parameters protocol pointer @param[in] ParamProtocol the shell parameters protocol pointer
@param[out] ExitStatus The exit code of the command or file.
Ignored if NULL.
@retval EFI_SUCCESS The command was completed. @retval EFI_SUCCESS The command was completed.
@retval EFI_ABORTED The command's operation was aborted. @retval EFI_ABORTED The command's operation was aborted.
**/ **/
@ -2241,8 +2168,7 @@ RunCommandOrFile(
IN SHELL_OPERATION_TYPES Type, IN SHELL_OPERATION_TYPES Type,
IN CONST CHAR16 *CmdLine, IN CONST CHAR16 *CmdLine,
IN CHAR16 *FirstParameter, IN CHAR16 *FirstParameter,
IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol, IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol
OUT SHELL_STATUS *ExitStatus
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -2258,12 +2184,7 @@ RunCommandOrFile(
switch (Type) { switch (Type) {
case Internal_Command: case Internal_Command:
Status = RunInternalCommand( Status = RunInternalCommand(CmdLine, FirstParameter, ParamProtocol);
CmdLine,
FirstParameter,
ParamProtocol,
&CalleeExitStatus
);
break; break;
case Script_File_Name: case Script_File_Name:
case Efi_Application: case Efi_Application:
@ -2298,13 +2219,7 @@ RunCommandOrFile(
} }
switch (Type) { switch (Type) {
case Script_File_Name: case Script_File_Name:
Status = RunScriptFile ( Status = RunScriptFile (CommandWithPath, NULL, CmdLine, ParamProtocol);
CommandWithPath,
NULL,
CmdLine,
ParamProtocol,
&CalleeExitStatus
);
break; break;
case Efi_Application: case Efi_Application:
// //
@ -2324,9 +2239,7 @@ RunCommandOrFile(
DevPath, DevPath,
CmdLine, CmdLine,
NULL, NULL,
&StartStatus, &StartStatus
NULL,
NULL
); );
SHELL_FREE_NON_NULL(DevPath); SHELL_FREE_NON_NULL(DevPath);
@ -2359,10 +2272,6 @@ RunCommandOrFile(
SHELL_FREE_NON_NULL(CommandWithPath); SHELL_FREE_NON_NULL(CommandWithPath);
if (ExitStatus != NULL) {
*ExitStatus = CalleeExitStatus;
}
return (Status); return (Status);
} }
@ -2374,20 +2283,16 @@ RunCommandOrFile(
@param[in] FirstParameter the first parameter on the command line. @param[in] FirstParameter the first parameter on the command line.
@param[in] ParamProtocol the shell parameters protocol pointer @param[in] ParamProtocol the shell parameters protocol pointer
@param[out] ExitStatus The exit code of the command or file.
Ignored if NULL.
@retval EFI_SUCCESS The command was completed. @retval EFI_SUCCESS The command was completed.
@retval EFI_ABORTED The command's operation was aborted. @retval EFI_ABORTED The command's operation was aborted.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
SetupAndRunCommandOrFile( SetupAndRunCommandOrFile(
IN SHELL_OPERATION_TYPES Type, IN SHELL_OPERATION_TYPES Type,
IN CHAR16 *CmdLine, IN CHAR16 *CmdLine,
IN CHAR16 *FirstParameter, IN CHAR16 *FirstParameter,
IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol, IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol
OUT SHELL_STATUS *ExitStatus
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -2407,13 +2312,7 @@ SetupAndRunCommandOrFile(
// //
if (!EFI_ERROR(Status)) { if (!EFI_ERROR(Status)) {
TrimSpaces(&CmdLine); TrimSpaces(&CmdLine);
Status = RunCommandOrFile( Status = RunCommandOrFile(Type, CmdLine, FirstParameter, ParamProtocol);
Type,
CmdLine,
FirstParameter,
ParamProtocol,
ExitStatus
);
} }
// //
@ -2438,7 +2337,6 @@ SetupAndRunCommandOrFile(
command or dispatch an external application. command or dispatch an external application.
@param[in] CmdLine The command line to parse. @param[in] CmdLine The command line to parse.
@param[out] ExitStatus The exit code of the command. Ignored if NULL.
@retval EFI_SUCCESS The command was completed. @retval EFI_SUCCESS The command was completed.
@retval EFI_ABORTED The command's operation was aborted. @retval EFI_ABORTED The command's operation was aborted.
@ -2446,8 +2344,7 @@ SetupAndRunCommandOrFile(
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
RunCommand( RunCommand(
IN CONST CHAR16 *CmdLine, IN CONST CHAR16 *CmdLine
OUT SHELL_STATUS *ExitStatus
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -2507,7 +2404,7 @@ RunCommand(
// We dont do normal processing with a split command line (output from one command input to another) // We dont do normal processing with a split command line (output from one command input to another)
// //
if (ContainsSplit(CleanOriginal)) { if (ContainsSplit(CleanOriginal)) {
Status = ProcessNewSplitCommandLine(CleanOriginal, ExitStatus); Status = ProcessNewSplitCommandLine(CleanOriginal);
SHELL_FREE_NON_NULL(CleanOriginal); SHELL_FREE_NON_NULL(CleanOriginal);
return (Status); return (Status);
} }
@ -2533,13 +2430,7 @@ RunCommand(
case Internal_Command: case Internal_Command:
case Script_File_Name: case Script_File_Name:
case Efi_Application: case Efi_Application:
Status = SetupAndRunCommandOrFile( Status = SetupAndRunCommandOrFile(Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol);
Type,
CleanOriginal,
FirstParameter,
ShellInfoObject.NewShellParametersProtocol,
ExitStatus
);
break; break;
default: default:
// //
@ -2594,16 +2485,13 @@ IsValidCommandName(
@param[in] Handle The handle to the already opened file. @param[in] Handle The handle to the already opened file.
@param[in] Name The name of the script file. @param[in] Name The name of the script file.
@param[out] ExitStatus The exit code of the script. Ignored if NULL.
@retval EFI_SUCCESS the script completed sucessfully @retval EFI_SUCCESS the script completed sucessfully
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
RunScriptFileHandle ( RunScriptFileHandle (
IN SHELL_FILE_HANDLE Handle, IN SHELL_FILE_HANDLE Handle,
IN CONST CHAR16 *Name, IN CONST CHAR16 *Name
OUT SHELL_STATUS *ExitStatus
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -2619,11 +2507,8 @@ RunScriptFileHandle (
CONST CHAR16 *CurDir; CONST CHAR16 *CurDir;
UINTN LineCount; UINTN LineCount;
CHAR16 LeString[50]; CHAR16 LeString[50];
SHELL_STATUS CalleeExitStatus;
ASSERT(!ShellCommandGetScriptExit()); ASSERT(!ShellCommandGetScriptExit());
CalleeExitStatus = SHELL_SUCCESS;
PreScriptEchoState = ShellCommandGetEchoState(); PreScriptEchoState = ShellCommandGetEchoState();
@ -2809,7 +2694,7 @@ RunScriptFileHandle (
// //
PreCommandEchoState = ShellCommandGetEchoState(); PreCommandEchoState = ShellCommandGetEchoState();
ShellCommandSetEchoState(FALSE); ShellCommandSetEchoState(FALSE);
Status = RunCommand(CommandLine3+1, NULL); Status = RunCommand(CommandLine3+1);
// //
// If command was "@echo -off" or "@echo -on" then don't restore echo state // If command was "@echo -off" or "@echo -on" then don't restore echo state
@ -2831,7 +2716,7 @@ RunScriptFileHandle (
} }
ShellPrintEx(-1, -1, L"%s\r\n", CommandLine2); ShellPrintEx(-1, -1, L"%s\r\n", CommandLine2);
} }
Status = RunCommand(CommandLine3, NULL); Status = RunCommand(CommandLine3);
} }
} }
@ -2839,8 +2724,7 @@ RunScriptFileHandle (
// //
// ShellCommandGetExitCode() always returns a UINT64 // ShellCommandGetExitCode() always returns a UINT64
// //
CalleeExitStatus = (SHELL_STATUS) ShellCommandGetExitCode(); UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode());
UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", CalleeExitStatus);
DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE);); DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););
InternalEfiShellSetEnv(L"lasterror", LeString, TRUE); InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);
@ -2852,11 +2736,9 @@ RunScriptFileHandle (
break; break;
} }
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
CalleeExitStatus = (SHELL_STATUS) Status;
break; break;
} }
if (ShellCommandGetExit()) { if (ShellCommandGetExit()) {
CalleeExitStatus = (SHELL_STATUS) ShellCommandGetExitCode();
break; break;
} }
} }
@ -2888,11 +2770,6 @@ RunScriptFileHandle (
if (ShellCommandGetCurrentScriptFile()==NULL) { if (ShellCommandGetCurrentScriptFile()==NULL) {
ShellCommandSetEchoState(PreScriptEchoState); ShellCommandSetEchoState(PreScriptEchoState);
} }
if (ExitStatus != NULL) {
*ExitStatus = CalleeExitStatus;
}
return (EFI_SUCCESS); return (EFI_SUCCESS);
} }
@ -2904,18 +2781,15 @@ RunScriptFileHandle (
@param[in] CmdLine the command line to run. @param[in] CmdLine the command line to run.
@param[in] ParamProtocol the shell parameters protocol pointer @param[in] ParamProtocol the shell parameters protocol pointer
@param[out] ExitStatus The exit code of the script. Ignored if NULL.
@retval EFI_SUCCESS the script completed sucessfully @retval EFI_SUCCESS the script completed sucessfully
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
RunScriptFile ( RunScriptFile (
IN CONST CHAR16 *ScriptPath, IN CONST CHAR16 *ScriptPath,
IN SHELL_FILE_HANDLE Handle OPTIONAL, IN SHELL_FILE_HANDLE Handle OPTIONAL,
IN CONST CHAR16 *CmdLine, IN CONST CHAR16 *CmdLine,
IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol, IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol
OUT SHELL_STATUS *ExitStatus
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -2942,7 +2816,7 @@ RunScriptFile (
// //
// run it // run it
// //
Status = RunScriptFileHandle(FileHandle, ScriptPath, ExitStatus); Status = RunScriptFileHandle(FileHandle, ScriptPath);
// //
// now close the file // now close the file
@ -2950,7 +2824,7 @@ RunScriptFile (
ShellCloseFile(&FileHandle); ShellCloseFile(&FileHandle);
} }
} else { } else {
Status = RunScriptFileHandle(Handle, ScriptPath, ExitStatus); Status = RunScriptFileHandle(Handle, ScriptPath);
} }
} }

View File

@ -231,17 +231,14 @@ ProcessCommandLine(
@param[in] ImagePath The path to the image for shell. The first place to look for the startup script. @param[in] ImagePath The path to the image for shell. The first place to look for the startup script.
@param[in] FilePath The path to the file for shell. The second place to look for the startup script. @param[in] FilePath The path to the file for shell. The second place to look for the startup script.
@param[out] ExitStatus The exit code of the script. Ignored if NULL.
Invalid when this function returns an error.
@retval EFI_SUCCESS The variable is initialized. @retval EFI_SUCCESS The variable is initialized.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
DoStartupScript( DoStartupScript(
IN EFI_DEVICE_PATH_PROTOCOL *ImagePath, IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,
IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN EFI_DEVICE_PATH_PROTOCOL *FilePath
OUT SHELL_STATUS *ExitStatus
); );
/** /**
@ -286,8 +283,7 @@ AddLineToCommandHistory(
This will determine if the command line represents an internal shell command or dispatch an external application. This will determine if the command line represents an internal shell command or dispatch an external application.
@param[in] CmdLine the command line to parse @param[in] CmdLine the command line to parse
@param[out] ExitStatus The exit status of the command. Ignored if NULL.
@retval EFI_SUCCESS the command was completed @retval EFI_SUCCESS the command was completed
@retval EFI_ABORTED the command's operation was aborted @retval EFI_ABORTED the command's operation was aborted
@ -295,8 +291,7 @@ AddLineToCommandHistory(
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
RunCommand( RunCommand(
IN CONST CHAR16 *CmdLine, IN CONST CHAR16 *CmdLine
OUT SHELL_STATUS *ExitStatus
); );
/** /**
@ -320,17 +315,13 @@ IsValidCommandName(
@param[in] Handle The handle to the already opened file. @param[in] Handle The handle to the already opened file.
@param[in] Name The name of the script file. @param[in] Name The name of the script file.
@param[out] ExitStatus The exit code of the script. Ignored if NULL.
Invalid when this function returns an error.
@retval EFI_SUCCESS the script completed sucessfully @retval EFI_SUCCESS the script completed sucessfully
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
RunScriptFileHandle ( RunScriptFileHandle (
IN SHELL_FILE_HANDLE Handle, IN SHELL_FILE_HANDLE Handle,
IN CONST CHAR16 *Name, IN CONST CHAR16 *Name
OUT SHELL_STATUS *ExitStatus
); );
/** /**
@ -341,20 +332,17 @@ RunScriptFileHandle (
@param[in] CmdLine the command line to run. @param[in] CmdLine the command line to run.
@param[in] ParamProtocol the shell parameters protocol pointer @param[in] ParamProtocol the shell parameters protocol pointer
@param[out] ExitStatus The exit code of the script. Ignored if NULL.
Invalid when this function returns an error.
@retval EFI_SUCCESS the script completed sucessfully @retval EFI_SUCCESS the script completed sucessfully
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
RunScriptFile ( RunScriptFile (
IN CONST CHAR16 *ScriptPath, IN CONST CHAR16 *ScriptPath,
IN SHELL_FILE_HANDLE Handle OPTIONAL, IN SHELL_FILE_HANDLE Handle OPTIONAL,
IN CONST CHAR16 *CmdLine, IN CONST CHAR16 *CmdLine,
IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol, IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol
OUT SHELL_STATUS *ExitStatus
); );
#endif //_SHELL_INTERNAL_HEADER_ #endif //_SHELL_INTERNAL_HEADER_

View File

@ -1401,8 +1401,6 @@ EfiShellEnablePageBreak (
is NULL, then the current shell environment is used. is NULL, then the current shell environment is used.
@param[out] StartImageStatus Returned status from gBS->StartImage. @param[out] StartImageStatus Returned status from gBS->StartImage.
@param[out] ExitDataSize ExitDataSize as returned from gBS->StartImage
@param[out] ExitData ExitData as returned from gBS->StartImage
@retval EFI_SUCCESS The command executed successfully. The status code @retval EFI_SUCCESS The command executed successfully. The status code
returned by the command is pointed to by StatusCode. returned by the command is pointed to by StatusCode.
@ -1417,9 +1415,7 @@ InternalShellExecuteDevicePath(
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CONST CHAR16 *CommandLine OPTIONAL, IN CONST CHAR16 *CommandLine OPTIONAL,
IN CONST CHAR16 **Environment OPTIONAL, IN CONST CHAR16 **Environment OPTIONAL,
OUT EFI_STATUS *StartImageStatus OPTIONAL, OUT EFI_STATUS *StartImageStatus OPTIONAL
OUT UINTN *ExitDataSize OPTIONAL,
OUT CHAR16 **ExitData OPTIONAL
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -1429,21 +1425,11 @@ InternalShellExecuteDevicePath(
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
LIST_ENTRY OrigEnvs; LIST_ENTRY OrigEnvs;
EFI_SHELL_PARAMETERS_PROTOCOL ShellParamsProtocol; EFI_SHELL_PARAMETERS_PROTOCOL ShellParamsProtocol;
UINTN InternalExitDataSize;
UINTN *ExitDataSizePtr;
CHAR16 *ImagePath; CHAR16 *ImagePath;
UINTN Index; UINTN Index;
CHAR16 *Walker; CHAR16 *Walker;
CHAR16 *NewCmdLine; CHAR16 *NewCmdLine;
// ExitDataSize is not OPTIONAL for gBS->BootServices, provide somewhere for
// it to be dumped if the caller doesn't want it.
if (ExitData == NULL) {
ExitDataSizePtr = &InternalExitDataSize;
} else {
ExitDataSizePtr = ExitDataSize;
}
if (ParentImageHandle == NULL) { if (ParentImageHandle == NULL) {
return (EFI_INVALID_PARAMETER); return (EFI_INVALID_PARAMETER);
} }
@ -1547,13 +1533,13 @@ InternalShellExecuteDevicePath(
///@todo initialize and install ShellInterface protocol on the new image for compatibility if - PcdGetBool(PcdShellSupportOldProtocols) ///@todo initialize and install ShellInterface protocol on the new image for compatibility if - PcdGetBool(PcdShellSupportOldProtocols)
// //
// now start the image, passing up exit data if the caller requested it // now start the image and if the caller wanted the return code pass it to them...
// //
if (!EFI_ERROR(Status)) { if (!EFI_ERROR(Status)) {
StartStatus = gBS->StartImage( StartStatus = gBS->StartImage(
NewHandle, NewHandle,
ExitDataSizePtr, 0,
ExitData NULL
); );
if (StartImageStatus != NULL) { if (StartImageStatus != NULL) {
*StartImageStatus = StartStatus; *StartImageStatus = StartStatus;
@ -1642,8 +1628,6 @@ EfiShellExecute(
CHAR16 *Temp; CHAR16 *Temp;
EFI_DEVICE_PATH_PROTOCOL *DevPath; EFI_DEVICE_PATH_PROTOCOL *DevPath;
UINTN Size; UINTN Size;
UINTN ExitDataSize;
CHAR16 *ExitData;
if ((PcdGet8(PcdShellSupportLevel) < 1)) { if ((PcdGet8(PcdShellSupportLevel) < 1)) {
return (EFI_UNSUPPORTED); return (EFI_UNSUPPORTED);
@ -1671,32 +1655,7 @@ EfiShellExecute(
DevPath, DevPath,
Temp, Temp,
(CONST CHAR16**)Environment, (CONST CHAR16**)Environment,
StatusCode, StatusCode);
&ExitDataSize,
&ExitData);
if (Status == EFI_ABORTED) {
// If the command exited with an error, the shell should put the exit
// status in ExitData, preceded by a null-terminated string.
ASSERT (ExitDataSize == StrSize (ExitData) + sizeof (SHELL_STATUS));
if (StatusCode != NULL) {
// Skip the null-terminated string
ExitData += StrLen (ExitData) + 1;
// Use CopyMem to avoid alignment faults
CopyMem (StatusCode, ExitData, sizeof (SHELL_STATUS));
// Convert from SHELL_STATUS to EFI_STATUS
// EFI_STATUSes have top bit set when they are errors.
// (See UEFI Spec Appendix D)
if (*StatusCode != SHELL_SUCCESS) {
*StatusCode = (EFI_STATUS) *StatusCode | MAX_BIT;
}
}
FreePool (ExitData);
Status = EFI_SUCCESS;
}
// //
// de-allocate and return // de-allocate and return

View File

@ -445,8 +445,6 @@ EfiShellEnablePageBreak (
environment variable name and y is the value. If this environment variable name and y is the value. If this
is NULL, then the current shell environment is used. is NULL, then the current shell environment is used.
@param[out] StartImageStatus Returned status from gBS->StartImage. @param[out] StartImageStatus Returned status from gBS->StartImage.
@param[out] ExitDataSize ExitDataSize as returned from gBS->StartImage
@param[out] ExitData ExitData as returned from gBS->StartImage
@retval EFI_SUCCESS The command executed successfully. The status code @retval EFI_SUCCESS The command executed successfully. The status code
returned by the command is pointed to by StatusCode. returned by the command is pointed to by StatusCode.
@ -461,9 +459,7 @@ InternalShellExecuteDevicePath(
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CONST CHAR16 *CommandLine OPTIONAL, IN CONST CHAR16 *CommandLine OPTIONAL,
IN CONST CHAR16 **Environment OPTIONAL, IN CONST CHAR16 **Environment OPTIONAL,
OUT EFI_STATUS *StartImageStatus OPTIONAL, OUT EFI_STATUS *StartImageStatus OPTIONAL
OUT UINTN *ExitDataSize OPTIONAL,
OUT CHAR16 **ExitData OPTIONAL
); );
/** /**