X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FApplication%2FShell%2FShell.c;h=3e4706c288dbd2cbac12ce28af1c34fbbfb73e10;hp=614c1e9595d3d02132750a1c3550a82c02db47d8;hb=ce68d3bc68eda5ce919b90aea8db094ed4b64c34;hpb=b6b22b132ada04696a0f7481a12169808c3e2b3e diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index 614c1e9595..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, @@ -827,6 +833,7 @@ DoStartupScript( return (EFI_SUCCESS); } + gST->ConOut->EnableCursor(gST->ConOut, FALSE); // // print out our warning and see if they press a key // @@ -841,6 +848,7 @@ DoStartupScript( } } ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CRLF), ShellInfoObject.HiiHandle); + gST->ConOut->EnableCursor(gST->ConOut, TRUE); // // ESC was pressed @@ -857,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); @@ -1215,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' ' ){ @@ -1236,7 +1257,6 @@ RunSplitCommand( ASSERT(Split->SplitStdOut != NULL); InsertHeadList(&ShellInfoObject.SplitList.Link, &Split->Link); - ASSERT(StrStr(OurCommandLine, L"|") == NULL); Status = RunCommand(OurCommandLine); // @@ -1296,6 +1316,7 @@ RunCommand( ) { EFI_STATUS Status; + EFI_STATUS StatusCode; CHAR16 *CommandName; SHELL_STATUS ShellStatus; UINTN Argc; @@ -1334,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; } @@ -1419,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 { // @@ -1537,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); @@ -1802,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 @@ -1825,6 +1858,15 @@ 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); } } @@ -1838,6 +1880,9 @@ RunScriptFileHandle ( Status = EFI_SUCCESS; break; } + if (ShellGetExecutionBreakFlag()) { + break; + } if (EFI_ERROR(Status)) { break; }