From c62667e5c78ea212e5ac49244e9792954a1d8f71 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Wed, 27 Feb 2013 16:45:21 +0800 Subject: 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 --- 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 - 5 files changed, 481 deletions(-) delete mode 100644 ui/common/loader.c delete mode 100644 ui/common/loader.h (limited to 'ui/common') 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); -- cgit v1.2.1