- if (child = dsi_start(&obj, (DSI *)polldata[i].data, server_children)) {
- /* Add IPC fd to select fd set */
- fdset_add_fd(obj.options.connections + AFP_LISTENERS + FDSET_SAFETY,
- &fdset,
- &polldata,
- &fdset_used,
- &fdset_size,
- child->ipc_fd,
- IPC_FD,
- child);
- }
- break;
-
- case IPC_FD:
- child = (afp_child_t *)polldata[i].data;
- LOG(log_debug, logtype_afpd, "main: IPC request from child[%u]", child->pid);
-
- if (ipc_server_read(server_children, child->ipc_fd) != 0) {
- fdset_del_fd(&fdset, &polldata, &fdset_used, &fdset_size, child->ipc_fd);
- close(child->ipc_fd);
- child->ipc_fd = -1;
- if ((obj.options.flags & OPTION_KEEPSESSIONS) && child->disasociated) {
- LOG(log_note, logtype_afpd, "main: removing reattached child[%u]", child->pid);
- server_child_remove(server_children, CHILD_DSIFORK, child->pid);
+ 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);