From 613b848d6d5a1dc7e714582c74bc98ffed1d84a0 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 26 Oct 2007 15:18:31 +0200 Subject: [PATCH] Set more file descriptors to non-blocking mode. --- afs.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/afs.c b/afs.c index 34e53806..c36f86b8 100644 --- a/afs.c +++ b/afs.c @@ -612,7 +612,7 @@ static void init_admissible_files(char *arg) static int setup_command_socket_or_die(void) { - int ret; + int ret, socket_fd; char *socket_name = conf.afs_socket_arg; struct sockaddr_un unix_addr; @@ -623,13 +623,18 @@ static int setup_command_socket_or_die(void) PARA_EMERG_LOG("%s: %s\n", PARA_STRERROR(-ret), socket_name); exit(EXIT_FAILURE); } - if (listen(ret , 5) < 0) { - PARA_EMERG_LOG("%s", "can not listen on socket\n"); + socket_fd = ret; + if (listen(socket_fd , 5) < 0) { + PARA_EMERG_LOG("can not listen on socket\n"); exit(EXIT_FAILURE); } - PARA_INFO_LOG("listening on command socket %s (fd %d)\n", socket_name, - ret); - return ret; + ret = mark_fd_nonblock(socket_fd); + if (ret < 0) { + close(socket_fd); + return ret; + } + PARA_INFO_LOG("listening on socket %s (fd %d)\n", socket_name, ret); + return socket_fd; } static void close_afs_tables(void) @@ -884,7 +889,7 @@ static void command_post_select(struct sched *s, struct task *t) struct command_task *ct = t->private_data; struct sockaddr_un unix_addr; struct afs_client *client, *tmp; - + int fd; if (FD_ISSET(server_socket, &s->rfds)) execute_server_command(); @@ -911,8 +916,15 @@ static void command_post_select(struct sched *s, struct task *t) PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-t->ret)); goto out; } + fd = t->ret; + t->ret = mark_fd_nonblock(fd); + if (t->ret < 0) { + PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-t->ret)); + close(fd); + goto out; + } client = para_malloc(sizeof(*client)); - client->fd = t->ret; + client->fd = fd; client->connect_time = *now; para_list_add(&client->node, &afs_client_list); out: -- 2.30.2