X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FApplication%2FShell%2FShell.c;h=3e4706c288dbd2cbac12ce28af1c34fbbfb73e10;hp=ecd48cdd78719149670ff1f464e955e9d1963b52;hb=ce68d3bc68eda5ce919b90aea8db094ed4b64c34;hpb=33c031ee2092282a069ce07d30202082ceaf61fe diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index ecd48cdd78..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,12 +52,17 @@ 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 + NULL, + NULL, + FALSE }; STATIC CONST CHAR16 mScriptExtension[] = L".NSH"; @@ -155,17 +162,11 @@ UefiMain ( IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; - CHAR16 *TempString; - UINTN Size; -// EFI_INPUT_KEY Key; - -// gST->ConOut->OutputString(gST->ConOut, L"ReadKeyStroke Calling\r\n"); -// -// Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); -// -// gST->ConOut->OutputString(gST->ConOut, L"ReadKeyStroke Done\r\n"); -// gBS->Stall (1000000); + EFI_STATUS Status; + CHAR16 *TempString; + UINTN Size; + EFI_HANDLE ConInHandle; + EFI_SIMPLE_TEXT_INPUT_PROTOCOL *OldConIn; if (PcdGet8(PcdShellSupportLevel) > 3) { return (EFI_UNSUPPORTED); @@ -361,6 +362,18 @@ UefiMain ( Status = InternalEfiShellStartCtrlSMonitor(); } + if (!EFI_ERROR(Status) && ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) { + // + // close off the gST->ConIn + // + OldConIn = gST->ConIn; + ConInHandle = gST->ConsoleInHandle; + gST->ConIn = CreateSimpleTextInOnFile((SHELL_FILE_HANDLE)&FileInterfaceNulFile, &gST->ConsoleInHandle); + } else { + OldConIn = NULL; + ConInHandle = NULL; + } + if (!EFI_ERROR(Status) && PcdGet8(PcdShellSupportLevel) >= 1) { // // process the startup script or launch the called app. @@ -399,6 +412,11 @@ UefiMain ( Status = DoShellPrompt(); } while (!ShellCommandGetExit()); } + if (OldConIn != NULL && ConInHandle != NULL) { + CloseSimpleTextInOnFile (gST->ConIn); + gST->ConIn = OldConIn; + gST->ConsoleInHandle = ConInHandle; + } } } @@ -463,6 +481,9 @@ UefiMain ( DEBUG_CODE(ShellInfoObject.ConsoleInfo = NULL;); } + if (ShellCommandGetExit()) { + return ((EFI_STATUS)ShellCommandGetExitCode()); + } return (Status); } @@ -548,16 +569,14 @@ IsScriptOnlyCommand( return (FALSE); } - - /** This function will populate the 2 device path protocol parameters based on the global gImageHandle. The DevPath will point to the device path for the handle that has loaded image protocol installed on it. The FilePath will point to the device path for the file that was loaded. - @param[in,out] DevPath On a sucessful return the device path to the loaded image. - @param[in,out] FilePath On a sucessful return the device path to the file. + @param[in, out] DevPath On a sucessful return the device path to the loaded image. + @param[in, out] FilePath On a sucessful return the device path to the file. @retval EFI_SUCCESS The 2 device paths were sucessfully returned. @retval other A error from gBS->HandleProtocol. @@ -598,6 +617,11 @@ GetDevicePathsForImageAndFile ( if (!EFI_ERROR (Status)) { *DevPath = DuplicateDevicePath (ImageDevicePath); *FilePath = DuplicateDevicePath (LoadedImage->FilePath); + gBS->CloseProtocol( + LoadedImage->DeviceHandle, + &gEfiDevicePathProtocolGuid, + gImageHandle, + NULL); } gBS->CloseProtocol( gImageHandle, @@ -620,6 +644,7 @@ STATIC CONST SHELL_PARAM_ITEM mShellParamList[] = { {L"-delay", TypeValue}, {NULL, TypeMax} }; + /** Process all Uefi Shell 2.0 command line options. @@ -808,6 +833,7 @@ DoStartupScript( return (EFI_SUCCESS); } + gST->ConOut->EnableCursor(gST->ConOut, FALSE); // // print out our warning and see if they press a key // @@ -822,6 +848,7 @@ DoStartupScript( } } ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CRLF), ShellInfoObject.HiiHandle); + gST->ConOut->EnableCursor(gST->ConOut, TRUE); // // ESC was pressed @@ -838,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); - ChopLastSlash(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); @@ -1000,10 +1031,10 @@ AddLineToCommandHistory( Checks if a string is an alias for another command. If yes, then it replaces the alias name with the correct command name. - @param[in,out] CommandString Upon entry the potential alias. Upon return the - command name if it was an alias. If it was not - an alias it will be unchanged. This function may - change the buffer to fit the command name. + @param[in, out] CommandString Upon entry the potential alias. Upon return the + command name if it was an alias. If it was not + an alias it will be unchanged. This function may + change the buffer to fit the command name. @retval EFI_SUCCESS The name was changed. @retval EFI_SUCCESS The name was not an alias. @@ -1196,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' ' ){ @@ -1217,7 +1257,6 @@ RunSplitCommand( ASSERT(Split->SplitStdOut != NULL); InsertHeadList(&ShellInfoObject.SplitList.Link, &Split->Link); - ASSERT(StrStr(OurCommandLine, L"|") == NULL); Status = RunCommand(OurCommandLine); // @@ -1277,6 +1316,7 @@ RunCommand( ) { EFI_STATUS Status; + EFI_STATUS StatusCode; CHAR16 *CommandName; SHELL_STATUS ShellStatus; UINTN Argc; @@ -1315,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; } @@ -1400,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 { // @@ -1427,21 +1473,6 @@ RunCommand( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle); } } else { - // - // remove the < and/or > from the command line now - // - for (TempLocation3 = PostVariableCmdLine ; TempLocation3 != NULL && *TempLocation3 != CHAR_NULL ; TempLocation3++) { - if (*TempLocation3 == L'^') { - if (*(TempLocation3+1) == L'<' || *(TempLocation3+1) == L'>') { - CopyMem(TempLocation3, TempLocation3+1, StrSize(TempLocation3) - sizeof(TempLocation3[0])); - } - } else if (*TempLocation3 == L'>') { - *TempLocation3 = CHAR_NULL; - } else if ((*TempLocation3 == L'1' || *TempLocation3 == L'2')&&(*(TempLocation3+1) == L'>')) { - *TempLocation3 = CHAR_NULL; - } - } - while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') { PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL; } @@ -1533,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); @@ -1618,8 +1664,10 @@ RunScriptFileHandle ( SCRIPT_COMMAND_LIST *LastCommand; BOOLEAN Ascii; BOOLEAN PreScriptEchoState; + BOOLEAN PreCommandEchoState; CONST CHAR16 *CurDir; UINTN LineCount; + CHAR16 LeString[50]; ASSERT(!ShellCommandGetScriptExit()); @@ -1796,23 +1844,45 @@ 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); + if (CommandLine3[0] == L'@') { + // + // We need to save the current echo state + // and disable echo for just this command. + // + PreCommandEchoState = ShellCommandGetEchoState(); + ShellCommandSetEchoState(FALSE); + Status = RunCommand(CommandLine3+1); + + // + // Now restore the pre-'@' echo state. + // + 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); } - ShellPrintEx(-1, -1, L"%s\r\n", CommandLine2); + Status = RunCommand(CommandLine3); } - 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; }