#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <libtwin/twin_png.h>
#include "petitboot.h"
+#include "petitboot-paths.h"
#include "devices/message.h"
-#define PBOOT_DEVICE_SOCKET "/var/tmp/petitboot-dev"
-#define PBOOT_DEFAULT_ICON "artwork/usbpen.png"
+#define PBOOT_DEFAULT_ICON "tux.png"
-static const char *default_icon = PBOOT_DEFAULT_ICON;
+static const char *default_icon = artwork_pathname(PBOOT_DEFAULT_ICON);
struct discovery_context {
/* nothing at present */
static int read_option(int fd, struct device_context *dev_ctx)
{
- struct boot_option opt;
+ struct boot_option *opt = malloc(sizeof(*opt));
twin_pixmap_t *icon;
int index = -1;
- if (!read_strings(fd, opt))
+ if (!opt)
return TWIN_FALSE;
- LOG("got option: '%s'\n", opt.name);
- icon = get_icon(opt.icon_file);
+ if (!read_strings(fd, (*opt)))
+ return TWIN_FALSE;
- if (icon)
- index = pboot_add_option(dev_ctx->device_idx, opt.name,
- opt.description, icon);
+ LOG("got option: '%s'\n", opt->name);
+ icon = get_icon(opt->icon_file);
- free_strings(opt);
+ if (icon)
+ index = pboot_add_option(dev_ctx->device_idx, opt->name,
+ opt->description, icon, opt);
return index != -1;
}
return TWIN_TRUE;
}
-int pboot_start_device_discovery(void)
+int pboot_start_device_discovery(int udev_trigger)
{
int sock;
struct sockaddr_un addr;
twin_set_file(pboot_proc_server_sock, sock, TWIN_READ, &_ctx);
+ if (udev_trigger) {
+ int rc = system("udevtrigger");
+ if (rc)
+ LOG("udevtrigger failed, rc %d\n", rc);
+ }
+
return TWIN_TRUE;
}
+void pboot_exec_option(void *data)
+{
+ struct boot_option *opt = data;
+ char *kexec_opts[10];
+ int i, nr_opts = 2;
+
+ kexec_opts[0] = "/usr/sbin/kexec";
+ kexec_opts[1] = "-f";
+ if (opt->initrd_file && *opt->initrd_file) {
+ kexec_opts[nr_opts] = malloc(10 + strlen(opt->initrd_file));
+ sprintf(kexec_opts[nr_opts], "--initrd=%s", opt->initrd_file);
+ nr_opts++;
+ }
+ if (opt->boot_args && *opt->boot_args) {
+ kexec_opts[nr_opts] = malloc(10 + strlen(opt->boot_args));
+ sprintf(kexec_opts[nr_opts], "--command-line=%s",
+ opt->boot_args);
+ nr_opts++;
+ }
+
+ kexec_opts[nr_opts++] = opt->boot_image_file;
+ kexec_opts[nr_opts] = NULL;
+
+ LOG("calling kexec:\n");
+ for (i = 0; i < nr_opts; i++) {
+ LOG("\t'%s'\n", kexec_opts[i]);
+ }
+ fflush(stdout);
+
+ execv(kexec_opts[0], kexec_opts);
+ pboot_message("kexec failed: %s", strerror(errno));
+ LOG("execv() failed: %s", strerror(errno));
+}