1 /** @file
2 Main file for exit shell level 1 function.
3
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "UefiShellLevel1CommandsLib.h"
11
12 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
13 {L"/b", TypeFlag},
14 {NULL, TypeMax}
15 };
16
17 /**
18 Function for 'exit' command.
19
20 @param[in] ImageHandle Handle to the Image (NULL if Internal).
21 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
22 **/
23 SHELL_STATUS
24 EFIAPI
ShellCommandRunExit(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)25 ShellCommandRunExit (
26 IN EFI_HANDLE ImageHandle,
27 IN EFI_SYSTEM_TABLE *SystemTable
28 )
29 {
30 EFI_STATUS Status;
31 LIST_ENTRY *Package;
32 CHAR16 *ProblemParam;
33 SHELL_STATUS ShellStatus;
34 UINT64 RetVal;
35 CONST CHAR16 *Return;
36
37 ShellStatus = SHELL_SUCCESS;
38
39 //
40 // initialize the shell lib (we must be in non-auto-init...)
41 //
42 Status = ShellInitialize();
43 ASSERT_EFI_ERROR(Status);
44
45 Status = CommandInit();
46 ASSERT_EFI_ERROR(Status);
47
48 //
49 // parse the command line
50 //
51 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
52 if (EFI_ERROR(Status)) {
53 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
54 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, L"exit", ProblemParam);
55 FreePool(ProblemParam);
56 ShellStatus = SHELL_INVALID_PARAMETER;
57 } else {
58 ASSERT(FALSE);
59 }
60 } else {
61
62 //
63 // return the specified error code
64 //
65 Return = ShellCommandLineGetRawValue(Package, 1);
66 if (Return != NULL) {
67 Status = ShellConvertStringToUint64(Return, &RetVal, FALSE, FALSE);
68 if (EFI_ERROR(Status)) {
69 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel1HiiHandle, L"exit", Return);
70 ShellStatus = SHELL_INVALID_PARAMETER;
71 } else {
72 //
73 // If we are in a batch file and /b then pass TRUE otherwise false...
74 //
75 ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")), RetVal);
76
77 ShellStatus = SHELL_SUCCESS;
78 }
79 } else {
80 // If we are in a batch file and /b then pass TRUE otherwise false...
81 //
82 ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")), 0);
83
84 ShellStatus = SHELL_SUCCESS;
85 }
86
87 ShellCommandLineFreeVarList (Package);
88 }
89 return (ShellStatus);
90 }
91
92