- for (config = configs; config; config = config->next) {
- if (config->fd < 0)
- continue;
- if (FD_ISSET(config->fd, &rfds))
- config->server_start(config, configs, server_children);
- }
- }
+ for (int i = 0; i < asev->used; i++) {
+ if (asev->fdset[i].revents & (POLLIN | POLLERR | POLLHUP | POLLNVAL)) {
+ switch (asev->data[i].fdtype) {
+
+ case LISTEN_FD:
+ if ((child = dsi_start(&obj, (DSI *)(asev->data[i].private), server_children))) {
+ if (!(asev_add_fd(asev, child->afpch_ipc_fd, IPC_FD, child))) {
+ LOG(log_error, logtype_afpd, "out of asev slots");
+
+ /*
+ * Close IPC fd here and mark it as unused
+ */
+ close(child->afpch_ipc_fd);
+ child->afpch_ipc_fd = -1;
+
+ /*
+ * Being unfriendly here, but we really
+ * want to get rid of it. The 'child'
+ * handle gets cleaned up in the SIGCLD
+ * handler.
+ */
+ kill(child->afpch_pid, SIGKILL);
+ }
+ }
+ break;
+
+ case IPC_FD:
+ child = (afp_child_t *)(asev->data[i].private);
+ LOG(log_debug, logtype_afpd, "main: IPC request from child[%u]", child->afpch_pid);
+
+ if (ipc_server_read(server_children, child->afpch_ipc_fd) != 0) {
+ if (!(asev_del_fd(asev, child->afpch_ipc_fd))) {
+ LOG(log_error, logtype_afpd, "child[%u]: no IPC fd");
+ }
+ close(child->afpch_ipc_fd);
+ child->afpch_ipc_fd = -1;
+ }
+ break;
+
+ default:
+ LOG(log_debug, logtype_afpd, "main: IPC request for unknown type");
+ break;
+ } /* switch */
+ } /* if */
+ } /* for (i)*/
+ } /* while (1) */