Blame SOURCES/0016-Make-exit-take-a-return-code.patch

8631a2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8631a2
From: Peter Jones <pjones@redhat.com>
8631a2
Date: Wed, 26 Feb 2014 21:49:12 -0500
8631a2
Subject: [PATCH] Make "exit" take a return code.
8631a2
8631a2
This adds "exit" with a return code.  With this patch, any "exit"
8631a2
command /may/ include a return code, and on platforms that support
8631a2
returning with an exit status, we will do so.  By default we return the
8631a2
same exit status we did before this patch.
8631a2
8631a2
Signed-off-by: Peter Jones <pjones@redhat.com>
8631a2
---
8631a2
 grub-core/commands/minicmd.c         | 20 ++++++++++++++++----
8631a2
 grub-core/kern/efi/efi.c             |  9 +++++++--
8631a2
 grub-core/kern/emu/main.c            |  2 +-
8631a2
 grub-core/kern/emu/misc.c            |  5 +++--
8631a2
 grub-core/kern/i386/coreboot/init.c  |  2 +-
8631a2
 grub-core/kern/i386/qemu/init.c      |  2 +-
8631a2
 grub-core/kern/ieee1275/init.c       |  2 +-
8631a2
 grub-core/kern/mips/arc/init.c       |  2 +-
8631a2
 grub-core/kern/mips/loongson/init.c  |  2 +-
8631a2
 grub-core/kern/mips/qemu_mips/init.c |  2 +-
8631a2
 grub-core/kern/misc.c                |  2 +-
8631a2
 grub-core/kern/uboot/init.c          |  6 +++---
8631a2
 grub-core/kern/xen/init.c            |  2 +-
8631a2
 include/grub/misc.h                  |  2 +-
8631a2
 14 files changed, 39 insertions(+), 21 deletions(-)
8631a2
8631a2
diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c
8631a2
index a3a11824172..b25ca4b9f17 100644
8631a2
--- a/grub-core/commands/minicmd.c
8631a2
+++ b/grub-core/commands/minicmd.c
8631a2
@@ -176,12 +176,24 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
8631a2
 }
8631a2
 
8631a2
 /* exit */
8631a2
-static grub_err_t __attribute__ ((noreturn))
8631a2
+static grub_err_t
8631a2
 grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
8631a2
-		    int argc __attribute__ ((unused)),
8631a2
-		    char *argv[] __attribute__ ((unused)))
8631a2
+		    int argc, char *argv[])
8631a2
 {
8631a2
-  grub_exit ();
8631a2
+  int retval = -1;
8631a2
+  unsigned long n;
8631a2
+
8631a2
+  if (argc < 0 || argc > 1)
8631a2
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
8631a2
+
8631a2
+  if (argc == 1)
8631a2
+    {
8631a2
+      n = grub_strtoul (argv[0], 0, 10);
8631a2
+      if (n != ~0UL)
8631a2
+	retval = n;
8631a2
+    }
8631a2
+
8631a2
+  grub_exit (retval);
8631a2
   /* Not reached.  */
8631a2
 }
8631a2
 
8631a2
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
8631a2
index 708581fcbde..e339f264b3a 100644
8631a2
--- a/grub-core/kern/efi/efi.c
8631a2
+++ b/grub-core/kern/efi/efi.c
8631a2
@@ -164,11 +164,16 @@ grub_reboot (void)
8631a2
 }
8631a2
 
8631a2
 void
8631a2
-grub_exit (void)
8631a2
+grub_exit (int retval)
8631a2
 {
8631a2
+  int rc = GRUB_EFI_LOAD_ERROR;
8631a2
+
8631a2
+  if (retval == 0)
8631a2
+    rc = GRUB_EFI_SUCCESS;
8631a2
+
8631a2
   grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
8631a2
   efi_call_4 (grub_efi_system_table->boot_services->exit,
8631a2
-              grub_efi_image_handle, GRUB_EFI_SUCCESS, 0, 0);
8631a2
+              grub_efi_image_handle, rc, 0, 0);
8631a2
   for (;;) ;
8631a2
 }
8631a2
 
8631a2
diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c
8631a2
index 425bb960347..55ea5a11ccd 100644
8631a2
--- a/grub-core/kern/emu/main.c
8631a2
+++ b/grub-core/kern/emu/main.c
8631a2
@@ -67,7 +67,7 @@ grub_reboot (void)
8631a2
 }
8631a2
 
8631a2
 void
8631a2
-grub_exit (void)
8631a2
+grub_exit (int retval __attribute__((unused)))
8631a2
 {
8631a2
   grub_reboot ();
8631a2
 }
8631a2
diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c
8631a2
index 76661337f10..82012a72fcb 100644
8631a2
--- a/grub-core/kern/emu/misc.c
8631a2
+++ b/grub-core/kern/emu/misc.c
8631a2
@@ -137,9 +137,10 @@ xasprintf (const char *fmt, ...)
8631a2
 
8631a2
 #if !defined (GRUB_MACHINE_EMU) || defined (GRUB_UTIL)
8631a2
 void
8631a2
-grub_exit (void)
8631a2
+__attribute__ ((noreturn))
8631a2
+grub_exit (int rc)
8631a2
 {
8631a2
-  exit (1);
8631a2
+  exit (rc < 0 ? 1 : rc);
8631a2
 }
8631a2
 #endif
8631a2
 
8631a2
diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c
8631a2
index 3314f027fec..36f9134b7b7 100644
8631a2
--- a/grub-core/kern/i386/coreboot/init.c
8631a2
+++ b/grub-core/kern/i386/coreboot/init.c
8631a2
@@ -41,7 +41,7 @@ extern grub_uint8_t _end[];
8631a2
 extern grub_uint8_t _edata[];
8631a2
 
8631a2
 void  __attribute__ ((noreturn))
8631a2
-grub_exit (void)
8631a2
+grub_exit (int rc __attribute__((unused)))
8631a2
 {
8631a2
   /* We can't use grub_fatal() in this function.  This would create an infinite
8631a2
      loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit().  */
8631a2
diff --git a/grub-core/kern/i386/qemu/init.c b/grub-core/kern/i386/qemu/init.c
8631a2
index 271b6fbfabd..9fafe98f015 100644
8631a2
--- a/grub-core/kern/i386/qemu/init.c
8631a2
+++ b/grub-core/kern/i386/qemu/init.c
8631a2
@@ -42,7 +42,7 @@ extern grub_uint8_t _end[];
8631a2
 extern grub_uint8_t _edata[];
8631a2
 
8631a2
 void  __attribute__ ((noreturn))
8631a2
-grub_exit (void)
8631a2
+grub_exit (int rc __attribute__((unused)))
8631a2
 {
8631a2
   /* We can't use grub_fatal() in this function.  This would create an infinite
8631a2
      loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit().  */
8631a2
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
8631a2
index 0d8ebf58b95..f5423ce27d9 100644
8631a2
--- a/grub-core/kern/ieee1275/init.c
8631a2
+++ b/grub-core/kern/ieee1275/init.c
8631a2
@@ -68,7 +68,7 @@ grub_addr_t grub_ieee1275_original_stack;
8631a2
 #endif
8631a2
 
8631a2
 void
8631a2
-grub_exit (void)
8631a2
+grub_exit (int rc __attribute__((unused)))
8631a2
 {
8631a2
   grub_ieee1275_exit ();
8631a2
 }
8631a2
diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c
8631a2
index 3834a149093..86b3a25ec40 100644
8631a2
--- a/grub-core/kern/mips/arc/init.c
8631a2
+++ b/grub-core/kern/mips/arc/init.c
8631a2
@@ -276,7 +276,7 @@ grub_halt (void)
8631a2
 }
8631a2
 
8631a2
 void
8631a2
-grub_exit (void)
8631a2
+grub_exit (int rc __attribute__((unused)))
8631a2
 {
8631a2
   GRUB_ARC_FIRMWARE_VECTOR->exit ();
8631a2
 
8631a2
diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c
8631a2
index 7b96531b983..dff598ca7b0 100644
8631a2
--- a/grub-core/kern/mips/loongson/init.c
8631a2
+++ b/grub-core/kern/mips/loongson/init.c
8631a2
@@ -304,7 +304,7 @@ grub_halt (void)
8631a2
 }
8631a2
 
8631a2
 void
8631a2
-grub_exit (void)
8631a2
+grub_exit (int rc __attribute__((unused)))
8631a2
 {
8631a2
   grub_halt ();
8631a2
 }
8631a2
diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c
8631a2
index be88b77d22d..8b6c55ffc01 100644
8631a2
--- a/grub-core/kern/mips/qemu_mips/init.c
8631a2
+++ b/grub-core/kern/mips/qemu_mips/init.c
8631a2
@@ -75,7 +75,7 @@ grub_machine_fini (int flags __attribute__ ((unused)))
8631a2
 }
8631a2
 
8631a2
 void
8631a2
-grub_exit (void)
8631a2
+grub_exit (int rc __attribute__((unused)))
8631a2
 {
8631a2
   grub_halt ();
8631a2
 }
8631a2
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
8631a2
index 3b633d51f4c..952411d5dc6 100644
8631a2
--- a/grub-core/kern/misc.c
8631a2
+++ b/grub-core/kern/misc.c
8631a2
@@ -1095,7 +1095,7 @@ grub_abort (void)
8631a2
       grub_getkey ();
8631a2
     }
8631a2
 
8631a2
-  grub_exit ();
8631a2
+  grub_exit (1);
8631a2
 }
8631a2
 
8631a2
 void
8631a2
diff --git a/grub-core/kern/uboot/init.c b/grub-core/kern/uboot/init.c
8631a2
index 3e338645c57..be2a5be1d07 100644
8631a2
--- a/grub-core/kern/uboot/init.c
8631a2
+++ b/grub-core/kern/uboot/init.c
8631a2
@@ -39,9 +39,9 @@ extern grub_size_t grub_total_module_size;
8631a2
 static unsigned long timer_start;
8631a2
 
8631a2
 void
8631a2
-grub_exit (void)
8631a2
+grub_exit (int rc)
8631a2
 {
8631a2
-  grub_uboot_return (0);
8631a2
+  grub_uboot_return (rc < 0 ? 1 : rc);
8631a2
 }
8631a2
 
8631a2
 static grub_uint64_t
8631a2
@@ -78,7 +78,7 @@ grub_machine_init (void)
8631a2
   if (!ver)
8631a2
     {
8631a2
       /* Don't even have a console to log errors to... */
8631a2
-      grub_exit ();
8631a2
+      grub_exit (-1);
8631a2
     }
8631a2
   else if (ver > API_SIG_VERSION)
8631a2
     {
8631a2
diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c
8631a2
index 0559c033c3d..fce526d417b 100644
8631a2
--- a/grub-core/kern/xen/init.c
8631a2
+++ b/grub-core/kern/xen/init.c
8631a2
@@ -549,7 +549,7 @@ grub_machine_init (void)
8631a2
 }
8631a2
 
8631a2
 void
8631a2
-grub_exit (void)
8631a2
+grub_exit (int rc __attribute__((unused)))
8631a2
 {
8631a2
   struct sched_shutdown arg;
8631a2
 
8631a2
diff --git a/include/grub/misc.h b/include/grub/misc.h
8631a2
index 372f009e84f..83fd69f4ada 100644
8631a2
--- a/include/grub/misc.h
8631a2
+++ b/include/grub/misc.h
8631a2
@@ -334,7 +334,7 @@ int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt,
8631a2
 char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...)
8631a2
      __attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT;
8631a2
 char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT;
8631a2
-void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
8631a2
+void EXPORT_FUNC(grub_exit) (int rc) __attribute__ ((noreturn));
8631a2
 grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
8631a2
 					  grub_uint64_t d,
8631a2
 					  grub_uint64_t *r);