]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c
ShellPkg/Dp: Add null pointer check
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel1CommandsLib / Exit.c
CommitLineData
a405b86d 1/** @file\r
2 Main file for exit shell level 1 function.\r
3\r
c011b6c9 4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
77dcec12 5 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
a405b86d 6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "UefiShellLevel1CommandsLib.h"\r
17\r
18STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
19 {L"/b", TypeFlag},\r
20 {NULL, TypeMax}\r
21 };\r
22\r
23/**\r
24 Function for 'exit' command.\r
25\r
26 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
27 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
28**/\r
29SHELL_STATUS\r
30EFIAPI\r
31ShellCommandRunExit (\r
32 IN EFI_HANDLE ImageHandle,\r
33 IN EFI_SYSTEM_TABLE *SystemTable\r
34 )\r
35{\r
36 EFI_STATUS Status;\r
37 LIST_ENTRY *Package;\r
38 CHAR16 *ProblemParam;\r
39 SHELL_STATUS ShellStatus;\r
77dcec12 40 UINT64 RetVal;\r
41 CONST CHAR16 *Return;\r
a405b86d 42\r
43 ShellStatus = SHELL_SUCCESS;\r
44\r
45 //\r
46 // initialize the shell lib (we must be in non-auto-init...)\r
47 //\r
48 Status = ShellInitialize();\r
49 ASSERT_EFI_ERROR(Status);\r
50\r
51 Status = CommandInit();\r
52 ASSERT_EFI_ERROR(Status);\r
53\r
54 //\r
55 // parse the command line\r
56 //\r
57 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
58 if (EFI_ERROR(Status)) {\r
59 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
0861edab 60 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, L"exit", ProblemParam);\r
a405b86d 61 FreePool(ProblemParam);\r
62 ShellStatus = SHELL_INVALID_PARAMETER;\r
63 } else {\r
64 ASSERT(FALSE);\r
65 }\r
66 } else {\r
67\r
a405b86d 68 //\r
69 // return the specified error code\r
70 //\r
77dcec12 71 Return = ShellCommandLineGetRawValue(Package, 1);\r
72 if (Return != NULL) {\r
73 Status = ShellConvertStringToUint64(Return, &RetVal, FALSE, FALSE);\r
74 if (EFI_ERROR(Status)) {\r
0861edab 75 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel1HiiHandle, L"exit", Return);\r
77dcec12 76 ShellStatus = SHELL_INVALID_PARAMETER;\r
77 } else {\r
78 //\r
79 // If we are in a batch file and /b then pass TRUE otherwise false...\r
80 //\r
b6b22b13 81 ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")), RetVal);\r
77dcec12 82\r
b6b22b13 83 ShellStatus = SHELL_SUCCESS;\r
77dcec12 84 }\r
85 } else {\r
86 // If we are in a batch file and /b then pass TRUE otherwise false...\r
87 //\r
b6b22b13 88 ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")), 0);\r
77dcec12 89\r
b6b22b13 90 ShellStatus = SHELL_SUCCESS;\r
a405b86d 91 }\r
92\r
93 ShellCommandLineFreeVarList (Package);\r
94 }\r
95 return (ShellStatus);\r
96}\r
97\r