X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fcommon%2Fui-system.c;h=02142dbf303a1e993dcc39897d2773f73297cb5c;hp=0140f0e484eedfc2757795ebc2fe9abd4520ad95;hb=c4be9490a5d94b662370576157b6e0ed73f2fe77;hpb=c763f15030565eef2e8b28fdf471ef3e7dd9b933 diff --git a/ui/common/ui-system.c b/ui/common/ui-system.c index 0140f0e..02142db 100644 --- a/ui/common/ui-system.c +++ b/ui/common/ui-system.c @@ -16,7 +16,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define _GNU_SOURCE +#if defined(HAVE_CONFIG_H) +#include "config.h" +#endif #include #include @@ -28,141 +30,35 @@ #include "log/log.h" #include +#include #include "talloc/talloc.h" -#include "loader.h" #include "ui-system.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. + * pb_start_daemon - start the pb-discover daemon. */ -static int kexec_load(const char *l_image, const char *l_initrd, - const char *args) +int pb_start_daemon(void *ctx) { + struct process *process; + const char **argv; 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); - - 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(void) -{ - int result; - 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); - - /* 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); - } - - if (result) - pb_log("%s: failed: (%d)\n", __func__, result); - - return result; -} - -/** - * pb_run_kexec - Run kexec with the supplied boot options. - */ - -int pb_run_kexec(const struct pb_kexec_data *kd) -{ - 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__, kd->image); - pb_log("%s: initrd: '%s'\n", __func__, kd->initrd); - pb_log("%s: args: '%s'\n", __func__, kd->args); - - result = -1; - - if (kd->image) { - l_image = pb_load_file(NULL, kd->image, &clean_image); - if (!l_image) - goto no_load; - } - - if (kd->initrd) { - l_initrd = pb_load_file(NULL, kd->initrd, &clean_initrd); - if (!l_initrd) - goto no_load; - } + char *name; - if (!l_image && !l_initrd) - goto no_load; + process = process_create(ctx); - result = kexec_load(l_image, l_initrd, kd->args); + argv = talloc_array(process, const char *, 2); + name = talloc_asprintf(process, "%s/sbin/pb-discover", + pb_system_apps.prefix); -no_load: - if (clean_image) - unlink(l_image); - if (clean_initrd) - unlink(l_initrd); + argv[0] = name; + argv[1] = NULL; - talloc_free(l_image); - talloc_free(l_initrd); + process->path = name; + process->argv = argv; - if (!result) - result = kexec_reboot(); + result = process_run_async(process); + process_release(process); return result; } @@ -182,7 +78,7 @@ unsigned int pb_elf_hash(const char *str) h ^= g >> 24; h &= ~g; } - pb_log("%s: %x\n", __func__, h); + pb_log_fn("%x\n", h); return h; }