|
|
f731ee |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
f731ee |
From: Peter Jones <pjones@redhat.com>
|
|
|
f731ee |
Date: Wed, 26 Feb 2014 21:49:12 -0500
|
|
|
f731ee |
Subject: [PATCH] Make "exit" take a return code.
|
|
|
f731ee |
|
|
|
f731ee |
This adds "exit" with a return code. With this patch, any "exit"
|
|
|
f731ee |
command /may/ include a return code, and on platforms that support
|
|
|
f731ee |
returning with an exit status, we will do so. By default we return the
|
|
|
f731ee |
same exit status we did before this patch.
|
|
|
f731ee |
|
|
|
f731ee |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
f731ee |
---
|
|
|
f731ee |
grub-core/commands/minicmd.c | 20 ++++++++++++++++----
|
|
|
f731ee |
grub-core/kern/efi/efi.c | 9 +++++++--
|
|
|
f731ee |
grub-core/kern/emu/main.c | 6 ++++++
|
|
|
f731ee |
grub-core/kern/emu/misc.c | 5 +++--
|
|
|
f731ee |
grub-core/kern/i386/coreboot/init.c | 2 +-
|
|
|
f731ee |
grub-core/kern/i386/qemu/init.c | 2 +-
|
|
|
f731ee |
grub-core/kern/ieee1275/init.c | 2 +-
|
|
|
f731ee |
grub-core/kern/mips/arc/init.c | 2 +-
|
|
|
f731ee |
grub-core/kern/mips/loongson/init.c | 2 +-
|
|
|
f731ee |
grub-core/kern/mips/qemu_mips/init.c | 2 +-
|
|
|
f731ee |
grub-core/kern/misc.c | 2 +-
|
|
|
f731ee |
grub-core/kern/uboot/init.c | 6 +++---
|
|
|
f731ee |
grub-core/kern/xen/init.c | 2 +-
|
|
|
f731ee |
include/grub/misc.h | 2 +-
|
|
|
f731ee |
14 files changed, 44 insertions(+), 20 deletions(-)
|
|
|
f731ee |
|
|
|
f731ee |
diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c
|
|
|
f731ee |
index a3a11824172..b25ca4b9f17 100644
|
|
|
f731ee |
--- a/grub-core/commands/minicmd.c
|
|
|
f731ee |
+++ b/grub-core/commands/minicmd.c
|
|
|
f731ee |
@@ -176,12 +176,24 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
/* exit */
|
|
|
f731ee |
-static grub_err_t __attribute__ ((noreturn))
|
|
|
f731ee |
+static grub_err_t
|
|
|
f731ee |
grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
|
|
|
f731ee |
- int argc __attribute__ ((unused)),
|
|
|
f731ee |
- char *argv[] __attribute__ ((unused)))
|
|
|
f731ee |
+ int argc, char *argv[])
|
|
|
f731ee |
{
|
|
|
f731ee |
- grub_exit ();
|
|
|
f731ee |
+ int retval = -1;
|
|
|
f731ee |
+ unsigned long n;
|
|
|
f731ee |
+
|
|
|
f731ee |
+ if (argc < 0 || argc > 1)
|
|
|
f731ee |
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
|
|
|
f731ee |
+
|
|
|
f731ee |
+ if (argc == 1)
|
|
|
f731ee |
+ {
|
|
|
f731ee |
+ n = grub_strtoul (argv[0], 0, 10);
|
|
|
f731ee |
+ if (n != ~0UL)
|
|
|
f731ee |
+ retval = n;
|
|
|
f731ee |
+ }
|
|
|
f731ee |
+
|
|
|
f731ee |
+ grub_exit (retval);
|
|
|
f731ee |
/* Not reached. */
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
|
|
|
f731ee |
index 7dfe2ef1455..453f97a7595 100644
|
|
|
f731ee |
--- a/grub-core/kern/efi/efi.c
|
|
|
f731ee |
+++ b/grub-core/kern/efi/efi.c
|
|
|
f731ee |
@@ -155,11 +155,16 @@ grub_efi_get_loaded_image (grub_efi_handle_t image_handle)
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
void
|
|
|
f731ee |
-grub_exit (void)
|
|
|
f731ee |
+grub_exit (int retval)
|
|
|
f731ee |
{
|
|
|
f731ee |
+ int rc = GRUB_EFI_LOAD_ERROR;
|
|
|
f731ee |
+
|
|
|
f731ee |
+ if (retval == 0)
|
|
|
f731ee |
+ rc = GRUB_EFI_SUCCESS;
|
|
|
f731ee |
+
|
|
|
f731ee |
grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
|
|
|
f731ee |
efi_call_4 (grub_efi_system_table->boot_services->exit,
|
|
|
f731ee |
- grub_efi_image_handle, GRUB_EFI_LOAD_ERROR, 0, 0);
|
|
|
f731ee |
+ grub_efi_image_handle, rc, 0, 0);
|
|
|
f731ee |
for (;;) ;
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c
|
|
|
f731ee |
index 4b509139c4a..d7c880c0c1f 100644
|
|
|
f731ee |
--- a/grub-core/kern/emu/main.c
|
|
|
f731ee |
+++ b/grub-core/kern/emu/main.c
|
|
|
f731ee |
@@ -65,6 +65,12 @@ grub_reboot (void)
|
|
|
f731ee |
longjmp (main_env, 1);
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
+void
|
|
|
f731ee |
+grub_exit (int retval __attribute__((unused)))
|
|
|
f731ee |
+{
|
|
|
f731ee |
+ grub_reboot ();
|
|
|
f731ee |
+}
|
|
|
f731ee |
+
|
|
|
f731ee |
void
|
|
|
f731ee |
grub_machine_init (void)
|
|
|
f731ee |
{
|
|
|
f731ee |
diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c
|
|
|
f731ee |
index bb606da2803..258a5649e2d 100644
|
|
|
f731ee |
--- a/grub-core/kern/emu/misc.c
|
|
|
f731ee |
+++ b/grub-core/kern/emu/misc.c
|
|
|
f731ee |
@@ -135,9 +135,10 @@ xasprintf (const char *fmt, ...)
|
|
|
f731ee |
#endif
|
|
|
f731ee |
|
|
|
f731ee |
void
|
|
|
f731ee |
-grub_exit (void)
|
|
|
f731ee |
+__attribute__ ((noreturn))
|
|
|
f731ee |
+grub_exit (int rc)
|
|
|
f731ee |
{
|
|
|
f731ee |
- exit (1);
|
|
|
f731ee |
+ exit (rc < 0 ? 1 : rc);
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
grub_uint64_t
|
|
|
f731ee |
diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c
|
|
|
f731ee |
index 3314f027fec..36f9134b7b7 100644
|
|
|
f731ee |
--- a/grub-core/kern/i386/coreboot/init.c
|
|
|
f731ee |
+++ b/grub-core/kern/i386/coreboot/init.c
|
|
|
f731ee |
@@ -41,7 +41,7 @@ extern grub_uint8_t _end[];
|
|
|
f731ee |
extern grub_uint8_t _edata[];
|
|
|
f731ee |
|
|
|
f731ee |
void __attribute__ ((noreturn))
|
|
|
f731ee |
-grub_exit (void)
|
|
|
f731ee |
+grub_exit (int rc __attribute__((unused)))
|
|
|
f731ee |
{
|
|
|
f731ee |
/* We can't use grub_fatal() in this function. This would create an infinite
|
|
|
f731ee |
loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */
|
|
|
f731ee |
diff --git a/grub-core/kern/i386/qemu/init.c b/grub-core/kern/i386/qemu/init.c
|
|
|
f731ee |
index 271b6fbfabd..9fafe98f015 100644
|
|
|
f731ee |
--- a/grub-core/kern/i386/qemu/init.c
|
|
|
f731ee |
+++ b/grub-core/kern/i386/qemu/init.c
|
|
|
f731ee |
@@ -42,7 +42,7 @@ extern grub_uint8_t _end[];
|
|
|
f731ee |
extern grub_uint8_t _edata[];
|
|
|
f731ee |
|
|
|
f731ee |
void __attribute__ ((noreturn))
|
|
|
f731ee |
-grub_exit (void)
|
|
|
f731ee |
+grub_exit (int rc __attribute__((unused)))
|
|
|
f731ee |
{
|
|
|
f731ee |
/* We can't use grub_fatal() in this function. This would create an infinite
|
|
|
f731ee |
loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */
|
|
|
f731ee |
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
|
|
|
f731ee |
index 8ca4bf79f09..e2540bc41ce 100644
|
|
|
f731ee |
--- a/grub-core/kern/ieee1275/init.c
|
|
|
f731ee |
+++ b/grub-core/kern/ieee1275/init.c
|
|
|
f731ee |
@@ -60,7 +60,7 @@ grub_addr_t grub_ieee1275_original_stack;
|
|
|
f731ee |
#endif
|
|
|
f731ee |
|
|
|
f731ee |
void
|
|
|
f731ee |
-grub_exit (void)
|
|
|
f731ee |
+grub_exit (int rc __attribute__((unused)))
|
|
|
f731ee |
{
|
|
|
f731ee |
grub_ieee1275_exit ();
|
|
|
f731ee |
}
|
|
|
f731ee |
diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c
|
|
|
f731ee |
index b4f50e49642..90049cb53ce 100644
|
|
|
f731ee |
--- a/grub-core/kern/mips/arc/init.c
|
|
|
f731ee |
+++ b/grub-core/kern/mips/arc/init.c
|
|
|
f731ee |
@@ -276,7 +276,7 @@ grub_halt (void)
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
void
|
|
|
f731ee |
-grub_exit (void)
|
|
|
f731ee |
+grub_exit (int rc __attribute__((unused)))
|
|
|
f731ee |
{
|
|
|
f731ee |
GRUB_ARC_FIRMWARE_VECTOR->exit ();
|
|
|
f731ee |
|
|
|
f731ee |
diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c
|
|
|
f731ee |
index 7b96531b983..dff598ca7b0 100644
|
|
|
f731ee |
--- a/grub-core/kern/mips/loongson/init.c
|
|
|
f731ee |
+++ b/grub-core/kern/mips/loongson/init.c
|
|
|
f731ee |
@@ -304,7 +304,7 @@ grub_halt (void)
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
void
|
|
|
f731ee |
-grub_exit (void)
|
|
|
f731ee |
+grub_exit (int rc __attribute__((unused)))
|
|
|
f731ee |
{
|
|
|
f731ee |
grub_halt ();
|
|
|
f731ee |
}
|
|
|
f731ee |
diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c
|
|
|
f731ee |
index be88b77d22d..8b6c55ffc01 100644
|
|
|
f731ee |
--- a/grub-core/kern/mips/qemu_mips/init.c
|
|
|
f731ee |
+++ b/grub-core/kern/mips/qemu_mips/init.c
|
|
|
f731ee |
@@ -75,7 +75,7 @@ grub_machine_fini (int flags __attribute__ ((unused)))
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
void
|
|
|
f731ee |
-grub_exit (void)
|
|
|
f731ee |
+grub_exit (int rc __attribute__((unused)))
|
|
|
f731ee |
{
|
|
|
f731ee |
grub_halt ();
|
|
|
f731ee |
}
|
|
|
f731ee |
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
|
|
|
f731ee |
index 392c697db03..240396c55f3 100644
|
|
|
f731ee |
--- a/grub-core/kern/misc.c
|
|
|
f731ee |
+++ b/grub-core/kern/misc.c
|
|
|
f731ee |
@@ -1278,7 +1278,7 @@ grub_abort (void)
|
|
|
f731ee |
grub_getkey ();
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
- grub_exit ();
|
|
|
f731ee |
+ grub_exit (1);
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
#if defined (__clang__) && !defined (GRUB_UTIL)
|
|
|
f731ee |
diff --git a/grub-core/kern/uboot/init.c b/grub-core/kern/uboot/init.c
|
|
|
f731ee |
index 5dcc106ed9b..430c62b66e0 100644
|
|
|
f731ee |
--- a/grub-core/kern/uboot/init.c
|
|
|
f731ee |
+++ b/grub-core/kern/uboot/init.c
|
|
|
f731ee |
@@ -43,9 +43,9 @@ extern grub_uint32_t grub_uboot_machine_type;
|
|
|
f731ee |
extern grub_addr_t grub_uboot_boot_data;
|
|
|
f731ee |
|
|
|
f731ee |
void
|
|
|
f731ee |
-grub_exit (void)
|
|
|
f731ee |
+grub_exit (int rc)
|
|
|
f731ee |
{
|
|
|
f731ee |
- grub_uboot_return (0);
|
|
|
f731ee |
+ grub_uboot_return (rc < 0 ? 1 : rc);
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
grub_uint32_t
|
|
|
f731ee |
@@ -94,7 +94,7 @@ grub_machine_init (void)
|
|
|
f731ee |
if (!ver)
|
|
|
f731ee |
{
|
|
|
f731ee |
/* Don't even have a console to log errors to... */
|
|
|
f731ee |
- grub_exit ();
|
|
|
f731ee |
+ grub_exit (-1);
|
|
|
f731ee |
}
|
|
|
f731ee |
else if (ver > API_SIG_VERSION)
|
|
|
f731ee |
{
|
|
|
f731ee |
diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c
|
|
|
f731ee |
index 0559c033c3d..fce526d417b 100644
|
|
|
f731ee |
--- a/grub-core/kern/xen/init.c
|
|
|
f731ee |
+++ b/grub-core/kern/xen/init.c
|
|
|
f731ee |
@@ -549,7 +549,7 @@ grub_machine_init (void)
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
void
|
|
|
f731ee |
-grub_exit (void)
|
|
|
f731ee |
+grub_exit (int rc __attribute__((unused)))
|
|
|
f731ee |
{
|
|
|
f731ee |
struct sched_shutdown arg;
|
|
|
f731ee |
|
|
|
f731ee |
diff --git a/include/grub/misc.h b/include/grub/misc.h
|
|
|
f731ee |
index 34250291908..c6851fb9dcf 100644
|
|
|
f731ee |
--- a/include/grub/misc.h
|
|
|
f731ee |
+++ b/include/grub/misc.h
|
|
|
f731ee |
@@ -398,7 +398,7 @@ int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt,
|
|
|
f731ee |
char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...)
|
|
|
f731ee |
__attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT;
|
|
|
f731ee |
char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT;
|
|
|
f731ee |
-void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
|
|
|
f731ee |
+void EXPORT_FUNC(grub_exit) (int rc) __attribute__ ((noreturn));
|
|
|
f731ee |
grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
|
|
|
f731ee |
grub_uint64_t d,
|
|
|
f731ee |
grub_uint64_t *r);
|