2018-07-12 14:56:34 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2016-03-04 20:28:21 +00:00
|
|
|
From: Peter Jones <pjones@redhat.com>
|
2016-03-04 18:32:29 +00:00
|
|
|
Date: Wed, 26 Feb 2014 21:49:12 -0500
|
2018-07-10 18:39:10 +00:00
|
|
|
Subject: [PATCH] Make "exit" take a return code.
|
2015-07-22 13:44:51 +00:00
|
|
|
|
|
|
|
This adds "exit" with a return code. With this patch, any "exit"
|
|
|
|
command /may/ include a return code, and on platforms that support
|
|
|
|
returning with an exit status, we will do so. By default we return the
|
|
|
|
same exit status we did before this patch.
|
|
|
|
|
|
|
|
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
|
---
|
|
|
|
grub-core/commands/minicmd.c | 20 ++++++++++++++++----
|
|
|
|
grub-core/kern/efi/efi.c | 9 +++++++--
|
2016-04-05 19:28:47 +00:00
|
|
|
grub-core/kern/emu/main.c | 2 +-
|
2024-10-18 18:18:00 +00:00
|
|
|
grub-core/kern/emu/misc.c | 9 +++++----
|
2015-07-22 13:44:51 +00:00
|
|
|
grub-core/kern/i386/coreboot/init.c | 2 +-
|
|
|
|
grub-core/kern/i386/qemu/init.c | 2 +-
|
|
|
|
grub-core/kern/ieee1275/init.c | 2 +-
|
|
|
|
grub-core/kern/mips/arc/init.c | 2 +-
|
|
|
|
grub-core/kern/mips/loongson/init.c | 2 +-
|
|
|
|
grub-core/kern/mips/qemu_mips/init.c | 2 +-
|
2019-07-16 09:23:51 +00:00
|
|
|
grub-core/kern/misc.c | 11 ++++++++++-
|
2015-07-22 13:44:51 +00:00
|
|
|
grub-core/kern/uboot/init.c | 6 +++---
|
|
|
|
grub-core/kern/xen/init.c | 2 +-
|
2015-07-22 14:14:34 +00:00
|
|
|
include/grub/misc.h | 2 +-
|
2024-10-18 18:18:00 +00:00
|
|
|
14 files changed, 50 insertions(+), 23 deletions(-)
|
2015-07-22 13:44:51 +00:00
|
|
|
|
|
|
|
diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index fa498931ed2..2bd3ac76f2d 100644
|
2015-07-22 13:44:51 +00:00
|
|
|
--- a/grub-core/commands/minicmd.c
|
|
|
|
+++ b/grub-core/commands/minicmd.c
|
2021-03-12 21:54:28 +00:00
|
|
|
@@ -182,12 +182,24 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
|
2015-07-22 13:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* exit */
|
|
|
|
-static grub_err_t __attribute__ ((noreturn))
|
|
|
|
+static grub_err_t
|
|
|
|
grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
|
|
|
|
- int argc __attribute__ ((unused)),
|
|
|
|
- char *argv[] __attribute__ ((unused)))
|
|
|
|
+ int argc, char *argv[])
|
|
|
|
{
|
|
|
|
- grub_exit ();
|
|
|
|
+ int retval = -1;
|
|
|
|
+ unsigned long n;
|
|
|
|
+
|
|
|
|
+ if (argc < 0 || argc > 1)
|
|
|
|
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
|
|
|
|
+
|
|
|
|
+ if (argc == 1)
|
|
|
|
+ {
|
|
|
|
+ n = grub_strtoul (argv[0], 0, 10);
|
|
|
|
+ if (n != ~0UL)
|
|
|
|
+ retval = n;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ grub_exit (retval);
|
|
|
|
/* Not reached. */
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index b93ae3aba12..885d7c6420e 100644
|
2015-07-22 13:44:51 +00:00
|
|
|
--- a/grub-core/kern/efi/efi.c
|
|
|
|
+++ b/grub-core/kern/efi/efi.c
|
2024-10-18 18:18:00 +00:00
|
|
|
@@ -175,11 +175,16 @@ grub_reboot (void)
|
2015-07-22 13:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
-grub_exit (void)
|
|
|
|
+grub_exit (int retval)
|
|
|
|
{
|
2018-01-17 22:04:09 +00:00
|
|
|
+ int rc = GRUB_EFI_LOAD_ERROR;
|
2015-07-22 13:44:51 +00:00
|
|
|
+
|
|
|
|
+ if (retval == 0)
|
|
|
|
+ rc = GRUB_EFI_SUCCESS;
|
|
|
|
+
|
|
|
|
grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
|
2024-10-18 18:18:00 +00:00
|
|
|
grub_efi_system_table->boot_services->exit (grub_efi_image_handle,
|
|
|
|
- GRUB_EFI_SUCCESS, 0, 0);
|
|
|
|
+ rc, 0, 0);
|
2015-07-22 13:44:51 +00:00
|
|
|
for (;;) ;
|
|
|
|
}
|
|
|
|
|
2016-04-05 19:28:47 +00:00
|
|
|
diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index 855b11c3dec..38c1576a2ef 100644
|
2016-04-05 19:28:47 +00:00
|
|
|
--- a/grub-core/kern/emu/main.c
|
|
|
|
+++ b/grub-core/kern/emu/main.c
|
2017-06-16 19:31:32 +00:00
|
|
|
@@ -67,7 +67,7 @@ grub_reboot (void)
|
2016-04-05 19:28:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
-grub_exit (void)
|
|
|
|
+grub_exit (int retval __attribute__((unused)))
|
|
|
|
{
|
|
|
|
grub_reboot ();
|
|
|
|
}
|
2015-07-22 13:44:51 +00:00
|
|
|
diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index 521220b49d2..16c79bc9488 100644
|
2015-07-22 13:44:51 +00:00
|
|
|
--- a/grub-core/kern/emu/misc.c
|
|
|
|
+++ b/grub-core/kern/emu/misc.c
|
2024-10-18 18:18:00 +00:00
|
|
|
@@ -83,7 +83,7 @@ grub_util_error (const char *fmt, ...)
|
|
|
|
vfprintf (stderr, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
fprintf (stderr, ".\n");
|
|
|
|
- grub_exit ();
|
|
|
|
+ grub_exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
@@ -152,12 +152,13 @@ xasprintf (const char *fmt, ...)
|
2015-07-22 13:44:51 +00:00
|
|
|
|
2016-03-04 18:32:29 +00:00
|
|
|
#if !defined (GRUB_MACHINE_EMU) || defined (GRUB_UTIL)
|
2015-07-22 13:44:51 +00:00
|
|
|
void
|
|
|
|
-grub_exit (void)
|
2015-07-22 14:14:34 +00:00
|
|
|
+__attribute__ ((noreturn))
|
2015-07-22 13:44:51 +00:00
|
|
|
+grub_exit (int rc)
|
|
|
|
{
|
2024-10-18 18:18:00 +00:00
|
|
|
-#if defined (GRUB_KERNEL)
|
|
|
|
+#if defined (GRUB_KERNEL) && !defined (GRUB_MACHINE_EFI)
|
|
|
|
grub_reboot ();
|
|
|
|
#endif
|
2015-07-22 13:44:51 +00:00
|
|
|
- exit (1);
|
|
|
|
+ exit (rc < 0 ? 1 : rc);
|
|
|
|
}
|
2016-03-04 18:32:29 +00:00
|
|
|
#endif
|
2015-07-22 13:44:51 +00:00
|
|
|
|
|
|
|
diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index 4fae8b571f1..feaf9295e30 100644
|
2015-07-22 13:44:51 +00:00
|
|
|
--- a/grub-core/kern/i386/coreboot/init.c
|
|
|
|
+++ b/grub-core/kern/i386/coreboot/init.c
|
|
|
|
@@ -41,7 +41,7 @@ extern grub_uint8_t _end[];
|
|
|
|
extern grub_uint8_t _edata[];
|
|
|
|
|
|
|
|
void __attribute__ ((noreturn))
|
|
|
|
-grub_exit (void)
|
|
|
|
+grub_exit (int rc __attribute__((unused)))
|
|
|
|
{
|
|
|
|
/* We can't use grub_fatal() in this function. This would create an infinite
|
|
|
|
loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */
|
|
|
|
diff --git a/grub-core/kern/i386/qemu/init.c b/grub-core/kern/i386/qemu/init.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index 08f81d25e68..604fc94b5a0 100644
|
2015-07-22 13:44:51 +00:00
|
|
|
--- a/grub-core/kern/i386/qemu/init.c
|
|
|
|
+++ b/grub-core/kern/i386/qemu/init.c
|
|
|
|
@@ -42,7 +42,7 @@ extern grub_uint8_t _end[];
|
|
|
|
extern grub_uint8_t _edata[];
|
|
|
|
|
|
|
|
void __attribute__ ((noreturn))
|
|
|
|
-grub_exit (void)
|
|
|
|
+grub_exit (int rc __attribute__((unused)))
|
|
|
|
{
|
|
|
|
/* We can't use grub_fatal() in this function. This would create an infinite
|
|
|
|
loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */
|
|
|
|
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index fb7d1a3bacf..50c65b2f6e5 100644
|
2015-07-22 13:44:51 +00:00
|
|
|
--- a/grub-core/kern/ieee1275/init.c
|
|
|
|
+++ b/grub-core/kern/ieee1275/init.c
|
2024-10-18 18:18:00 +00:00
|
|
|
@@ -114,7 +114,7 @@ grub_addr_t grub_ieee1275_original_stack;
|
|
|
|
#define BYTE22 (DY_MEM_V2 | DRC_INFO)
|
2015-07-22 13:44:51 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
-grub_exit (void)
|
|
|
|
+grub_exit (int rc __attribute__((unused)))
|
|
|
|
{
|
|
|
|
grub_ieee1275_exit ();
|
|
|
|
}
|
|
|
|
diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index 2ed3ff3191e..5c40c34078d 100644
|
2015-07-22 13:44:51 +00:00
|
|
|
--- a/grub-core/kern/mips/arc/init.c
|
|
|
|
+++ b/grub-core/kern/mips/arc/init.c
|
|
|
|
@@ -276,7 +276,7 @@ grub_halt (void)
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
-grub_exit (void)
|
|
|
|
+grub_exit (int rc __attribute__((unused)))
|
|
|
|
{
|
|
|
|
GRUB_ARC_FIRMWARE_VECTOR->exit ();
|
|
|
|
|
|
|
|
diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index 5bd721260f6..97b09b0eeea 100644
|
2015-07-22 13:44:51 +00:00
|
|
|
--- a/grub-core/kern/mips/loongson/init.c
|
|
|
|
+++ b/grub-core/kern/mips/loongson/init.c
|
|
|
|
@@ -304,7 +304,7 @@ grub_halt (void)
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
-grub_exit (void)
|
|
|
|
+grub_exit (int rc __attribute__((unused)))
|
|
|
|
{
|
|
|
|
grub_halt ();
|
|
|
|
}
|
|
|
|
diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index b5477b87ffa..69488a34e7c 100644
|
2015-07-22 13:44:51 +00:00
|
|
|
--- a/grub-core/kern/mips/qemu_mips/init.c
|
|
|
|
+++ b/grub-core/kern/mips/qemu_mips/init.c
|
|
|
|
@@ -75,7 +75,7 @@ grub_machine_fini (int flags __attribute__ ((unused)))
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
-grub_exit (void)
|
|
|
|
+grub_exit (int rc __attribute__((unused)))
|
|
|
|
{
|
|
|
|
grub_halt ();
|
|
|
|
}
|
|
|
|
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index 7cee5d75c3c..11037dc0227 100644
|
2015-07-22 13:44:51 +00:00
|
|
|
--- a/grub-core/kern/misc.c
|
|
|
|
+++ b/grub-core/kern/misc.c
|
2024-10-18 18:18:00 +00:00
|
|
|
@@ -1311,9 +1311,18 @@ grub_abort (void)
|
2015-07-22 13:44:51 +00:00
|
|
|
grub_getkey ();
|
|
|
|
}
|
|
|
|
|
|
|
|
- grub_exit ();
|
|
|
|
+ grub_exit (1);
|
|
|
|
}
|
|
|
|
|
2019-07-16 09:23:51 +00:00
|
|
|
+#if defined (__clang__) && !defined (GRUB_UTIL)
|
|
|
|
+/* clang emits references to abort(). */
|
|
|
|
+void __attribute__ ((noreturn))
|
|
|
|
+abort (void)
|
|
|
|
+{
|
|
|
|
+ grub_abort ();
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
2015-07-22 13:44:51 +00:00
|
|
|
void
|
2019-07-16 09:23:51 +00:00
|
|
|
grub_fatal (const char *fmt, ...)
|
|
|
|
{
|
2015-07-22 13:44:51 +00:00
|
|
|
diff --git a/grub-core/kern/uboot/init.c b/grub-core/kern/uboot/init.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index 3e338645c57..be2a5be1d07 100644
|
2015-07-22 13:44:51 +00:00
|
|
|
--- a/grub-core/kern/uboot/init.c
|
|
|
|
+++ b/grub-core/kern/uboot/init.c
|
2017-06-16 19:31:32 +00:00
|
|
|
@@ -39,9 +39,9 @@ extern grub_size_t grub_total_module_size;
|
|
|
|
static unsigned long timer_start;
|
2015-07-22 13:44:51 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
-grub_exit (void)
|
|
|
|
+grub_exit (int rc)
|
|
|
|
{
|
|
|
|
- grub_uboot_return (0);
|
|
|
|
+ grub_uboot_return (rc < 0 ? 1 : rc);
|
|
|
|
}
|
|
|
|
|
2017-06-16 19:31:32 +00:00
|
|
|
static grub_uint64_t
|
|
|
|
@@ -78,7 +78,7 @@ grub_machine_init (void)
|
2015-07-22 13:44:51 +00:00
|
|
|
if (!ver)
|
|
|
|
{
|
|
|
|
/* Don't even have a console to log errors to... */
|
|
|
|
- grub_exit ();
|
|
|
|
+ grub_exit (-1);
|
|
|
|
}
|
|
|
|
else if (ver > API_SIG_VERSION)
|
|
|
|
{
|
|
|
|
diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c
|
2024-10-18 18:18:00 +00:00
|
|
|
index 782ca72952a..708b060f324 100644
|
2015-07-22 13:44:51 +00:00
|
|
|
--- a/grub-core/kern/xen/init.c
|
|
|
|
+++ b/grub-core/kern/xen/init.c
|
2019-08-15 06:01:31 +00:00
|
|
|
@@ -584,7 +584,7 @@ grub_machine_init (void)
|
2015-07-22 13:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
-grub_exit (void)
|
|
|
|
+grub_exit (int rc __attribute__((unused)))
|
|
|
|
{
|
|
|
|
struct sched_shutdown arg;
|
|
|
|
|
2015-07-22 14:14:34 +00:00
|
|
|
diff --git a/include/grub/misc.h b/include/grub/misc.h
|
2024-10-18 18:18:00 +00:00
|
|
|
index 1b35a167fde..72aff15750d 100644
|
2015-07-22 14:14:34 +00:00
|
|
|
--- a/include/grub/misc.h
|
|
|
|
+++ b/include/grub/misc.h
|
2024-10-18 18:18:00 +00:00
|
|
|
@@ -385,7 +385,7 @@ char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...)
|
2015-07-22 14:14:34 +00:00
|
|
|
__attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT;
|
|
|
|
char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT;
|
2024-10-18 18:18:00 +00:00
|
|
|
|
2015-07-22 14:14:34 +00:00
|
|
|
-void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
|
|
|
|
+void EXPORT_FUNC(grub_exit) (int rc) __attribute__ ((noreturn));
|
2024-10-18 18:18:00 +00:00
|
|
|
void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn));
|
2015-07-22 14:14:34 +00:00
|
|
|
grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
|
|
|
|
grub_uint64_t d,
|