From c62667e5c78ea212e5ac49244e9792954a1d8f71 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Wed, 27 Feb 2013 16:45:21 +0800 Subject: [PATCH 1/1] Move boot to discover server This change moves the boot-via-kexec functionality from the UIs to the discover server. On the UI side: rather than run kexec directly, we just send a message to the discover server. Because this is generic discover client functionality, we no longer need the boot callbacks in the twin- and ncurses-specific code. We also remove the kexec and URL-loading code from the UIs, and add it to the discover server code, in paths.c. We expose this to the server though a new function: load_path(void *, const char *, unsigned int *); On the server side, we simply move hook up the boot() function to use the load_file and kexec calls. Signed-off-by: Jeremy Kerr --- discover/boot.c | 157 ++++++++++++++++++- discover/paths.c | 277 +++++++++++++++++++++++++++++++++ discover/paths.h | 3 + ui/common/Makefile.am | 2 - ui/common/loader.c | 318 -------------------------------------- ui/common/loader.h | 24 --- ui/common/ui-system.c | 136 ---------------- ui/common/ui-system.h | 1 - ui/ncurses/generic-main.c | 28 +--- ui/ncurses/nc-cui.c | 12 +- ui/ncurses/nc-cui.h | 1 - ui/twin/main-generic.c | 15 +- ui/twin/pbt-client.c | 17 +- ui/twin/pbt-client.h | 3 - 14 files changed, 443 insertions(+), 551 deletions(-) delete mode 100644 ui/common/loader.c delete mode 100644 ui/common/loader.h diff --git a/discover/boot.c b/discover/boot.c index ddb9e7d..6109562 100644 --- a/discover/boot.c +++ b/discover/boot.c @@ -1,14 +1,159 @@ +#include + +#include +#include +#include +#include + #include "boot.h" +#include "paths.h" + +/** + * 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; +} int boot(void *ctx, struct boot_option *opt, struct boot_command *cmd, int dry_run) { - /* todo: run kexec with options from opt & cmd */ - (void)ctx; - (void)opt; - (void)cmd; - (void)dry_run; + char *local_image, *local_initrd; + unsigned int clean_image = 0; + unsigned int clean_initrd = 0; + char *image, *initrd, *args; + int result; + + image = NULL; + initrd = NULL; + args = NULL; + + if (cmd->boot_image_file) { + image = talloc_strdup(ctx, cmd->boot_image_file); + } else if (opt && opt->boot_image_file) { + image = talloc_strdup(ctx, opt->boot_image_file); + } else { + pb_log("%s: no image specified", __func__); + return -1; + } + + if (cmd->initrd_file) { + image = talloc_strdup(ctx, cmd->initrd_file); + } else if (opt && opt->initrd_file) { + image = talloc_strdup(ctx, opt->initrd_file); + } + + if (cmd->boot_args) { + args = talloc_strdup(ctx, cmd->boot_args); + } else if (opt && opt->boot_args) { + args = talloc_strdup(ctx, opt->boot_args); + } + + result = -1; + + local_image = load_file(NULL, image, &clean_image); + if (!local_image) + goto no_load; + + local_initrd = NULL; + if (initrd) { + local_initrd = load_file(NULL, initrd, &clean_initrd); + if (!local_initrd) + goto no_load; + } + + result = kexec_load(local_image, local_initrd, args, dry_run); + +no_load: + if (clean_image) + unlink(local_image); + if (clean_initrd) + unlink(local_initrd); + + talloc_free(local_image); + talloc_free(local_initrd); + + if (!result) + result = kexec_reboot(dry_run); - return 0; + return result; } diff --git a/discover/paths.c b/discover/paths.c index c403691..ef8a45f 100644 --- a/discover/paths.c +++ b/discover/paths.c @@ -5,6 +5,9 @@ #include #include +#include +#include +#include #include "paths.h" @@ -153,3 +156,277 @@ char *join_paths(void *alloc_ctx, const char *a, const char *b) return full_path; } + +static char *local_name(void *ctx) +{ + char *tmp, *ret; + + tmp = tempnam(NULL, "pb-"); + + if (!tmp) + return NULL; + + ret = talloc_strdup(ctx, tmp); + free(tmp); + + return ret; +} + +/** + * pb_load_nfs - Mounts the NFS export and returns the local file path. + * + * Returns the local file path in a talloc'ed character string on success, + * or NULL on error. + */ +static char *load_nfs(void *ctx, struct pb_url *url) +{ + int result; + const char *argv[8]; + const char **p; + char *local; + char *opts; + + local = local_name(ctx); + + if (!local) + return NULL; + + result = pb_mkdir_recursive(local); + + if (result) + goto fail; + + opts = talloc_strdup(NULL, "ro,nolock,nodiratime"); + + if (url->port) + opts = talloc_asprintf_append(opts, ",port=%s", url->port); + + p = argv; + *p++ = pb_system_apps.mount; /* 1 */ + *p++ = "-t"; /* 2 */ + *p++ = "nfs"; /* 3 */ + *p++ = opts; /* 4 */ + *p++ = url->host; /* 5 */ + *p++ = url->dir; /* 6 */ + *p++ = local; /* 7 */ + *p++ = NULL; /* 8 */ + + result = pb_run_cmd(argv, 1, 0); + + talloc_free(opts); + + if (result) + goto fail; + + local = talloc_asprintf_append(local, "/%s", url->path); + pb_log("%s: local '%s'\n", __func__, local); + + return local; + +fail: + pb_rmdir_recursive("/", local); + talloc_free(local); + return NULL; +} + +/** + * pb_load_sftp - Loads a remote file via sftp and returns the local file path. + * + * Returns the local file path in a talloc'ed character string on success, + * or NULL on error. + */ +static char *load_sftp(void *ctx, struct pb_url *url) +{ + int result; + const char *argv[4]; + const char **p; + char *local; + + local = local_name(ctx); + + if (!local) + return NULL; + + p = argv; + *p++ = pb_system_apps.sftp; /* 1 */ + *p++ = talloc_asprintf(local, "%s:%s", url->host, url->path); /* 2 */ + *p++ = local; /* 3 */ + *p++ = NULL; /* 4 */ + + result = pb_run_cmd(argv, 1, 0); + + if (result) + goto fail; + + return local; + +fail: + talloc_free(local); + return NULL; +} + +/** + * pb_load_tftp - Loads a remote file via tftp and returns the local file path. + * + * Returns the local file path in a talloc'ed character string on success, + * or NULL on error. + */ + +static char *load_tftp(void *ctx, struct pb_url *url) +{ + int result; + const char *argv[10]; + const char **p; + char *local; + + local = local_name(ctx); + + if (!local) + return NULL; + + /* first try busybox tftp args */ + + p = argv; + *p++ = pb_system_apps.tftp; /* 1 */ + *p++ = "-g"; /* 2 */ + *p++ = "-l"; /* 3 */ + *p++ = local; /* 4 */ + *p++ = "-r"; /* 5 */ + *p++ = url->path; /* 6 */ + *p++ = url->host; /* 7 */ + if (url->port) + *p++ = url->port; /* 8 */ + *p++ = NULL; /* 9 */ + + result = pb_run_cmd(argv, 1, 0); + + if (!result) + return local; + + /* next try tftp-hpa args */ + + p = argv; + *p++ = pb_system_apps.tftp; /* 1 */ + *p++ = "-m"; /* 2 */ + *p++ = "binary"; /* 3 */ + *p++ = url->host; /* 4 */ + if (url->port) + *p++ = url->port; /* 5 */ + *p++ = "-c"; /* 6 */ + *p++ = "get"; /* 7 */ + *p++ = url->path; /* 8 */ + *p++ = local; /* 9 */ + *p++ = NULL; /* 10 */ + + result = pb_run_cmd(argv, 1, 0); + + if (!result) + return local; + + talloc_free(local); + return NULL; +} + +enum wget_flags { + wget_empty = 0, + wget_no_check_certificate = 1, +}; + +/** + * pb_load_wget - Loads a remote file via wget and returns the local file path. + * + * Returns the local file path in a talloc'ed character string on success, + * or NULL on error. + */ + +static char *load_wget(void *ctx, struct pb_url *url, enum wget_flags flags) +{ + int result; + const char *argv[7]; + const char **p; + char *local; + + local = local_name(ctx); + + if (!local) + return NULL; + + p = argv; + *p++ = pb_system_apps.wget; /* 1 */ +#if !defined(DEBUG) + *p++ = "--quiet"; /* 2 */ +#endif + *p++ = "-O"; /* 3 */ + *p++ = local; /* 4 */ + *p++ = url->full; /* 5 */ + if (flags & wget_no_check_certificate) + *p++ = "--no-check-certificate"; /* 6 */ + *p++ = NULL; /* 7 */ + + result = pb_run_cmd(argv, 1, 0); + + if (result) + goto fail; + + return local; + +fail: + talloc_free(local); + return NULL; +} + +/** + * pb_load_file - Loads a (possibly) remote file and returns the local file + * path. + * @ctx: The talloc context to associate with the returned string. + * @remote: The remote file URL. + * @tempfile: An optional variable pointer to be set when a temporary local + * file is created. + * + * Returns the local file path in a talloc'ed character string on success, + * or NULL on error. + */ + +char *load_file(void *ctx, const char *remote, unsigned int *tempfile) +{ + struct pb_url *url = pb_url_parse(ctx, remote); + char *local; + int tmp = 0; + + if (!url) + return NULL; + + switch (url->scheme) { + case pb_url_ftp: + case pb_url_http: + local = load_wget(ctx, url, 0); + tmp = !!local; + break; + case pb_url_https: + local = load_wget(ctx, url, wget_no_check_certificate); + tmp = !!local; + break; + case pb_url_nfs: + local = load_nfs(ctx, url); + tmp = !!local; + break; + case pb_url_sftp: + local = load_sftp(ctx, url); + tmp = !!local; + break; + case pb_url_tftp: + local = load_tftp(ctx, url); + tmp = !!local; + break; + default: + local = talloc_strdup(ctx, url->full); + tmp = 0; + break; + } + + if (tempfile) + *tempfile = tmp; + + talloc_free(url); + return local; +} diff --git a/discover/paths.h b/discover/paths.h index e7c23e5..34de79a 100644 --- a/discover/paths.h +++ b/discover/paths.h @@ -51,4 +51,7 @@ char *encode_label(void *alloc_ctx, const char *label); */ const char *mount_base(void); +/* Load a (potentially remote) file, and return a guaranteed-local name */ +char *load_file(void *ctx, const char *remote, unsigned int *tempfile); + #endif /* PATHS_H */ diff --git a/ui/common/Makefile.am b/ui/common/Makefile.am index 9e8d3ea..e629f1c 100644 --- a/ui/common/Makefile.am +++ b/ui/common/Makefile.am @@ -28,8 +28,6 @@ libpbui_la_SOURCES = \ discover-client.h \ joystick.c \ joystick.h \ - loader.c \ - loader.h \ timer.c \ timer.h \ ui-system.c \ diff --git a/ui/common/loader.c b/ui/common/loader.c deleted file mode 100644 index b3ae765..0000000 --- a/ui/common/loader.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright (C) 2009 Sony Computer Entertainment Inc. - * Copyright 2009 Sony Corp. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#if defined(HAVE_CONFIG_H) -#include "config.h" -#endif - -#define _GNU_SOURCE -#include -#include - -#include "log/log.h" -#include -#include -#include "talloc/talloc.h" -#include "loader.h" - - -/** - * pb_local_name - Helper to create a unique local path name. - * @ctx: A talloc context. - * - * Returns the local file path in a talloc'ed character string on success, - * or NULL on error. - */ - -static char *pb_local_name(void *ctx) -{ - char *tmp, *ret; - - tmp = tempnam(NULL, "pb-"); - - if (!tmp) - return NULL; - - ret = talloc_strdup(ctx, tmp); - free(tmp); - - return ret; -} - -/** - * pb_load_nfs - Mounts the NFS export and returns the local file path. - * - * Returns the local file path in a talloc'ed character string on success, - * or NULL on error. - */ - -static char *pb_load_nfs(void *ctx, struct pb_url *url) -{ - int result; - const char *argv[8]; - const char **p; - char *local; - char *opts; - - local = pb_local_name(ctx); - - if (!local) - return NULL; - - result = pb_mkdir_recursive(local); - - if (result) - goto fail; - - opts = talloc_strdup(NULL, "ro,nolock,nodiratime"); - - if (url->port) - opts = talloc_asprintf_append(opts, ",port=%s", url->port); - - p = argv; - *p++ = pb_system_apps.mount; /* 1 */ - *p++ = "-t"; /* 2 */ - *p++ = "nfs"; /* 3 */ - *p++ = opts; /* 4 */ - *p++ = url->host; /* 5 */ - *p++ = url->dir; /* 6 */ - *p++ = local; /* 7 */ - *p++ = NULL; /* 8 */ - - result = pb_run_cmd(argv, 1, 0); - - talloc_free(opts); - - if (result) - goto fail; - - local = talloc_asprintf_append(local, "/%s", url->path); - pb_log("%s: local '%s'\n", __func__, local); - - return local; - -fail: - pb_rmdir_recursive("/", local); - talloc_free(local); - return NULL; -} - -/** - * pb_load_sftp - Loads a remote file via sftp and returns the local file path. - * - * Returns the local file path in a talloc'ed character string on success, - * or NULL on error. - */ - -static char *pb_load_sftp(void *ctx, struct pb_url __attribute__((unused)) *url) -{ - int result; - const char *argv[4]; - const char **p; - char *local; - - local = pb_local_name(ctx); - - if (!local) - return NULL; - - p = argv; - *p++ = pb_system_apps.sftp; /* 1 */ - *p++ = talloc_asprintf(local, "%s:%s", url->host, url->path); /* 2 */ - *p++ = local; /* 3 */ - *p++ = NULL; /* 4 */ - - result = pb_run_cmd(argv, 1, 0); - - if (result) - goto fail; - - return local; - -fail: - talloc_free(local); - return NULL; -} - -/** - * pb_load_tftp - Loads a remote file via tftp and returns the local file path. - * - * Returns the local file path in a talloc'ed character string on success, - * or NULL on error. - */ - -static char *pb_load_tftp(void *ctx, struct pb_url *url) -{ - int result; - const char *argv[10]; - const char **p; - char *local; - - local = pb_local_name(ctx); - - if (!local) - return NULL; - - /* first try busybox tftp args */ - - p = argv; - *p++ = pb_system_apps.tftp; /* 1 */ - *p++ = "-g"; /* 2 */ - *p++ = "-l"; /* 3 */ - *p++ = local; /* 4 */ - *p++ = "-r"; /* 5 */ - *p++ = url->path; /* 6 */ - *p++ = url->host; /* 7 */ - if (url->port) - *p++ = url->port; /* 8 */ - *p++ = NULL; /* 9 */ - - result = pb_run_cmd(argv, 1, 0); - - if (!result) - return local; - - /* next try tftp-hpa args */ - - p = argv; - *p++ = pb_system_apps.tftp; /* 1 */ - *p++ = "-m"; /* 2 */ - *p++ = "binary"; /* 3 */ - *p++ = url->host; /* 4 */ - if (url->port) - *p++ = url->port; /* 5 */ - *p++ = "-c"; /* 6 */ - *p++ = "get"; /* 7 */ - *p++ = url->path; /* 8 */ - *p++ = local; /* 9 */ - *p++ = NULL; /* 10 */ - - result = pb_run_cmd(argv, 1, 0); - - if (!result) - return local; - - talloc_free(local); - return NULL; -} - -enum wget_flags { - wget_empty = 0, - wget_no_check_certificate = 1, -}; - -/** - * pb_load_wget - Loads a remote file via wget and returns the local file path. - * - * Returns the local file path in a talloc'ed character string on success, - * or NULL on error. - */ - -static char *pb_load_wget(void *ctx, struct pb_url *url, enum wget_flags flags) -{ - int result; - const char *argv[7]; - const char **p; - char *local; - - local = pb_local_name(ctx); - - if (!local) - return NULL; - - p = argv; - *p++ = pb_system_apps.wget; /* 1 */ -#if !defined(DEBUG) - *p++ = "--quiet"; /* 2 */ -#endif - *p++ = "-O"; /* 3 */ - *p++ = local; /* 4 */ - *p++ = url->full; /* 5 */ - if (flags & wget_no_check_certificate) - *p++ = "--no-check-certificate"; /* 6 */ - *p++ = NULL; /* 7 */ - - result = pb_run_cmd(argv, 1, 0); - - if (result) - goto fail; - - return local; - -fail: - talloc_free(local); - return NULL; -} - -/** - * pb_load_file - Loads a remote file and returns the local file path. - * @ctx: The talloc context to associate with the returned string. - * @remote: The remote file URL. - * @tempfile: An optional variable pointer to be set when a temporary local - * file is created. - * - * Returns the local file path in a talloc'ed character string on success, - * or NULL on error. - */ - -char *pb_load_file(void *ctx, const char *remote, unsigned int *tempfile) -{ - char *local; - struct pb_url *url = pb_url_parse(NULL, remote); - - if (tempfile) - *tempfile = 0; - - if (!url) - return NULL; - - switch (url->scheme) { - case pb_url_ftp: - case pb_url_http: - local = pb_load_wget(ctx, url, 0); - if (tempfile && local) - *tempfile = 1; - break; - case pb_url_https: - local = pb_load_wget(ctx, url, wget_no_check_certificate); - if (tempfile && local) - *tempfile = 1; - break; - case pb_url_nfs: - local = pb_load_nfs(ctx, url); - if (tempfile && local) - *tempfile = 1; - break; - case pb_url_sftp: - local = pb_load_sftp(ctx, url); - if (tempfile && local) - *tempfile = 1; - break; - case pb_url_tftp: - local = pb_load_tftp(ctx, url); - if (tempfile && local) - *tempfile = 1; - break; - default: - local = talloc_strdup(ctx, url->full); - break; - } - - talloc_free(url); - return local; -} diff --git a/ui/common/loader.h b/ui/common/loader.h deleted file mode 100644 index 42d4d4b..0000000 --- a/ui/common/loader.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2009 Sony Computer Entertainment Inc. - * Copyright 2009 Sony Corp. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#if !defined(_PB_FILE_LOADER_H) -#define _PB_FILE_LOADER_H - -char *pb_load_file(void *ctx, const char *remote, unsigned int *tempfile); - -#endif 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. */ diff --git a/ui/common/ui-system.h b/ui/common/ui-system.h index b4372ee..5ce501a 100644 --- a/ui/common/ui-system.h +++ b/ui/common/ui-system.h @@ -28,7 +28,6 @@ #include -int pb_boot(const struct pb_boot_data *bd, int dry_run); int pb_start_daemon(void); unsigned int pb_elf_hash(const char *str); diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c index 8cb876f..ddf0de3 100644 --- a/ui/ncurses/generic-main.c +++ b/ui/ncurses/generic-main.c @@ -131,31 +131,6 @@ struct pb_cui { struct cui *cui; }; -static struct pb_cui *pb_from_cui(struct cui *cui) -{ - struct pb_cui *pb; - - assert(cui->c_sig == pb_cui_sig); - pb = cui->platform_info; - assert(pb->cui->c_sig == pb_cui_sig); - return pb; -} - -/** - * pb_boot_cb - The kexec callback. - */ - -static int pb_boot_cb(struct cui *cui, struct cui_opt_data *cod) -{ - struct pb_cui *pb = pb_from_cui(cui); - - pb_log("%s: %s\n", __func__, cod->name); - - assert(pb->cui->current == &pb->cui->main->scr); - - return pb_boot(cod->bd, pb->cui->dry_run); -} - /** * pb_mm_init - Setup the main menu instance. */ @@ -285,8 +260,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - pb.cui = cui_init(&pb, pb_boot_cb, NULL, opts.start_daemon, - opts.dry_run); + pb.cui = cui_init(&pb, NULL, opts.start_daemon, opts.dry_run); if (!pb.cui) return EXIT_FAILURE; diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index b3fe451..fafa293 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -135,14 +135,13 @@ static int cui_boot(struct pmenu_item *item) struct cui_opt_data *cod = cod_from_item(item); assert(cui->current == &cui->main->scr); - assert(cui->on_boot); pb_log("%s: %s\n", __func__, cod->name); nc_scr_status_printf(cui->current, "Booting %s...", cod->name); def_prog_mode(); - result = cui->on_boot(cui, cod); + result = discover_client_boot(cui->client, cod->dev, cod->opt, cod->bd); reset_prog_mode(); redrawwin(cui->current->main_ncw); @@ -151,12 +150,11 @@ static int cui_boot(struct pmenu_item *item) clear(); mvaddstr(1, 0, "system is going down now..."); refresh(); - sleep(cui->dry_run ? 1 : 60); + } else { + nc_scr_status_printf(cui->current, + "Failed: boot %s", cod->bd->image); } - pb_log("%s: failed: %s\n", __func__, cod->bd->image); - nc_scr_status_printf(cui->current, "Failed: kexec %s", cod->bd->image); - return 0; } @@ -522,7 +520,6 @@ static struct discover_client_ops cui_client_ops = { */ struct cui *cui_init(void* platform_info, - int (*on_boot)(struct cui *, struct cui_opt_data *), int (*js_map)(const struct js_event *e), int start_deamon, int dry_run) { struct cui *cui; @@ -538,7 +535,6 @@ struct cui *cui_init(void* platform_info, cui->c_sig = pb_cui_sig; cui->platform_info = platform_info; - cui->on_boot = on_boot; cui->timer.handle_timeout = cui_handle_timeout; cui->dry_run = dry_run; cui->waitset = waitset_create(cui); diff --git a/ui/ncurses/nc-cui.h b/ui/ncurses/nc-cui.h index 14e4e06..33f2661 100644 --- a/ui/ncurses/nc-cui.h +++ b/ui/ncurses/nc-cui.h @@ -64,7 +64,6 @@ struct cui { }; struct cui *cui_init(void* platform_info, - int (*on_boot)(struct cui *, struct cui_opt_data *), int (*js_map)(const struct js_event *e), int start_deamon, int dry_run); struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr); int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item); diff --git a/ui/twin/main-generic.c b/ui/twin/main-generic.c index 517422e..cc5140e 100644 --- a/ui/twin/main-generic.c +++ b/ui/twin/main-generic.c @@ -199,19 +199,6 @@ fail_menu: return NULL; } -static int boot_cb(struct pbt_client *client, struct pb_opt_data *opt_data) -{ - int result; - - assert(opt_data); - - pb_log("%s: %s\n", __func__, opt_data->name); - - result = pb_boot(opt_data->bd, client->dry_run); - - return result; -} - static int run(struct pbt_client *client) { while (1) { @@ -330,7 +317,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - client = pbt_client_init(opts.backend, 1024, 640, boot_cb, + client = pbt_client_init(opts.backend, 1024, 640, opts.start_daemon, opts.dry_run); if (!client) { diff --git a/ui/twin/pbt-client.c b/ui/twin/pbt-client.c index dfbe955..c664740 100644 --- a/ui/twin/pbt-client.c +++ b/ui/twin/pbt-client.c @@ -62,18 +62,15 @@ static int pbt_client_boot(struct pbt_item *item) pbt_frame_status_printf(&item->pbt_client->frame, "Booting %s...", pbt_item_name(item)); - assert(item->pbt_client->boot_cb); - result = item->pbt_client->boot_cb(item->pbt_client, opt_data); + result = discover_client_boot(item->pbt_client->discover_client, + opt_data->dev, opt_data->opt, opt_data->bd); - if (!result) { - sleep(item->pbt_client->dry_run ? 1 : 60); + if (result) { + pb_log("%s: failed: %s\n", __func__, opt_data->bd->image); + pbt_frame_status_printf(&item->pbt_client->frame, + "Failed: kexec %s", opt_data->bd->image); } - pb_log("%s: failed: %s\n", __func__, opt_data->bd->image); - - pbt_frame_status_printf(&item->pbt_client->frame, "Failed: kexec %s", - opt_data->bd->image); - return 0; } @@ -265,7 +262,6 @@ static void pbt_client_destructor(struct pbt_client *client) struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, unsigned int width, unsigned int height, - int (*boot_cb)(struct pbt_client *, struct pb_opt_data *), int start_deamon, int dry_run) { struct pbt_client *pbt_client; @@ -284,7 +280,6 @@ struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, pbt_client->waitset = waitset_create(pbt_client); pbt_client->sig = "pbt_client"; - pbt_client->boot_cb = boot_cb; pbt_client->dry_run = dry_run; pbt_client->frame.scr = pbt_scr_init(pbt_client, pbt_client->waitset, backend, width, height, NULL, NULL); diff --git a/ui/twin/pbt-client.h b/ui/twin/pbt-client.h index 7e74e4e..2c96d48 100644 --- a/ui/twin/pbt-client.h +++ b/ui/twin/pbt-client.h @@ -45,8 +45,6 @@ struct pbt_client { int dry_run; struct pb_signal_data signal_data; void *client_data; - int (*boot_cb)(struct pbt_client *pbt_client, struct pb_opt_data *pod); - struct pbt_frame frame; struct discover_client *discover_client; struct waitset *waitset; @@ -54,7 +52,6 @@ struct pbt_client { struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, unsigned int width, unsigned int height, - int (*boot_cb)(struct pbt_client *, struct pb_opt_data *), int start_deamon, int dry_run); void pbt_client_destroy(struct pbt_client *client); void pbt_client_resize(struct pbt_client *client); -- 2.39.2