X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fcommon%2Fui-system.c;h=ad3bfba8a9d4534507f849925fd3e2b42bc26afd;hp=157c6db7797c30ec286ed010094b920e98772b63;hb=c62667e5c78ea212e5ac49244e9792954a1d8f71;hpb=b8122dc9340e2f208220f0c88b4d71f91b78774f diff --git a/ui/common/ui-system.c b/ui/common/ui-system.c index 157c6db..ad3bfba 100644 --- a/ui/common/ui-system.c +++ b/ui/common/ui-system.c @@ -29,7 +29,6 @@ #include "log/log.h" #include #include "talloc/talloc.h" -#include "loader.h" #include "ui-system.h" /** @@ -56,141 +55,6 @@ int pb_start_daemon(void) return result; } -/** - * kexec_load - kexec load helper. - * @l_image: The local image file for kexec to execute. - * @l_initrd: Optional local initrd file for kexec --initrd, can be NULL. - * @args: Optional command line args for kexec --append, can be NULL. - */ - -static int kexec_load(const char *l_image, const char *l_initrd, - const char *args, int dry_run) -{ - int result; - const char *argv[6]; - const char **p; - char *s_initrd = NULL; - char *s_args = NULL; - - p = argv; - *p++ = pb_system_apps.kexec; /* 1 */ - *p++ = "-l"; /* 2 */ - - if (l_initrd) { - s_initrd = talloc_asprintf(NULL, "--initrd=%s", l_initrd); - assert(s_initrd); - *p++ = s_initrd; /* 3 */ - } - - if (args) { - s_args = talloc_asprintf(NULL, "--append=%s", args); - assert(s_args); - *p++ = s_args; /* 4 */ - } - - *p++ = l_image; /* 5 */ - *p++ = NULL; /* 6 */ - - result = pb_run_cmd(argv, 1, dry_run); - - if (result) - pb_log("%s: failed: (%d)\n", __func__, result); - - talloc_free(s_initrd); - talloc_free(s_args); - - return result; -} - -/** - * kexec_reboot - Helper to boot the new kernel. - * - * Must only be called after a successful call to kexec_load(). - */ - -static int kexec_reboot(int dry_run) -{ - int result = 0; - const char *argv[4]; - const char **p; - - /* First try running shutdown. Init scripts should run 'exec -e' */ - - p = argv; - *p++ = pb_system_apps.shutdown; /* 1 */ - *p++ = "-r"; /* 2 */ - *p++ = "now"; /* 3 */ - *p++ = NULL; /* 4 */ - - result = pb_run_cmd(argv, 1, dry_run); - - /* On error, force a kexec with the -e option */ - - if (result) { - p = argv; - *p++ = pb_system_apps.kexec; /* 1 */ - *p++ = "-e"; /* 2 */ - *p++ = NULL; /* 3 */ - - result = pb_run_cmd(argv, 1, 0); - } - - if (result) - pb_log("%s: failed: (%d)\n", __func__, result); - - return result; -} - -/** - * pb_boot - Run kexec with the supplied boot options. - */ - -int pb_boot(const struct pb_boot_data *bd, int dry_run) -{ - int result; - char *l_image = NULL; - char *l_initrd = NULL; - unsigned int clean_image = 0; - unsigned int clean_initrd = 0; - - pb_log("%s: image: '%s'\n", __func__, bd->image); - pb_log("%s: initrd: '%s'\n", __func__, bd->initrd); - pb_log("%s: args: '%s'\n", __func__, bd->args); - - result = -1; - - if (bd->image) { - l_image = pb_load_file(NULL, bd->image, &clean_image); - if (!l_image) - goto no_load; - } - - if (bd->initrd) { - l_initrd = pb_load_file(NULL, bd->initrd, &clean_initrd); - if (!l_initrd) - goto no_load; - } - - if (!l_image && !l_initrd) - goto no_load; - - result = kexec_load(l_image, l_initrd, bd->args, dry_run); - -no_load: - if (clean_image) - unlink(l_image); - if (clean_initrd) - unlink(l_initrd); - - talloc_free(l_image); - talloc_free(l_initrd); - - if (!result) - result = kexec_reboot(dry_run); - - return result; -} - /** * pb_elf_hash - Standard elf hash routine. */