]> git.ozlabs.org Git - petitboot/commitdiff
Move boot to discover server
authorJeremy Kerr <jk@ozlabs.org>
Wed, 27 Feb 2013 08:45:21 +0000 (16:45 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 15 Apr 2013 07:42:27 +0000 (15:42 +0800)
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 <jk@ozlabs.org>
14 files changed:
discover/boot.c
discover/paths.c
discover/paths.h
ui/common/Makefile.am
ui/common/loader.c [deleted file]
ui/common/loader.h [deleted file]
ui/common/ui-system.c
ui/common/ui-system.h
ui/ncurses/generic-main.c
ui/ncurses/nc-cui.c
ui/ncurses/nc-cui.h
ui/twin/main-generic.c
ui/twin/pbt-client.c
ui/twin/pbt-client.h

index ddb9e7dc367539343e09cb28d321388c5fecb452..6109562491db79855655a4bf8431e07c20bd1e0f 100644 (file)
 
 
+#include <assert.h>
+
+#include <log/log.h>
+#include <pb-protocol/pb-protocol.h>
+#include <system/system.h>
+#include <talloc/talloc.h>
+
 #include "boot.h"
 #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)
 {
 
 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;
 }
 }
index c4036919bdf7e9ff05f4afa9389c96137d5bc8c3..ef8a45f924c8fa658fd4c39330f40eaf485761b4 100644 (file)
@@ -5,6 +5,9 @@
 #include <stdlib.h>
 
 #include <talloc/talloc.h>
 #include <stdlib.h>
 
 #include <talloc/talloc.h>
+#include <system/system.h>
+#include <url/url.h>
+#include <log/log.h>
 
 #include "paths.h"
 
 
 #include "paths.h"
 
@@ -153,3 +156,277 @@ char *join_paths(void *alloc_ctx, const char *a, const char *b)
        return full_path;
 }
 
        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;
+}
index e7c23e56848b3dc584640723c36ee9f598d39ebb..34de79a1649fd34e7ed4b8f22aa1ef582a7a5cba 100644 (file)
@@ -51,4 +51,7 @@ char *encode_label(void *alloc_ctx, const char *label);
  */
 const char *mount_base(void);
 
  */
 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 */
 #endif /* PATHS_H */
index 9e8d3eabc5397074a7bf5e31bf30f6ebf49b09ce..e629f1c3720b2ce2f24f08781fa037afd0ba04e0 100644 (file)
@@ -28,8 +28,6 @@ libpbui_la_SOURCES = \
        discover-client.h \
        joystick.c \
        joystick.h \
        discover-client.h \
        joystick.c \
        joystick.h \
-       loader.c \
-       loader.h \
        timer.c \
        timer.h \
        ui-system.c \
        timer.c \
        timer.h \
        ui-system.c \
diff --git a/ui/common/loader.c b/ui/common/loader.c
deleted file mode 100644 (file)
index b3ae765..0000000
+++ /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 <assert.h>
-#include <stdlib.h>
-
-#include "log/log.h"
-#include <system/system.h>
-#include <url/url.h>
-#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 (file)
index 42d4d4b..0000000
+++ /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
index 157c6db7797c30ec286ed010094b920e98772b63..ad3bfba8a9d4534507f849925fd3e2b42bc26afd 100644 (file)
@@ -29,7 +29,6 @@
 #include "log/log.h"
 #include <system/system.h>
 #include "talloc/talloc.h"
 #include "log/log.h"
 #include <system/system.h>
 #include "talloc/talloc.h"
-#include "loader.h"
 #include "ui-system.h"
 
 /**
 #include "ui-system.h"
 
 /**
@@ -56,141 +55,6 @@ int pb_start_daemon(void)
        return result;
 }
 
        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.
  */
 /**
  * pb_elf_hash - Standard elf hash routine.
  */
index b4372ee7fcab02ab8be7239b2d0dac017322d723..5ce501af81e1b9dddc5ca92d22c888fb5c75cf69 100644 (file)
@@ -28,7 +28,6 @@
 
 #include <signal.h>
 
 
 #include <signal.h>
 
-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);
 int pb_start_daemon(void);
 
 unsigned int pb_elf_hash(const char *str);
index 8cb876f4ea4229522bc55b87b08a0ac7a251b9f7..ddf0de34e7be5d6efd8b646d755bd5e07445de22 100644 (file)
@@ -131,31 +131,6 @@ struct pb_cui {
        struct cui *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.
  */
 /**
  * pb_mm_init - Setup the main menu instance.
  */
@@ -285,8 +260,7 @@ int main(int argc, char *argv[])
                return EXIT_FAILURE;
        }
 
                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;
 
        if (!pb.cui)
                return EXIT_FAILURE;
index b3fe451dba4eaab99fc5e564c178217d09242d3d..fafa29315a2de6657c46fe84b8671ef454fb699c 100644 (file)
@@ -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);
        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();
 
 
        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);
 
        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();
                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;
 }
 
        return 0;
 }
 
@@ -522,7 +520,6 @@ static struct discover_client_ops cui_client_ops = {
  */
 
 struct cui *cui_init(void* platform_info,
  */
 
 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;
        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->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);
        cui->timer.handle_timeout = cui_handle_timeout;
        cui->dry_run = dry_run;
        cui->waitset = waitset_create(cui);
index 14e4e0661ac42484c5ba759b5dc4ec226c63c6ff..33f266181acc6d47bfb3656c6dff6a9e19189d7a 100644 (file)
@@ -64,7 +64,6 @@ struct cui {
 };
 
 struct cui *cui_init(void* platform_info,
 };
 
 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);
        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);
index 517422e4da9285ded2c1dfb8ec5d1d593bfd149a..cc5140ea67f52cd0f29c383c12b25cd542b11fee 100644 (file)
@@ -199,19 +199,6 @@ fail_menu:
        return NULL;
 }
 
        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) {
 static int run(struct pbt_client *client)
 {
        while (1) {
@@ -330,7 +317,7 @@ int main(int argc, char *argv[])
                return EXIT_FAILURE;
        }
 
                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) {
                opts.start_daemon, opts.dry_run);
 
        if (!client) {
index dfbe9552c32bca48a8c4f33700249896dd755c5e..c664740d04e726025fa56d5319c0d99a7d8cdb22 100644 (file)
@@ -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));
 
        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;
 }
 
        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,
 
 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;
        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->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);
        pbt_client->dry_run = dry_run;
        pbt_client->frame.scr = pbt_scr_init(pbt_client, pbt_client->waitset,
                        backend, width, height, NULL, NULL);
index 7e74e4ec5cf822acecc6e6b0db84c96fb825439d..2c96d489f4d889844ea46a29ed239a4567714bd4 100644 (file)
@@ -45,8 +45,6 @@ struct pbt_client {
        int dry_run;
        struct pb_signal_data signal_data;
        void *client_data;
        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;
        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,
 
 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);
        int start_deamon, int dry_run);
 void pbt_client_destroy(struct pbt_client *client);
 void pbt_client_resize(struct pbt_client *client);