X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fcommon%2Fui-system.c;h=7e04801edf9a96a8e146ad050074e32256779707;hp=b252e9a98edbde407731bc0f29c85ddbadeeda9a;hb=218b5233de442ce67784f9f5e3cd43b2b3f3306b;hpb=93b3fb6196709a0de77059b6b2bb7b8e27530477 diff --git a/ui/common/ui-system.c b/ui/common/ui-system.c index b252e9a..7e04801 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,101 +30,35 @@ #include "log/log.h" #include +#include #include "talloc/talloc.h" -#include "loader.h" #include "ui-system.h" /** - * run_kexec_local - Final kexec 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 run_kexec_local(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 */ - - if (l_initrd) { - s_initrd = talloc_asprintf(NULL, "--initrd=%s", l_initrd); - assert(s_initrd); - *p++ = s_initrd; /* 2 */ - } - - if (args) { - s_args = talloc_asprintf(NULL, "--append=%s", args); - assert(s_args); - *p++ = s_args; /* 3 */ - } - - /* First try by telling kexec to run shutdown */ - - *(p + 0) = l_image; - *(p + 1) = NULL; - - result = pb_run_cmd(argv); - - /* kexec will return zero on success */ - /* On error, force a kexec with the -f option */ - - if (result) { - *(p + 0) = "-f"; /* 4 */ - *(p + 1) = l_image; /* 5 */ - *(p + 2) = NULL; /* 6 */ - - result = pb_run_cmd(argv); - } - - if (result) - pb_log("%s: failed: (%d)\n", __func__, result); + char *name; - talloc_free(s_initrd); - talloc_free(s_args); + process = process_create(ctx); - return result; -} - -/** - * pb_run_kexec - Run kexec with the supplied boot options. - * - * For the convenience of the user, tries to load both files before - * returning error. - */ - -int pb_run_kexec(const struct pb_kexec_data *kd) -{ - int result; - char *l_image; - char *l_initrd; - - 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); - - if (kd->image) - l_image = pb_load_file(NULL, kd->image); - else { - l_image = NULL; - pb_log("%s: error null image\n", __func__); - } + argv = talloc_array(process, const char *, 2); + name = talloc_asprintf(process, "%s/sbin/pb-discover", + pb_system_apps.prefix); - l_initrd = kd->initrd ? pb_load_file(NULL, kd->initrd) : NULL; + argv[0] = name; + argv[1] = NULL; - if (!l_image || (kd->initrd && !l_initrd)) - result = -1; - else - result = run_kexec_local(l_image, l_initrd, kd->args); + process->path = name; + process->argv = argv; - talloc_free(l_image); - talloc_free(l_initrd); + result = process_run_async(process); + process_release(process); return result; }