-/* returns:
- * negative errno on error
- * -2 if server commands to terminate
- * 0 if all ok
- * ERRNO on other errors
- */
-
-int prefork_wait_for_client(struct pf_worker_data *pf,
- int lock_fd, int listen_fd,
- struct sockaddr *addr,
- socklen_t *addrlen, int *fd)
-{
- int ret;
- int sd = -1;
- int err;
-
- ret = prefork_grab_lock(pf, lock_fd, -1);
- if (ret != 0) {
- return ret;
- }
-
- err = 0;
- do {
- sd = accept(listen_fd, addr, addrlen);
-
- if (sd != -1) break;
-
- if (errno == EINTR) {
- if (pf->cmds == PF_SRV_MSG_EXIT) {
- err = -2;
- }
- } else {
- err = errno;
- }
-
- } while ((sd == -1) && (err == 0));
-
- /* return lock now, even if the accept failed.
- * if it takes more than 10 seconds we are in deep trouble */
- ret = prefork_release_lock(pf, lock_fd, 2);
- if (ret != 0) {
- /* we were unable to release the lock!! */
- DEBUG(0, ("Terminating due to fatal failure!\n"));
-
- /* Just exit we cannot hold the whole server, better to error
- * on this one client and hope it was a transiet problem */
- err = -2;
- }
-
- if (err != 0) {
- if (sd != -1) {
- close(sd);
- sd = -1;
- }
- return err;
- }
-
- pf->status = PF_WORKER_BUSY;
- pf->num_clients++;
- *fd = sd;
- return 0;
-}
-