X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=ShellPkg%2FApplication%2FShell%2FShell.c;h=3e4706c288dbd2cbac12ce28af1c34fbbfb73e10;hb=ce68d3bc68eda5ce919b90aea8db094ed4b64c34;hp=3a5899f342ee989f9683e731e96f11a931078ea9;hpb=4ff7e37b4f7e336a8ecb7080b8f48eef4b52d396;p=mirror_edk2.git
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index 3a5899f342..3e4706c288 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -1,7 +1,7 @@
/** @file
This is THE shell (application)
- Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -23,22 +23,24 @@ SHELL_INFO ShellInfoObject = {
FALSE,
FALSE,
{
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
+ {{
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0
+ }},
0,
NULL,
NULL
},
- {0,0},
+ {{NULL, NULL}, NULL},
{
- {0,0},
+ {{NULL, NULL}, NULL},
0,
0,
TRUE
@@ -50,8 +52,12 @@ SHELL_INFO ShellInfoObject = {
NULL,
NULL,
NULL,
- {0,0,NULL,NULL},
- {0,0},
+ {{NULL, NULL}, NULL, NULL},
+ {{NULL, NULL}, NULL, NULL},
+ NULL,
+ NULL,
+ NULL,
+ NULL,
NULL,
NULL,
NULL,
@@ -475,6 +481,9 @@ UefiMain (
DEBUG_CODE(ShellInfoObject.ConsoleInfo = NULL;);
}
+ if (ShellCommandGetExit()) {
+ return ((EFI_STATUS)ShellCommandGetExitCode());
+ }
return (Status);
}
@@ -824,6 +833,7 @@ DoStartupScript(
return (EFI_SUCCESS);
}
+ gST->ConOut->EnableCursor(gST->ConOut, FALSE);
//
// print out our warning and see if they press a key
//
@@ -838,6 +848,7 @@ DoStartupScript(
}
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CRLF), ShellInfoObject.HiiHandle);
+ gST->ConOut->EnableCursor(gST->ConOut, TRUE);
//
// ESC was pressed
@@ -854,15 +865,19 @@ DoStartupScript(
FileStringPath = NULL;
NewSize = 0;
FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, MapName, 0);
- TempSpot = StrStr(FileStringPath, L";");
- if (TempSpot != NULL) {
- *TempSpot = CHAR_NULL;
+ if (FileStringPath == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ TempSpot = StrStr(FileStringPath, L";");
+ if (TempSpot != NULL) {
+ *TempSpot = CHAR_NULL;
+ }
+ FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);
+ PathRemoveLastItem(FileStringPath);
+ FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);
+ Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);
+ FreePool(FileStringPath);
}
- FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);
- PathRemoveLastItem(FileStringPath);
- FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);
- Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);
- FreePool(FileStringPath);
}
if (EFI_ERROR(Status)) {
NamePath = FileDevicePath (NULL, mStartupScript);
@@ -1212,7 +1227,16 @@ RunSplitCommand(
NextCommandLine = StrnCatGrow(&NextCommandLine, &Size1, StrStr(CmdLine, L"|")+1, 0);
OurCommandLine = StrnCatGrow(&OurCommandLine , &Size2, CmdLine , StrStr(CmdLine, L"|") - CmdLine);
- if (NextCommandLine[0] != CHAR_NULL &&
+
+ if (NextCommandLine == NULL || OurCommandLine == NULL) {
+ SHELL_FREE_NON_NULL(OurCommandLine);
+ SHELL_FREE_NON_NULL(NextCommandLine);
+ return (EFI_OUT_OF_RESOURCES);
+ } else if (StrStr(OurCommandLine, L"|") != NULL || Size1 == 0 || Size2 == 0) {
+ SHELL_FREE_NON_NULL(OurCommandLine);
+ SHELL_FREE_NON_NULL(NextCommandLine);
+ return (EFI_INVALID_PARAMETER);
+ } else if (NextCommandLine[0] != CHAR_NULL &&
NextCommandLine[0] == L'a' &&
NextCommandLine[1] == L' '
){
@@ -1233,7 +1257,6 @@ RunSplitCommand(
ASSERT(Split->SplitStdOut != NULL);
InsertHeadList(&ShellInfoObject.SplitList.Link, &Split->Link);
- ASSERT(StrStr(OurCommandLine, L"|") == NULL);
Status = RunCommand(OurCommandLine);
//
@@ -1293,6 +1316,7 @@ RunCommand(
)
{
EFI_STATUS Status;
+ EFI_STATUS StatusCode;
CHAR16 *CommandName;
SHELL_STATUS ShellStatus;
UINTN Argc;
@@ -1331,6 +1355,9 @@ RunCommand(
Split = NULL;
CleanOriginal = StrnCatGrow(&CleanOriginal, NULL, CmdLine, 0);
+ if (CleanOriginal == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
while (CleanOriginal[StrLen(CleanOriginal)-1] == L' ') {
CleanOriginal[StrLen(CleanOriginal)-1] = CHAR_NULL;
}
@@ -1416,6 +1443,9 @@ RunCommand(
} else {
Status = RunSplitCommand(PostVariableCmdLine, Split->SplitStdIn, Split->SplitStdOut);
}
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, PostVariableCmdLine);
+ }
} else {
//
@@ -1534,11 +1564,26 @@ RunCommand(
DevPath,
PostVariableCmdLine,
NULL,
- NULL
+ &StatusCode
);
+
+ //
+ // Updatet last error status.
+ //
+ UnicodeSPrint(LeString, sizeof(LeString)*sizeof(LeString[0]), L"0x%08x", StatusCode);
+ DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE););
+ InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);
}
}
}
+
+ //
+ // Print some error info.
+ //
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_ERROR), ShellInfoObject.HiiHandle, (VOID*)(Status));
+ }
+
CommandName = StrnCatGrow(&CommandName, NULL, ShellInfoObject.NewShellParametersProtocol->Argv[0], 0);
RestoreArgcArgv(ShellInfoObject.NewShellParametersProtocol, &Argv, &Argc);
@@ -1622,6 +1667,7 @@ RunScriptFileHandle (
BOOLEAN PreCommandEchoState;
CONST CHAR16 *CurDir;
UINTN LineCount;
+ CHAR16 LeString[50];
ASSERT(!ShellCommandGetScriptExit());
@@ -1798,15 +1844,6 @@ RunScriptFileHandle (
//
} else {
if (CommandLine3 != NULL && StrLen(CommandLine3) > 0) {
- if (ShellCommandGetEchoState()) {
- CurDir = ShellInfoObject.NewEfiShellProtocol->GetEnv(L"cwd");
- if (CurDir != NULL && StrLen(CurDir) > 1) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CURDIR), ShellInfoObject.HiiHandle, CurDir);
- } else {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_SHELL), ShellInfoObject.HiiHandle);
- }
- ShellPrintEx(-1, -1, L"%s\r\n", CommandLine2);
- }
if (CommandLine3[0] == L'@') {
//
// We need to save the current echo state
@@ -1821,15 +1858,31 @@ RunScriptFileHandle (
//
ShellCommandSetEchoState(PreCommandEchoState);
} else {
+ if (ShellCommandGetEchoState()) {
+ CurDir = ShellInfoObject.NewEfiShellProtocol->GetEnv(L"cwd");
+ if (CurDir != NULL && StrLen(CurDir) > 1) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CURDIR), ShellInfoObject.HiiHandle, CurDir);
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_SHELL), ShellInfoObject.HiiHandle);
+ }
+ ShellPrintEx(-1, -1, L"%s\r\n", CommandLine2);
+ }
Status = RunCommand(CommandLine3);
}
}
if (ShellCommandGetScriptExit()) {
- ShellCommandRegisterExit(FALSE);
+ UnicodeSPrint(LeString, sizeof(LeString)*sizeof(LeString[0]), L"0x%Lx", ShellCommandGetExitCode());
+ DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE););
+ InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);
+
+ ShellCommandRegisterExit(FALSE, 0);
Status = EFI_SUCCESS;
break;
}
+ if (ShellGetExecutionBreakFlag()) {
+ break;
+ }
if (EFI_ERROR(Status)) {
break;
}