diff options
Diffstat (limited to 'seatd')
-rw-r--r-- | seatd/poller.c | 16 | ||||
-rw-r--r-- | seatd/seatd.c | 2 | ||||
-rw-r--r-- | seatd/server.c | 26 |
3 files changed, 14 insertions, 30 deletions
diff --git a/seatd/poller.c b/seatd/poller.c index 43a57b4..f786d47 100644 --- a/seatd/poller.c +++ b/seatd/poller.c @@ -10,28 +10,20 @@ #include "list.h" #include "poller.h" +/* Used for signal handling */ struct poller *global_poller = NULL; -struct poller *poller_create(void) { - if (global_poller != NULL) { - errno = EEXIST; - return NULL; - } +void poller_init(struct poller *poller) { + assert(global_poller == NULL); - struct poller *poller = calloc(1, sizeof(struct poller)); - if (poller == NULL) { - errno = ENOMEM; - return NULL; - } list_init(&poller->fds); list_init(&poller->new_fds); list_init(&poller->signals); list_init(&poller->new_signals); global_poller = poller; - return poller; } -int poller_destroy(struct poller *poller) { +int poller_finish(struct poller *poller) { for (size_t idx = 0; idx < poller->fds.length; idx++) { struct event_source_fd *bpfd = poller->fds.items[idx]; free(bpfd); diff --git a/seatd/seatd.c b/seatd/seatd.c index c1cdccf..0c83253 100644 --- a/seatd/seatd.c +++ b/seatd/seatd.c @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) { log_info("seatd started"); while (server->running) { - if (poller_poll(server->poller) == -1) { + if (poller_poll(&server->poller) == -1) { log_errorf("poller failed: %s", strerror(errno)); return 1; } diff --git a/seatd/server.c b/seatd/server.c index 725ebf7..017aa39 100644 --- a/seatd/server.c +++ b/seatd/server.c @@ -27,23 +27,18 @@ static int server_handle_vt_rel(int signal, void *data); static int server_handle_kill(int signal, void *data); struct server *server_create(void) { - struct poller *poller = poller_create(); - if (poller == NULL) { - log_error("could not create poller"); - return NULL; - } struct server *server = calloc(1, sizeof(struct server)); if (server == NULL) { return NULL; } - server->poller = poller; + poller_init(&server->poller); list_init(&server->seats); - if (poller_add_signal(poller, SIGUSR1, server_handle_vt_rel, server) == NULL || - poller_add_signal(poller, SIGUSR2, server_handle_vt_acq, server) == NULL || - poller_add_signal(poller, SIGINT, server_handle_kill, server) == NULL || - poller_add_signal(poller, SIGTERM, server_handle_kill, server) == NULL) { + if (poller_add_signal(&server->poller, SIGUSR1, server_handle_vt_rel, server) == NULL || + poller_add_signal(&server->poller, SIGUSR2, server_handle_vt_acq, server) == NULL || + poller_add_signal(&server->poller, SIGINT, server_handle_kill, server) == NULL || + poller_add_signal(&server->poller, SIGTERM, server_handle_kill, server) == NULL) { server_destroy(server); return NULL; } @@ -69,10 +64,7 @@ void server_destroy(struct server *server) { seat_destroy(seat); } list_free(&server->seats); - if (server->poller != NULL) { - poller_destroy(server->poller); - server->poller = NULL; - } + poller_finish(&server->poller); free(server); } @@ -152,7 +144,7 @@ static int server_handle_connection(int fd, uint32_t mask, void *data) { } struct client *client = client_create(server, new_fd); - client->event_source = poller_add_fd(server->poller, new_fd, EVENT_READABLE, + client->event_source = poller_add_fd(&server->poller, new_fd, EVENT_READABLE, client_handle_connection, client); if (client->event_source == NULL) { client_destroy(client); @@ -174,7 +166,7 @@ int server_add_client(struct server *server, int fd) { struct client *client = client_create(server, fd); client->event_source = - poller_add_fd(server->poller, fd, EVENT_READABLE, client_handle_connection, client); + poller_add_fd(&server->poller, fd, EVENT_READABLE, client_handle_connection, client); if (client->event_source == NULL) { client_destroy(client); log_errorf("could not add client socket to poller: %s", strerror(errno)); @@ -222,7 +214,7 @@ int server_listen(struct server *server, const char *path) { } else { log_errorf("could not get video group: %s", strerror(errno)); } - if (poller_add_fd(server->poller, fd, EVENT_READABLE, server_handle_connection, server) == + if (poller_add_fd(&server->poller, fd, EVENT_READABLE, server_handle_connection, server) == NULL) { log_errorf("could not add socket to poller: %s", strerror(errno)); close(fd); |