]> git.ozlabs.org Git - petitboot/blobdiff - discover/user-event.c
utils/hooks: Set linux,stdout-path for primary console
[petitboot] / discover / user-event.c
index 69defa34e341b22a9441b4b233f39d7b532eaa94..15d9c87bebc2213a1cb265b532999921f0e92925 100644 (file)
@@ -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;
        }
@@ -439,7 +441,25 @@ static int user_event_url(struct user_event *uev, struct event *event)
 
        url = event_get_param(event, "url");
        if (url)
-               device_handler_process_url(handler, url);
+               device_handler_process_url(handler, url, NULL, NULL);
+
+       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;
 }
@@ -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;
        }
@@ -488,10 +511,10 @@ static void user_event_handle_message(struct user_event *uev, char *buf,
 static int user_event_process(void *arg)
 {
        struct user_event *uev = arg;
-       char buf[PBOOT_USER_EVENT_SIZE];
+       char buf[PBOOT_USER_EVENT_SIZE + 1];
        int len;
 
-       len = recvfrom(uev->socket, buf, sizeof(buf), 0, NULL, NULL);
+       len = recvfrom(uev->socket, buf, PBOOT_USER_EVENT_SIZE, 0, NULL, NULL);
 
        if (len < 0) {
                pb_log("%s: socket read failed: %s", __func__, strerror(errno));
@@ -503,6 +526,8 @@ static int user_event_process(void *arg)
                return 0;
        }
 
+       buf[len] = '\0';
+
        pb_debug("%s: %u bytes\n", __func__, len);
 
        user_event_handle_message(uev, buf, len);