diff options
author | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2016-12-14 14:44:23 +1100 |
---|---|---|
committer | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2016-12-20 16:40:22 +1100 |
commit | 75c97cfd449b2bac8e61af1017a83bdf43f5e8fe (patch) | |
tree | cc6b4a0bf23e58cb1cd737a3cefdf7c54c4f7566 /discover/discover-server.c | |
parent | 6a065198be213092c67071ee77eccf3e493a4cba (diff) | |
download | petitboot-75c97cfd449b2bac8e61af1017a83bdf43f5e8fe.zip petitboot-75c97cfd449b2bac8e61af1017a83bdf43f5e8fe.tar.gz |
discover: Maintain a backlog of status updates
Add status updates to a persistent list in the discover_server struct,
and send each client the backlog on connect. This avoids clients missing
useful messages from early init. Clients will only show this in the
backlog screen to avoid flooding the client's status line.
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'discover/discover-server.c')
-rw-r--r-- | discover/discover-server.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/discover/discover-server.c b/discover/discover-server.c index ad184f6..a3087b3 100644 --- a/discover/discover-server.c +++ b/discover/discover-server.c @@ -28,6 +28,7 @@ struct discover_server { struct waitset *waitset; struct waiter *waiter; struct list clients; + struct list status; struct device_handler *device_handler; }; @@ -282,6 +283,7 @@ static int discover_server_process_message(void *arg) static int discover_server_process_connection(void *arg) { struct discover_server *server = arg; + struct statuslog_entry *entry; int fd, rc, i, n_devices; struct client *client; @@ -333,6 +335,10 @@ static int discover_server_process_connection(void *arg) } } + /* send status backlog to client */ + list_for_each_entry(&server->status, entry, list) + write_boot_status_message(server, client, entry->status); + return 0; } @@ -368,8 +374,26 @@ void discover_server_notify_device_remove(struct discover_server *server, void discover_server_notify_boot_status(struct discover_server *server, struct status *status) { + struct statuslog_entry *entry; struct client *client; + /* Duplicate the status struct to add to the backlog */ + entry = talloc(server, struct statuslog_entry); + if (!entry) { + pb_log("Failed to allocated saved status!\n"); + } else { + entry->status = talloc(entry, struct status); + if (entry->status) { + entry->status->type = status->type; + entry->status->message = talloc_strdup(entry->status, + status->message); + entry->status->backlog = true; + list_add_tail(&server->status, &entry->list); + } else { + talloc_free(entry); + } + } + list_for_each_entry(&server->clients, client, list) write_boot_status_message(server, client, status); } @@ -410,6 +434,7 @@ struct discover_server *discover_server_init(struct waitset *waitset) server->waiter = NULL; server->waitset = waitset; list_init(&server->clients); + list_init(&server->status); unlink(PB_SOCKET_PATH); |