Curently, the protocol deserialise functions are allocating device and
boot_command structures. This (implicitly) makes them responsible for
initialisation of these structures too.
Rather that making the protocol responsible for initialising the devices
and boot commands, this change gives the deserialise functions an
argument to an already-instanciated structure. This means that the
creation is no longer implied by the deserialise.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
struct pb_protocol_message *message;
struct boot_command *boot_command;
struct client *client = arg;
struct pb_protocol_message *message;
struct boot_command *boot_command;
struct client *client = arg;
message = pb_protocol_read_message(client, client->fd);
message = pb_protocol_read_message(client, client->fd);
- boot_command = pb_protocol_deserialise_boot_command(client, message);
- if (!boot_command) {
+ boot_command = talloc(client, struct boot_command);
+
+ rc = pb_protocol_deserialise_boot_command(boot_command, message);
+ if (rc) {
pb_log("%s: no boot command?", __func__);
return 0;
}
pb_log("%s: no boot command?", __func__);
return 0;
}
-struct device *pb_protocol_deserialise_device(void *ctx,
+int pb_protocol_deserialise_device(struct device *dev,
const struct pb_protocol_message *message)
{
const struct pb_protocol_message *message)
{
const char *pos;
int i, n_options;
unsigned int len;
const char *pos;
int i, n_options;
unsigned int len;
len = message->payload_len;
pos = message->payload;
len = message->payload_len;
pos = message->payload;
- dev = talloc(ctx, struct device);
-
if (read_string(dev, &pos, &len, &dev->id))
goto out_err;
if (read_string(dev, &pos, &len, &dev->id))
goto out_err;
list_add(&dev->boot_options, &opt->list);
}
list_add(&dev->boot_options, &opt->list);
}
- talloc_free(dev);
- return NULL;
-struct boot_command *pb_protocol_deserialise_boot_command(void *ctx,
+int pb_protocol_deserialise_boot_command(struct boot_command *cmd,
const struct pb_protocol_message *message)
{
const struct pb_protocol_message *message)
{
- struct boot_command *cmd;
const char *pos;
unsigned int len;
len = message->payload_len;
pos = message->payload;
const char *pos;
unsigned int len;
len = message->payload_len;
pos = message->payload;
- cmd = talloc(ctx, struct boot_command);
-
if (read_string(cmd, &pos, &len, &cmd->option_id))
goto out_err;
if (read_string(cmd, &pos, &len, &cmd->option_id))
goto out_err;
if (read_string(cmd, &pos, &len, &cmd->boot_args))
goto out_err;
if (read_string(cmd, &pos, &len, &cmd->boot_args))
goto out_err;
- talloc_free(cmd);
- return NULL;
struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd);
struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd);
-struct device *pb_protocol_deserialise_device(void *ctx,
+int pb_protocol_deserialise_device(struct device *dev,
const struct pb_protocol_message *message);
const struct pb_protocol_message *message);
-struct boot_command *pb_protocol_deserialise_boot_command(void *ctx,
+int pb_protocol_deserialise_boot_command(struct boot_command *cmd,
const struct pb_protocol_message *message);
#endif /* _PB_PROTOCOL_H */
const struct pb_protocol_message *message);
#endif /* _PB_PROTOCOL_H */
struct pb_protocol_message *message;
struct device *dev;
char *dev_id;
struct pb_protocol_message *message;
struct device *dev;
char *dev_id;
message = pb_protocol_read_message(client, client->fd);
message = pb_protocol_read_message(client, client->fd);
switch (message->action) {
case PB_PROTOCOL_ACTION_ADD:
switch (message->action) {
case PB_PROTOCOL_ACTION_ADD:
- dev = pb_protocol_deserialise_device(client, message);
- if (!dev) {
+ dev = talloc(client, struct device);
+
+ rc = pb_protocol_deserialise_device(dev, message);
+ if (rc) {
pb_log("%s: no device?\n", __func__);
return 0;
}
pb_log("%s: no device?\n", __func__);
return 0;
}