+ int fd;
+ int status, i;
+ pid_t pid;
+
+#ifndef WAIT_ANY
+#define WAIT_ANY (-1)
+#endif /* ! WAIT_ANY */
+
+ while ((pid = waitpid(WAIT_ANY, &status, WNOHANG)) > 0) {
+ for (i = 0; i < server_children->nforks; i++) {
+ if ((fd = server_child_remove(server_children, i, pid)) != -1) {
+ fdset_del_fd(&fdset, &polldata, &fdset_used, &fdset_size, fd);
+ break;
+ }
+ }
+
+ if (WIFEXITED(status)) {
+ if (WEXITSTATUS(status))
+ LOG(log_info, logtype_afpd, "child[%d]: exited %d", pid, WEXITSTATUS(status));
+ else
+ LOG(log_info, logtype_afpd, "child[%d]: done", pid);
+ } else {
+ if (WIFSIGNALED(status))
+ LOG(log_info, logtype_afpd, "child[%d]: killed by signal %d", pid, WTERMSIG(status));
+ else
+ LOG(log_info, logtype_afpd, "child[%d]: died", pid);
+ }
+ }
+}
+
+static int setlimits(void)
+{
+ struct rlimit rlim;
+
+ if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
+ LOG(log_error, logtype_afpd, "setlimits: %s", strerror(errno));
+ exit(1);
+ }
+ if (rlim.rlim_cur != RLIM_INFINITY && rlim.rlim_cur < 65535) {
+ rlim.rlim_cur = 65535;
+ if (rlim.rlim_max != RLIM_INFINITY && rlim.rlim_max < 65535)
+ rlim.rlim_max = 65535;
+ if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
+ LOG(log_error, logtype_afpd, "setlimits: %s", strerror(errno));
+ exit(1);
+ }
+ }
+ return 0;