[PATCH] pb-event: Add 'boot' user event

Samuel Mendoza-Jonas sam at mendozajonas.com
Tue May 3 09:51:44 AEST 2016


Add a user event to send a boot command to the discover server.
The format of the boot command is similar to the add command, eg:

pb-event boot at eth0 image="http://host/image" initrd="http://host/initrd"

and also recognises "id", "dtb", and "args" arguments.

Signed-off-by: Samuel Mendoza-Jonas <sam at mendozajonas.com>
---
 discover/event.c      |  2 ++
 discover/event.h      |  1 +
 discover/user-event.c | 23 +++++++++++++++++++++++
 utils/pb-event.c      |  2 +-
 4 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/discover/event.c b/discover/event.c
index 7932378..8b3a1ab 100644
--- a/discover/event.c
+++ b/discover/event.c
@@ -53,6 +53,8 @@ static int event_parse_ad_header(char *buf, int len, enum event_action *action,
 		*action = EVENT_ACTION_CONF;
 	else if (streq(buf, "dhcp"))
 		*action = EVENT_ACTION_DHCP;
+	else if (streq(buf, "boot"))
+		*action = EVENT_ACTION_BOOT;
 	else {
 		pb_log("%s: unknown action: %s\n", __func__, buf);
 		return -1;
diff --git a/discover/event.h b/discover/event.h
index 8dee13b..35c0767 100644
--- a/discover/event.h
+++ b/discover/event.h
@@ -13,6 +13,7 @@ enum event_action {
 	EVENT_ACTION_URL,
 	EVENT_ACTION_CONF,
 	EVENT_ACTION_DHCP,
+	EVENT_ACTION_BOOT,
 	EVENT_ACTION_MAX,
 };
 
diff --git a/discover/user-event.c b/discover/user-event.c
index 8926458..15d9c87 100644
--- a/discover/user-event.c
+++ b/discover/user-event.c
@@ -58,6 +58,8 @@ static const char *event_action_name(enum event_action action)
 		return "url";
 	case EVENT_ACTION_DHCP:
 		return "dhcp";
+	case EVENT_ACTION_BOOT:
+		return "boot";
 	default:
 		break;
 	}
@@ -444,6 +446,24 @@ static int user_event_url(struct user_event *uev, struct event *event)
 	return 0;
 }
 
+static int user_event_boot(struct user_event *uev, struct event *event)
+{
+	struct device_handler *handler = uev->handler;
+	struct boot_command *cmd = talloc(handler, struct boot_command);
+
+	cmd->option_id = talloc_strdup(cmd, event_get_param(event, "id"));
+	cmd->boot_image_file = talloc_strdup(cmd, event_get_param(event, "image"));
+	cmd->initrd_file = talloc_strdup(cmd, event_get_param(event, "initrd"));
+	cmd->dtb_file = talloc_strdup(cmd, event_get_param(event, "dtb"));
+	cmd->boot_args = talloc_strdup(cmd, event_get_param(event, "args"));
+
+	device_handler_boot(handler, cmd);
+
+	talloc_free(cmd);
+
+	return 0;
+}
+
 static void user_event_handle_message(struct user_event *uev, char *buf,
 	int len)
 {
@@ -476,6 +496,9 @@ static void user_event_handle_message(struct user_event *uev, char *buf,
 	case EVENT_ACTION_DHCP:
 		result = user_event_dhcp(uev, event);
 		break;
+	case EVENT_ACTION_BOOT:
+		result = user_event_boot(uev, event);
+		break;
 	default:
 		break;
 	}
diff --git a/utils/pb-event.c b/utils/pb-event.c
index a1affe5..572eb16 100644
--- a/utils/pb-event.c
+++ b/utils/pb-event.c
@@ -55,7 +55,7 @@ static void print_usage(void)
 "       Events can be read from stdin, or provided on the command line.\n"
 "       User events must have the following format:\n"
 "\n"
-"         (add|remove)@device-id [name=value] [image=value] [args=value]\n"
+"         (add|remove|boot)@device-id [name=value] [image=value] [args=value]\n"
 "\n"
 "       When read from stdin, components are separated by NUL chars\n"
 "\n"
-- 
2.8.2



More information about the Petitboot mailing list