summaryrefslogtreecommitdiff
path: root/ShellPkg/Application/Shell/Shell.c
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2014-09-18 01:58:03 +0000
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>2014-09-18 01:58:03 +0000
commita308e0588b3ad87b94611391e9e7a04a8eb05ebf (patch)
treed90edaf7e5d543b64dc78400a32fa2733a039251 /ShellPkg/Application/Shell/Shell.c
parent4b6b543e77f3237c63e691f35d0bb259ddc287b4 (diff)
downloadedk2-platforms-a308e0588b3ad87b94611391e9e7a04a8eb05ebf.tar.xz
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
Diffstat (limited to 'ShellPkg/Application/Shell/Shell.c')
-rw-r--r--ShellPkg/Application/Shell/Shell.c210
1 files changed, 42 insertions, 168 deletions
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index 29c65b7f27..41fa78004d 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -244,9 +244,6 @@ UefiMain (
UINTN Size;
EFI_HANDLE ConInHandle;
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *OldConIn;
- UINTN ExitDataSize;
- CHAR16 *ExitData;
- SHELL_STATUS ExitStatus;
if (PcdGet8(PcdShellSupportLevel) > 3) {
return (EFI_UNSUPPORTED);
@@ -300,12 +297,6 @@ UefiMain (
// install our console logger. This will keep a log of the output for back-browsing
//
Status = ConsoleLoggerInstall(ShellInfoObject.LogScreenCount, &ShellInfoObject.ConsoleInfo);
- if(EFI_ERROR (Status)) {
- ExitStatus = (SHELL_STATUS) (Status & (~MAX_BIT));
- } else {
- ExitStatus = SHELL_SUCCESS;
- }
-
if (!EFI_ERROR(Status)) {
//
// Enable the cursor to be visible
@@ -419,7 +410,7 @@ UefiMain (
// Display the mapping
//
if (PcdGet8(PcdShellSupportLevel) >= 2 && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) {
- Status = RunCommand(L"map", NULL);
+ Status = RunCommand(L"map");
ASSERT_EFI_ERROR(Status);
}
@@ -485,11 +476,7 @@ UefiMain (
//
// process the startup script or launch the called app.
//
- Status = DoStartupScript(
- ShellInfoObject.ImageDevPath,
- ShellInfoObject.FileDevPath,
- &ExitStatus
- );
+ Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);
}
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();
} while (!ShellCommandGetExit());
- ExitStatus = (SHELL_STATUS) ShellCommandGetExitCode();
}
if (OldConIn != NULL && ConInHandle != NULL) {
CloseSimpleTextInOnFile (gST->ConIn);
@@ -595,33 +581,10 @@ FreeResources:
DEBUG_CODE(ShellInfoObject.ConsoleInfo = NULL;);
}
- if (!EFI_ERROR (Status)) {
- // If the command exited with an error, we pass this error out in the ExitData
- // 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;
+ if (ShellCommandGetExit()) {
+ return ((EFI_STATUS)ShellCommandGetExitCode());
}
+ 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 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.
**/
EFI_STATUS
EFIAPI
DoStartupScript(
- IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- OUT SHELL_STATUS *ExitStatus
+ IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath
)
{
EFI_STATUS Status;
@@ -1030,7 +990,7 @@ DoStartupScript(
StrnCat(FileStringPath, L" ", 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);
return (Status);
@@ -1107,13 +1067,7 @@ DoStartupScript(
// If we got a file, run it
//
if (!EFI_ERROR(Status) && FileHandle != NULL) {
- Status = RunScriptFile (
- mStartupScript,
- FileHandle,
- L"",
- ShellInfoObject.NewShellParametersProtocol,
- ExitStatus
- );
+ Status = RunScriptFile (mStartupScript, FileHandle, L"", ShellInfoObject.NewShellParametersProtocol);
ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);
} else {
FileStringPath = ShellFindFilePath(mStartupScript);
@@ -1124,13 +1078,7 @@ DoStartupScript(
Status = EFI_SUCCESS;
ASSERT(FileHandle == NULL);
} else {
- Status = RunScriptFile(
- FileStringPath,
- NULL,
- L"",
- ShellInfoObject.NewShellParametersProtocol,
- ExitStatus
- );
+ Status = RunScriptFile(FileStringPath, NULL, L"", ShellInfoObject.NewShellParametersProtocol);
FreePool(FileStringPath);
}
}
@@ -1195,7 +1143,7 @@ DoShellPrompt (
//
if (!EFI_ERROR (Status)) {
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] 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 other Some error occurs when executing the split command.
**/
@@ -1537,8 +1482,7 @@ EFIAPI
RunSplitCommand(
IN CONST CHAR16 *CmdLine,
IN SHELL_FILE_HANDLE *StdIn,
- IN SHELL_FILE_HANDLE *StdOut,
- OUT SHELL_STATUS *ExitStatus
+ IN SHELL_FILE_HANDLE *StdOut
)
{
EFI_STATUS Status;
@@ -1592,7 +1536,7 @@ RunSplitCommand(
ASSERT(Split->SplitStdOut != NULL);
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.
@@ -1607,7 +1551,7 @@ RunSplitCommand(
ShellInfoObject.NewEfiShellProtocol->SetFilePosition(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn), 0);
if (!EFI_ERROR(Status)) {
- Status = RunCommand(NextCommandLine, ExitStatus);
+ Status = RunCommand(NextCommandLine);
}
//
@@ -1901,9 +1845,7 @@ VerifySplit(
/**
Process a split based operation.
- @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.
+ @param[in] CmdLine pointer to the command line to process
@retval EFI_SUCCESS The operation was successful
@return an error occured.
@@ -1911,8 +1853,7 @@ VerifySplit(
EFI_STATUS
EFIAPI
ProcessNewSplitCommandLine(
- IN CONST CHAR16 *CmdLine,
- OUT SHELL_STATUS *ExitStatus
+ IN CONST CHAR16 *CmdLine
)
{
SPLIT_LIST *Split;
@@ -1933,14 +1874,9 @@ ProcessNewSplitCommandLine(
}
if (Split == NULL) {
- Status = RunSplitCommand(CmdLine, NULL, NULL, ExitStatus);
+ Status = RunSplitCommand(CmdLine, NULL, NULL);
} else {
- Status = RunSplitCommand(
- CmdLine,
- Split->SplitStdIn,
- Split->SplitStdOut,
- ExitStatus
- );
+ Status = RunSplitCommand(CmdLine, Split->SplitStdIn, Split->SplitStdOut);
}
if (EFI_ERROR(Status)) {
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] 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_ABORTED The command's operation was aborted.
**/
@@ -2130,8 +2064,7 @@ EFIAPI
RunInternalCommand(
IN CONST CHAR16 *CmdLine,
IN CHAR16 *FirstParameter,
- IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,
- OUT SHELL_STATUS *ExitStatus OPTIONAL
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol
)
{
EFI_STATUS Status;
@@ -2171,9 +2104,6 @@ RunInternalCommand(
if (LastError) {
SetLastError(CommandReturnedStatus);
}
- if (ExitStatus != NULL) {
- *ExitStatus = CommandReturnedStatus;
- }
//
// Pass thru the exitcode from the app.
@@ -2229,9 +2159,6 @@ RunInternalCommand(
@param[in] FirstParameter the first parameter on the command line
@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_ABORTED The command's operation was aborted.
**/
@@ -2241,8 +2168,7 @@ RunCommandOrFile(
IN SHELL_OPERATION_TYPES Type,
IN CONST CHAR16 *CmdLine,
IN CHAR16 *FirstParameter,
- IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,
- OUT SHELL_STATUS *ExitStatus
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol
)
{
EFI_STATUS Status;
@@ -2258,12 +2184,7 @@ RunCommandOrFile(
switch (Type) {
case Internal_Command:
- Status = RunInternalCommand(
- CmdLine,
- FirstParameter,
- ParamProtocol,
- &CalleeExitStatus
- );
+ Status = RunInternalCommand(CmdLine, FirstParameter, ParamProtocol);
break;
case Script_File_Name:
case Efi_Application:
@@ -2298,13 +2219,7 @@ RunCommandOrFile(
}
switch (Type) {
case Script_File_Name:
- Status = RunScriptFile (
- CommandWithPath,
- NULL,
- CmdLine,
- ParamProtocol,
- &CalleeExitStatus
- );
+ Status = RunScriptFile (CommandWithPath, NULL, CmdLine, ParamProtocol);
break;
case Efi_Application:
//
@@ -2324,9 +2239,7 @@ RunCommandOrFile(
DevPath,
CmdLine,
NULL,
- &StartStatus,
- NULL,
- NULL
+ &StartStatus
);
SHELL_FREE_NON_NULL(DevPath);
@@ -2359,10 +2272,6 @@ RunCommandOrFile(
SHELL_FREE_NON_NULL(CommandWithPath);
- if (ExitStatus != NULL) {
- *ExitStatus = CalleeExitStatus;
- }
-
return (Status);
}
@@ -2374,20 +2283,16 @@ RunCommandOrFile(
@param[in] FirstParameter the first parameter on the command line.
@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_ABORTED The command's operation was aborted.
**/
EFI_STATUS
EFIAPI
SetupAndRunCommandOrFile(
- IN SHELL_OPERATION_TYPES Type,
- IN CHAR16 *CmdLine,
- IN CHAR16 *FirstParameter,
- IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,
- OUT SHELL_STATUS *ExitStatus
+ IN SHELL_OPERATION_TYPES Type,
+ IN CHAR16 *CmdLine,
+ IN CHAR16 *FirstParameter,
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol
)
{
EFI_STATUS Status;
@@ -2407,13 +2312,7 @@ SetupAndRunCommandOrFile(
//
if (!EFI_ERROR(Status)) {
TrimSpaces(&CmdLine);
- Status = RunCommandOrFile(
- Type,
- CmdLine,
- FirstParameter,
- ParamProtocol,
- ExitStatus
- );
+ Status = RunCommandOrFile(Type, CmdLine, FirstParameter, ParamProtocol);
}
//
@@ -2438,7 +2337,6 @@ SetupAndRunCommandOrFile(
command or dispatch an external application.
@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_ABORTED The command's operation was aborted.
@@ -2446,8 +2344,7 @@ SetupAndRunCommandOrFile(
EFI_STATUS
EFIAPI
RunCommand(
- IN CONST CHAR16 *CmdLine,
- OUT SHELL_STATUS *ExitStatus
+ IN CONST CHAR16 *CmdLine
)
{
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)
//
if (ContainsSplit(CleanOriginal)) {
- Status = ProcessNewSplitCommandLine(CleanOriginal, ExitStatus);
+ Status = ProcessNewSplitCommandLine(CleanOriginal);
SHELL_FREE_NON_NULL(CleanOriginal);
return (Status);
}
@@ -2533,13 +2430,7 @@ RunCommand(
case Internal_Command:
case Script_File_Name:
case Efi_Application:
- Status = SetupAndRunCommandOrFile(
- Type,
- CleanOriginal,
- FirstParameter,
- ShellInfoObject.NewShellParametersProtocol,
- ExitStatus
- );
+ Status = SetupAndRunCommandOrFile(Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol);
break;
default:
//
@@ -2594,16 +2485,13 @@ IsValidCommandName(
@param[in] Handle The handle to the already opened 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
**/
EFI_STATUS
EFIAPI
RunScriptFileHandle (
- IN SHELL_FILE_HANDLE Handle,
- IN CONST CHAR16 *Name,
- OUT SHELL_STATUS *ExitStatus
+ IN SHELL_FILE_HANDLE Handle,
+ IN CONST CHAR16 *Name
)
{
EFI_STATUS Status;
@@ -2619,11 +2507,8 @@ RunScriptFileHandle (
CONST CHAR16 *CurDir;
UINTN LineCount;
CHAR16 LeString[50];
- SHELL_STATUS CalleeExitStatus;
ASSERT(!ShellCommandGetScriptExit());
-
- CalleeExitStatus = SHELL_SUCCESS;
PreScriptEchoState = ShellCommandGetEchoState();
@@ -2809,7 +2694,7 @@ RunScriptFileHandle (
//
PreCommandEchoState = ShellCommandGetEchoState();
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
@@ -2831,7 +2716,7 @@ RunScriptFileHandle (
}
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
//
- CalleeExitStatus = (SHELL_STATUS) ShellCommandGetExitCode();
- UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", CalleeExitStatus);
+ UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode());
DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););
InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);
@@ -2852,11 +2736,9 @@ RunScriptFileHandle (
break;
}
if (EFI_ERROR(Status)) {
- CalleeExitStatus = (SHELL_STATUS) Status;
break;
}
if (ShellCommandGetExit()) {
- CalleeExitStatus = (SHELL_STATUS) ShellCommandGetExitCode();
break;
}
}
@@ -2888,11 +2770,6 @@ RunScriptFileHandle (
if (ShellCommandGetCurrentScriptFile()==NULL) {
ShellCommandSetEchoState(PreScriptEchoState);
}
-
- if (ExitStatus != NULL) {
- *ExitStatus = CalleeExitStatus;
- }
-
return (EFI_SUCCESS);
}
@@ -2904,18 +2781,15 @@ RunScriptFileHandle (
@param[in] CmdLine the command line to run.
@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
**/
EFI_STATUS
EFIAPI
RunScriptFile (
- IN CONST CHAR16 *ScriptPath,
- IN SHELL_FILE_HANDLE Handle OPTIONAL,
- IN CONST CHAR16 *CmdLine,
- IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,
- OUT SHELL_STATUS *ExitStatus
+ IN CONST CHAR16 *ScriptPath,
+ IN SHELL_FILE_HANDLE Handle OPTIONAL,
+ IN CONST CHAR16 *CmdLine,
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol
)
{
EFI_STATUS Status;
@@ -2942,7 +2816,7 @@ RunScriptFile (
//
// run it
//
- Status = RunScriptFileHandle(FileHandle, ScriptPath, ExitStatus);
+ Status = RunScriptFileHandle(FileHandle, ScriptPath);
//
// now close the file
@@ -2950,7 +2824,7 @@ RunScriptFile (
ShellCloseFile(&FileHandle);
}
} else {
- Status = RunScriptFileHandle(Handle, ScriptPath, ExitStatus);
+ Status = RunScriptFileHandle(Handle, ScriptPath);
}
}