]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/Shell.c
ShellPkg: CTRL-C stops a running script at the same time
[mirror_edk2.git] / ShellPkg / Application / Shell / Shell.c
index fe722e955448bd0c60d6901da4bf3f9d350e85fc..5e3af1d0565644add4095a1bb42a8288434cdc9f 100644 (file)
@@ -1840,8 +1840,19 @@ RunInternalCommand(
       // Pass thru the exitcode from the app.\r
       //\r
       if (ShellCommandGetExit()) {\r
+        //\r
+        // An Exit was requested ("exit" command), pass its value up.\r
+        //\r
         Status = CommandReturnedStatus;\r
-      } else if (CommandReturnedStatus != 0 && IsScriptOnlyCommand(FirstParameter)) {\r
+      } else if (CommandReturnedStatus != SHELL_SUCCESS && IsScriptOnlyCommand(FirstParameter)) {\r
+        //\r
+        // Always abort when a script only command fails for any reason\r
+        //\r
+        Status = EFI_ABORTED;\r
+      } else if (ShellCommandGetCurrentScriptFile() != NULL && CommandReturnedStatus == SHELL_ABORTED) {\r
+        //\r
+        // Abort when in a script and a command aborted\r
+        //\r
         Status = EFI_ABORTED;\r
       }\r
     }\r
@@ -1853,11 +1864,17 @@ RunInternalCommand(
   //\r
   RestoreArgcArgv(ParamProtocol, &Argv, &Argc);\r
 \r
-  if (ShellCommandGetCurrentScriptFile() != NULL &&  !IsScriptOnlyCommand(FirstParameter)) {\r
-    //\r
-    // if this is NOT a scipt only command return success so the script won't quit.\r
-    // prevent killing the script - this is the only place where we know the actual command name (after alias and variable replacement...)\r
-    //\r
+  //\r
+  // If a script is running and the command is not a scipt only command, then\r
+  // change return value to success so the script won't halt (unless aborted).\r
+  //\r
+  // Script only commands have to be able halt the script since the script will\r
+  // not operate if they are failing.\r
+  //\r
+  if ( ShellCommandGetCurrentScriptFile() != NULL\r
+    && !IsScriptOnlyCommand(FirstParameter)\r
+    && Status != EFI_ABORTED\r
+    ) {\r
     Status = EFI_SUCCESS;\r
   }\r
 \r