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