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

a85e8e
From 2dfde7888d4bcd31b3c88680a96e1e935f01cec6 Mon Sep 17 00:00:00 2001
a85e8e
From: Peter Jones <pjones@redhat.com>
a85e8e
Date: Wed, 26 Feb 2014 21:49:12 -0500
a85e8e
Subject: [PATCH 234/260] Make "exit" take a return code.
a85e8e
a85e8e
This adds "exit" with a return code.  With this patch, any "exit"
a85e8e
command /may/ include a return code, and on platforms that support
a85e8e
returning with an exit status, we will do so.  By default we return the
a85e8e
same exit status we did before this patch.
a85e8e
a85e8e
Signed-off-by: Peter Jones <pjones@redhat.com>
a85e8e
---
a85e8e
 grub-core/commands/minicmd.c         | 20 ++++++++++++++++----
a85e8e
 grub-core/kern/efi/efi.c             |  9 +++++++--
a85e8e
 grub-core/kern/emu/main.c            |  6 ++++++
a85e8e
 grub-core/kern/emu/misc.c            |  5 +++--
a85e8e
 grub-core/kern/i386/coreboot/init.c  |  2 +-
a85e8e
 grub-core/kern/i386/qemu/init.c      |  2 +-
a85e8e
 grub-core/kern/ieee1275/init.c       |  2 +-
a85e8e
 grub-core/kern/mips/arc/init.c       |  2 +-
a85e8e
 grub-core/kern/mips/loongson/init.c  |  2 +-
a85e8e
 grub-core/kern/mips/qemu_mips/init.c |  2 +-
a85e8e
 grub-core/kern/misc.c                |  2 +-
a85e8e
 grub-core/kern/uboot/init.c          |  6 +++---
a85e8e
 grub-core/kern/xen/init.c            |  2 +-
a85e8e
 include/grub/misc.h                  |  2 +-
a85e8e
 14 files changed, 44 insertions(+), 20 deletions(-)
a85e8e
a85e8e
diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c
a85e8e
index a3a118241..b25ca4b9f 100644
a85e8e
--- a/grub-core/commands/minicmd.c
a85e8e
+++ b/grub-core/commands/minicmd.c
a85e8e
@@ -176,12 +176,24 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
a85e8e
 }
a85e8e
 
a85e8e
 /* exit */
a85e8e
-static grub_err_t __attribute__ ((noreturn))
a85e8e
+static grub_err_t
a85e8e
 grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
a85e8e
-		    int argc __attribute__ ((unused)),
a85e8e
-		    char *argv[] __attribute__ ((unused)))
a85e8e
+		    int argc, char *argv[])
a85e8e
 {
a85e8e
-  grub_exit ();
a85e8e
+  int retval = -1;
a85e8e
+  unsigned long n;
a85e8e
+
a85e8e
+  if (argc < 0 || argc > 1)
a85e8e
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
a85e8e
+
a85e8e
+  if (argc == 1)
a85e8e
+    {
a85e8e
+      n = grub_strtoul (argv[0], 0, 10);
a85e8e
+      if (n != ~0UL)
a85e8e
+	retval = n;
a85e8e
+    }
a85e8e
+
a85e8e
+  grub_exit (retval);
a85e8e
   /* Not reached.  */
a85e8e
 }
a85e8e
 
a85e8e
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
a85e8e
index 7dfe2ef14..453f97a75 100644
a85e8e
--- a/grub-core/kern/efi/efi.c
a85e8e
+++ b/grub-core/kern/efi/efi.c
a85e8e
@@ -155,11 +155,16 @@ grub_efi_get_loaded_image (grub_efi_handle_t image_handle)
a85e8e
 }
a85e8e
 
a85e8e
 void
a85e8e
-grub_exit (void)
a85e8e
+grub_exit (int retval)
a85e8e
 {
a85e8e
+  int rc = GRUB_EFI_LOAD_ERROR;
a85e8e
+
a85e8e
+  if (retval == 0)
a85e8e
+    rc = GRUB_EFI_SUCCESS;
a85e8e
+
a85e8e
   grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
a85e8e
   efi_call_4 (grub_efi_system_table->boot_services->exit,
a85e8e
-              grub_efi_image_handle, GRUB_EFI_LOAD_ERROR, 0, 0);
a85e8e
+              grub_efi_image_handle, rc, 0, 0);
a85e8e
   for (;;) ;
a85e8e
 }
a85e8e
 
a85e8e
diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c
a85e8e
index 4b509139c..d7c880c0c 100644
a85e8e
--- a/grub-core/kern/emu/main.c
a85e8e
+++ b/grub-core/kern/emu/main.c
a85e8e
@@ -66,6 +66,12 @@ grub_reboot (void)
a85e8e
 }
a85e8e
 
a85e8e
 void
a85e8e
+grub_exit (int retval __attribute__((unused)))
a85e8e
+{
a85e8e
+  grub_reboot ();
a85e8e
+}
a85e8e
+
a85e8e
+void
a85e8e
 grub_machine_init (void)
a85e8e
 {
a85e8e
 }
a85e8e
diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c
a85e8e
index bb606da28..258a5649e 100644
a85e8e
--- a/grub-core/kern/emu/misc.c
a85e8e
+++ b/grub-core/kern/emu/misc.c
a85e8e
@@ -135,9 +135,10 @@ xasprintf (const char *fmt, ...)
a85e8e
 #endif
a85e8e
 
a85e8e
 void
a85e8e
-grub_exit (void)
a85e8e
+__attribute__ ((noreturn))
a85e8e
+grub_exit (int rc)
a85e8e
 {
a85e8e
-  exit (1);
a85e8e
+  exit (rc < 0 ? 1 : rc);
a85e8e
 }
a85e8e
 
a85e8e
 grub_uint64_t
a85e8e
diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c
a85e8e
index 3314f027f..36f9134b7 100644
a85e8e
--- a/grub-core/kern/i386/coreboot/init.c
a85e8e
+++ b/grub-core/kern/i386/coreboot/init.c
a85e8e
@@ -41,7 +41,7 @@ extern grub_uint8_t _end[];
a85e8e
 extern grub_uint8_t _edata[];
a85e8e
 
a85e8e
 void  __attribute__ ((noreturn))
a85e8e
-grub_exit (void)
a85e8e
+grub_exit (int rc __attribute__((unused)))
a85e8e
 {
a85e8e
   /* We can't use grub_fatal() in this function.  This would create an infinite
a85e8e
      loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit().  */
a85e8e
diff --git a/grub-core/kern/i386/qemu/init.c b/grub-core/kern/i386/qemu/init.c
a85e8e
index 271b6fbfa..9fafe98f0 100644
a85e8e
--- a/grub-core/kern/i386/qemu/init.c
a85e8e
+++ b/grub-core/kern/i386/qemu/init.c
a85e8e
@@ -42,7 +42,7 @@ extern grub_uint8_t _end[];
a85e8e
 extern grub_uint8_t _edata[];
a85e8e
 
a85e8e
 void  __attribute__ ((noreturn))
a85e8e
-grub_exit (void)
a85e8e
+grub_exit (int rc __attribute__((unused)))
a85e8e
 {
a85e8e
   /* We can't use grub_fatal() in this function.  This would create an infinite
a85e8e
      loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit().  */
a85e8e
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
a85e8e
index 8ca4bf79f..e2540bc41 100644
a85e8e
--- a/grub-core/kern/ieee1275/init.c
a85e8e
+++ b/grub-core/kern/ieee1275/init.c
a85e8e
@@ -60,7 +60,7 @@ grub_addr_t grub_ieee1275_original_stack;
a85e8e
 #endif
a85e8e
 
a85e8e
 void
a85e8e
-grub_exit (void)
a85e8e
+grub_exit (int rc __attribute__((unused)))
a85e8e
 {
a85e8e
   grub_ieee1275_exit ();
a85e8e
 }
a85e8e
diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c
a85e8e
index b4f50e496..90049cb53 100644
a85e8e
--- a/grub-core/kern/mips/arc/init.c
a85e8e
+++ b/grub-core/kern/mips/arc/init.c
a85e8e
@@ -276,7 +276,7 @@ grub_halt (void)
a85e8e
 }
a85e8e
 
a85e8e
 void
a85e8e
-grub_exit (void)
a85e8e
+grub_exit (int rc __attribute__((unused)))
a85e8e
 {
a85e8e
   GRUB_ARC_FIRMWARE_VECTOR->exit ();
a85e8e
 
a85e8e
diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c
a85e8e
index 7b96531b9..dff598ca7 100644
a85e8e
--- a/grub-core/kern/mips/loongson/init.c
a85e8e
+++ b/grub-core/kern/mips/loongson/init.c
a85e8e
@@ -304,7 +304,7 @@ grub_halt (void)
a85e8e
 }
a85e8e
 
a85e8e
 void
a85e8e
-grub_exit (void)
a85e8e
+grub_exit (int rc __attribute__((unused)))
a85e8e
 {
a85e8e
   grub_halt ();
a85e8e
 }
a85e8e
diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c
a85e8e
index be88b77d2..8b6c55ffc 100644
a85e8e
--- a/grub-core/kern/mips/qemu_mips/init.c
a85e8e
+++ b/grub-core/kern/mips/qemu_mips/init.c
a85e8e
@@ -75,7 +75,7 @@ grub_machine_fini (int flags __attribute__ ((unused)))
a85e8e
 }
a85e8e
 
a85e8e
 void
a85e8e
-grub_exit (void)
a85e8e
+grub_exit (int rc __attribute__((unused)))
a85e8e
 {
a85e8e
   grub_halt ();
a85e8e
 }
a85e8e
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
a85e8e
index 392c697db..240396c55 100644
a85e8e
--- a/grub-core/kern/misc.c
a85e8e
+++ b/grub-core/kern/misc.c
a85e8e
@@ -1278,7 +1278,7 @@ grub_abort (void)
a85e8e
       grub_getkey ();
a85e8e
     }
a85e8e
 
a85e8e
-  grub_exit ();
a85e8e
+  grub_exit (1);
a85e8e
 }
a85e8e
 
a85e8e
 #if defined (__clang__) && !defined (GRUB_UTIL)
a85e8e
diff --git a/grub-core/kern/uboot/init.c b/grub-core/kern/uboot/init.c
a85e8e
index 5dcc106ed..430c62b66 100644
a85e8e
--- a/grub-core/kern/uboot/init.c
a85e8e
+++ b/grub-core/kern/uboot/init.c
a85e8e
@@ -43,9 +43,9 @@ extern grub_uint32_t grub_uboot_machine_type;
a85e8e
 extern grub_addr_t grub_uboot_boot_data;
a85e8e
 
a85e8e
 void
a85e8e
-grub_exit (void)
a85e8e
+grub_exit (int rc)
a85e8e
 {
a85e8e
-  grub_uboot_return (0);
a85e8e
+  grub_uboot_return (rc < 0 ? 1 : rc);
a85e8e
 }
a85e8e
 
a85e8e
 grub_uint32_t
a85e8e
@@ -94,7 +94,7 @@ grub_machine_init (void)
a85e8e
   if (!ver)
a85e8e
     {
a85e8e
       /* Don't even have a console to log errors to... */
a85e8e
-      grub_exit ();
a85e8e
+      grub_exit (-1);
a85e8e
     }
a85e8e
   else if (ver > API_SIG_VERSION)
a85e8e
     {
a85e8e
diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c
a85e8e
index 0559c033c..fce526d41 100644
a85e8e
--- a/grub-core/kern/xen/init.c
a85e8e
+++ b/grub-core/kern/xen/init.c
a85e8e
@@ -549,7 +549,7 @@ grub_machine_init (void)
a85e8e
 }
a85e8e
 
a85e8e
 void
a85e8e
-grub_exit (void)
a85e8e
+grub_exit (int rc __attribute__((unused)))
a85e8e
 {
a85e8e
   struct sched_shutdown arg;
a85e8e
 
a85e8e
diff --git a/include/grub/misc.h b/include/grub/misc.h
a85e8e
index 342502919..c6851fb9d 100644
a85e8e
--- a/include/grub/misc.h
a85e8e
+++ b/include/grub/misc.h
a85e8e
@@ -398,7 +398,7 @@ int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt,
a85e8e
 char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...)
a85e8e
      __attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT;
a85e8e
 char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT;
a85e8e
-void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
a85e8e
+void EXPORT_FUNC(grub_exit) (int rc) __attribute__ ((noreturn));
a85e8e
 grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
a85e8e
 					  grub_uint64_t d,
a85e8e
 					  grub_uint64_t *r);
a85e8e
-- 
a85e8e
2.13.0
a85e8e