+static int server_select(int max_fileno, fd_set *readfds, fd_set *writefds,
+ struct timeval *timeout_tv)
+{
+ int ret;
+
+ status_refresh();
+ mmd_unlock();
+ ret = para_select(max_fileno + 1, readfds, writefds, timeout_tv);
+ mmd_lock();
+ return ret;
+}
+
+static void command_pre_select(int *max_fileno, fd_set *rfds)
+{
+ para_fd_set(listen_fd, rfds, max_fileno);
+}
+
+static void command_post_select(fd_set *rfds)
+{
+ int new_fd, ret;
+ char *peer_name;
+ pid_t child_pid;
+
+ if (!FD_ISSET(listen_fd, rfds))
+ return;
+ ret = para_accept(listen_fd, NULL, 0);
+ if (ret < 0)
+ goto out;
+ new_fd = ret;
+ peer_name = remote_name(new_fd);
+ PARA_INFO_LOG("got connection from %s, forking\n", peer_name);
+ mmd->num_connects++;
+ mmd->active_connections++;
+ random();
+ child_pid = fork();
+ if (child_pid < 0) {
+ ret = -ERRNO_TO_PARA_ERROR(errno);
+ goto out;
+ }
+ if (child_pid) {
+ close(new_fd);
+ /* parent keeps accepting connections */
+ return;
+ }
+ alarm(ALARM_TIMEOUT);
+ close_listed_fds();
+ para_signal_shutdown();
+ /*
+ * put info on who we are serving into argv[0] to make
+ * client ip visible in top/ps
+ */
+// for (i = argc - 1; i >= 0; i--)
+// memset(argv[i], 0, strlen(argv[i]));
+// sprintf(argv[0], "para_server (serving %s)", peer_name);
+ return handle_connect(new_fd, peer_name);
+out:
+ if (ret < 0)
+ PARA_CRIT_LOG("%s\n", para_strerror(-ret));
+}
+