]> git.ozlabs.org Git - petitboot/blobdiff - ui/common/discover-client.c
discover-client: Add discover_client_boot
[petitboot] / ui / common / discover-client.c
index b1ef440a9127e927f3e6456fb25688248f05ecc7..9374dc538506fd788a4c246a547f6d0b0629d38f 100644 (file)
@@ -12,7 +12,7 @@
 #include <talloc/talloc.h>
 #include <log/log.h>
 
-#include "ui/common/discover-client.h"
+#include "discover-client.h"
 #include "pb-protocol/pb-protocol.h"
 
 struct discover_client {
@@ -46,7 +46,7 @@ struct discover_client* discover_client_init(
        client->ops.cb_arg = cb_arg;
 
        client->fd = socket(AF_UNIX, SOCK_STREAM, 0);
-       if (!client->fd < 0) {
+       if (client->fd < 0) {
                pb_log("%s: socket: %s\n", __func__, strerror(errno));
                goto out_err;
        }
@@ -111,7 +111,7 @@ static void device_remove(struct discover_client *client, const char *id)
        /* remove the device from the client's device array */
        client->n_devices--;
        memmove(&client->devices[i], &client->devices[i+1],
-                       client->n_devices - i);
+                       (client->n_devices - i) * sizeof(client->devices[0]));
        client->devices = talloc_realloc(client, client->devices,
                        struct device *, client->n_devices);
 
@@ -172,3 +172,42 @@ struct device *discover_client_get_device(struct discover_client *client,
 
        return client->devices[index];
 }
+
+static void create_boot_command(struct boot_command *command,
+               const struct device *device __attribute__((unused)),
+               const struct boot_option *boot_option,
+               const struct pb_boot_data *data)
+{
+
+       command->option_id = boot_option->id;
+       command->boot_image_file = data->image;
+       command->initrd_file = data->initrd;
+       command->boot_args = data->args;
+}
+
+int discover_client_boot(struct discover_client *client,
+               const struct device *device,
+               const struct boot_option *boot_option,
+               const struct pb_boot_data *data)
+{
+       struct pb_protocol_message *message;
+       struct boot_command boot_command;
+       int len, rc;
+
+       create_boot_command(&boot_command, device, boot_option, data);
+
+       len = pb_protocol_boot_len(&boot_command);
+
+       message = pb_protocol_create_message(client,
+                       PB_PROTOCOL_ACTION_BOOT, len);
+
+       if (!message)
+               return -1;
+
+       pb_protocol_serialise_boot_command(&boot_command,
+                       message->payload, len);
+
+       rc = pb_protocol_write_message(client->fd, message);
+
+       return rc;
+}