ShellPkg: Fix 'EfiShellExecute' doesn't get command status correctly.

1. Add a new  function 'RunShellCommand' to return command status, thus 'EfiShellExecute' can get the command return status of 'CommandLine'.
2. Refine the code logic of 'EfiShellExecute' to make the new image of shell be loaded only if  'Environment' isn't NULL.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Signed-off-by: Jin Eric <eric.jin@intel.com>
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18664 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Qiu Shumin
2015-10-26 13:28:01 +00:00
committed by shenshushi
parent c2305a4af8
commit 490ce43d92
4 changed files with 125 additions and 40 deletions

View File

@ -1631,40 +1631,60 @@ EfiShellExecute(
CHAR16 *Temp;
EFI_DEVICE_PATH_PROTOCOL *DevPath;
UINTN Size;
EFI_STATUS CalleeStatusCode;
if ((PcdGet8(PcdShellSupportLevel) < 1)) {
return (EFI_UNSUPPORTED);
}
DevPath = AppendDevicePath (ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);
if (Environment != NULL) {
// If Environment isn't null, load a new image of the shell with its own
// environment
DevPath = AppendDevicePath (ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);
DEBUG_CODE_BEGIN();
Temp = ConvertDevicePathToText(ShellInfoObject.FileDevPath, TRUE, TRUE);
FreePool(Temp);
Temp = ConvertDevicePathToText(ShellInfoObject.ImageDevPath, TRUE, TRUE);
FreePool(Temp);
Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE);
FreePool(Temp);
DEBUG_CODE_END();
DEBUG_CODE_BEGIN();
Temp = ConvertDevicePathToText(ShellInfoObject.FileDevPath, TRUE, TRUE);
FreePool(Temp);
Temp = ConvertDevicePathToText(ShellInfoObject.ImageDevPath, TRUE, TRUE);
FreePool(Temp);
Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE);
FreePool(Temp);
DEBUG_CODE_END();
Temp = NULL;
Size = 0;
ASSERT((Temp == NULL && Size == 0) || (Temp != NULL));
StrnCatGrow(&Temp, &Size, L"Shell.efi -_exit ", 0);
StrnCatGrow(&Temp, &Size, CommandLine, 0);
Temp = NULL;
Size = 0;
ASSERT((Temp == NULL && Size == 0) || (Temp != NULL));
StrnCatGrow(&Temp, &Size, L"Shell.efi -_exit ", 0);
StrnCatGrow(&Temp, &Size, CommandLine, 0);
Status = InternalShellExecuteDevicePath(
ParentImageHandle,
DevPath,
Temp,
(CONST CHAR16**)Environment,
StatusCode);
Status = InternalShellExecuteDevicePath(
ParentImageHandle,
DevPath,
Temp,
(CONST CHAR16**)Environment,
StatusCode);
//
// de-allocate and return
//
FreePool(DevPath);
FreePool(Temp);
} else {
// If Environment is NULL, we are free to use and mutate the current shell
// environment. This is much faster as uses much less memory.
if (CommandLine == NULL) {
CommandLine = L"";
}
Status = RunShellCommand (CommandLine, &CalleeStatusCode);
// Pass up the command's exit code if the caller wants it
if (StatusCode != NULL) {
*StatusCode = (EFI_STATUS) CalleeStatusCode;
}
}
//
// de-allocate and return
//
FreePool(DevPath);
FreePool(Temp);
return(Status);
}