abduco

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit e48ea73ce0e636b8d7b86e4ed0609fdd403f433a
parent bb7e4e77f466fd9d01244484b7328587484881ed
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sat, 17 Mar 2018 19:04:49 +0100

Move server_accept_client function around

Diffstat:
server.c | 42+++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/server.c b/server.c @@ -75,27 +75,6 @@ static int server_set_socket_non_blocking(int sock) { return fcntl(sock, F_SETFL, flags | O_NONBLOCK); } -static Client *server_accept_client(void) { - int newfd = accept(server.socket, NULL, NULL); - if (newfd == -1 || server_set_socket_non_blocking(newfd) == -1) - goto error; - Client *c = client_malloc(newfd); - if (!c) - goto error; - if (!server.clients) - server_mark_socket_exec(true, true); - c->socket = newfd; - c->state = STATE_CONNECTED; - c->next = server.clients; - server.clients = c; - server.read_pty = true; - return c; -error: - if (newfd != -1) - close(newfd); - return NULL; -} - static bool server_read_pty(Packet *pkt) { pkt->type = MSG_CONTENT; ssize_t len = read(server.pty, pkt->u.msg, sizeof(pkt->u.msg)); @@ -157,6 +136,27 @@ static void server_sigterm_handler(int sig) { exit(EXIT_FAILURE); /* invoke atexit handler */ } +static Client *server_accept_client(void) { + int newfd = accept(server.socket, NULL, NULL); + if (newfd == -1 || server_set_socket_non_blocking(newfd) == -1) + goto error; + Client *c = client_malloc(newfd); + if (!c) + goto error; + if (!server.clients) + server_mark_socket_exec(true, true); + c->socket = newfd; + c->state = STATE_CONNECTED; + c->next = server.clients; + server.clients = c; + server.read_pty = true; + return c; +error: + if (newfd != -1) + close(newfd); + return NULL; +} + static void server_sigusr1_handler(int sig) { int socket = server_create_socket(server.session_name); if (socket != -1) {