X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fdiscover-server.c;h=2467e33dc97ac5b9cfc45c44576f18d6f969c79a;hp=67ce266c4c433fced328f810360094cd8e60f10f;hb=0ed4725477f7676d7b3d72d5e5a1008bdb045e2d;hpb=658d9e98eec02f92e3cf263a1bb27beb3d395b2f diff --git a/discover/discover-server.c b/discover/discover-server.c index 67ce266..2467e33 100644 --- a/discover/discover-server.c +++ b/discover/discover-server.c @@ -19,6 +19,7 @@ #include "device-handler.h" #include "discover-server.h" +#include "sysinfo.h" struct discover_server { int socket; @@ -33,6 +34,7 @@ struct client { struct list_item list; struct waiter *waiter; int fd; + bool remote_closed; }; @@ -88,9 +90,12 @@ static int client_write_message( { int rc; + if (client->remote_closed) + return -1; + rc = pb_protocol_write_message(client->fd, message); if (rc) - talloc_free(client); + client->remote_closed = true; return rc; } @@ -167,6 +172,24 @@ static int write_boot_status_message(struct discover_server *server, return client_write_message(server, client, message); } +static int write_system_info_message(struct discover_server *server, + struct client *client, const struct system_info *sysinfo) +{ + struct pb_protocol_message *message; + int len; + + len = pb_protocol_system_info_len(sysinfo); + + message = pb_protocol_create_message(client, + PB_PROTOCOL_ACTION_SYSTEM_INFO, len); + if (!message) + return -1; + + pb_protocol_serialise_system_info(sysinfo, message->payload, len); + + return client_write_message(server, client, message); +} + static int discover_server_process_message(void *arg) { struct pb_protocol_message *message; @@ -182,20 +205,30 @@ static int discover_server_process_message(void *arg) } - if (message->action != PB_PROTOCOL_ACTION_BOOT) { - pb_log("%s: invalid action %d\n", __func__, message->action); - return 0; - } + switch (message->action) { + case PB_PROTOCOL_ACTION_BOOT: + 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; + } + + device_handler_boot(client->server->device_handler, + boot_command); + break; - boot_command = talloc(client, struct boot_command); + case PB_PROTOCOL_ACTION_CANCEL_DEFAULT: + device_handler_cancel_default(client->server->device_handler); + break; - rc = pb_protocol_deserialise_boot_command(boot_command, message); - if (rc) { - pb_log("%s: no boot command?", __func__); + default: + pb_log("%s: invalid action %d\n", __func__, message->action); return 0; } - device_handler_boot(client->server->device_handler, boot_command); return 0; } @@ -221,6 +254,14 @@ static int discover_server_process_connection(void *arg) client->fd = fd; client->server = server; + client->waiter = waiter_register_io(server->waitset, client->fd, + WAIT_IN, discover_server_process_message, + client); + + /* send sysinfo to client */ + rc = write_system_info_message(server, client, system_info_get()); + if (rc) + return 0; /* send existing devices to client */ n_devices = device_handler_get_device_count(server->device_handler); @@ -241,10 +282,6 @@ static int discover_server_process_connection(void *arg) } } - client->waiter = waiter_register_io(server->waitset, client->fd, - WAIT_IN, discover_server_process_message, - client); - return 0; } @@ -286,6 +323,15 @@ void discover_server_notify_boot_status(struct discover_server *server, write_boot_status_message(server, client, status); } +void discover_server_notify_system_info(struct discover_server *server, + const struct system_info *sysinfo) +{ + struct client *client; + + list_for_each_entry(&server->clients, client, list) + write_system_info_message(server, client, sysinfo); +} + void discover_server_set_device_source(struct discover_server *server, struct device_handler *handler) {