+ ret = call_callback(fd, query_shmid);
+ if (ret >= 0)
+ return;
+err:
+ PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
+}
+
+/** Shutdown connection if query has not arrived until this many seconds. */
+#define AFS_CLIENT_TIMEOUT 3
+
+static void command_post_select(struct sched *s, struct task *t)
+{
+ struct command_task *ct = container_of(t, struct command_task, task);
+ struct sockaddr_un unix_addr;
+ struct afs_client *client, *tmp;
+ int fd, ret;
+
+ if (FD_ISSET(server_socket, &s->rfds)) {
+ ret = execute_server_command();
+ if (ret < 0) {
+ PARA_EMERG_LOG("%s\n", para_strerror(-ret));
+ sched_shutdown();
+ return;
+ }
+ }
+
+ /* Check the list of connected clients. */
+ list_for_each_entry_safe(client, tmp, &afs_client_list, node) {
+ if (FD_ISSET(client->fd, &s->rfds))
+ execute_afs_command(client->fd, ct->cookie);
+ else { /* prevent bogus connection flooding */
+ struct timeval diff;
+ tv_diff(now, &client->connect_time, &diff);
+ if (diff.tv_sec < AFS_CLIENT_TIMEOUT)
+ continue;
+ PARA_WARNING_LOG("connection timeout\n");
+ }
+ close(client->fd);
+ list_del(&client->node);
+ free(client);
+ }
+ /* Accept connections on the local socket. */
+ if (!FD_ISSET(ct->fd, &s->rfds))
+ return;
+ ret = para_accept(ct->fd, &unix_addr, sizeof(unix_addr));
+ if (ret < 0) {
+ PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
+ return;
+ }
+ fd = ret;
+ ret = mark_fd_nonblocking(fd);
+ if (ret < 0) {
+ PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
+ close(fd);
+ return;
+ }
+ client = para_malloc(sizeof(*client));
+ client->fd = fd;
+ client->connect_time = *now;
+ para_list_add(&client->node, &afs_client_list);