if (debug) log_d("fork_request: fcntl(2, F_SETFL, 0) = %d", rv);
int fork_request(struct request *r, int (*f)(struct request *)){	int fd, efd, rv;	pid_t pid;	char *child_filename;	if (forked)		_exit(1);	pid = fork();	switch (pid) {	case 0:		my_pid = getpid();		if (debug)			log_d("fork_request: child process created");		forked = 1;		mysignal(SIGPIPE, SIG_DFL);		fd = r->cn->fd;		child_filename = r->c->child_filename;		if (child_filename == 0)			efd = fd;		else {			efd = open(child_filename, O_WRONLY | O_CREAT | O_APPEND, DEFAULT_FILEMODE);			if (debug)				log_d("fork_request: open(\"%s\", ...) = %d", child_filename, efd);			if (efd == -1) {				log_d("cannot open child log %s", child_filename);				lerror("open");				efd = fd;			}		}		rv = dup2(fd, 0);		if (debug)			log_d("fork_request: dup2(%d, 0) = %d", fd, rv);		rv = dup2(fd, 1);		if (debug)			log_d("fork_request: dup2(%d, 1) = %d", fd, rv);		rv = dup2(efd, 2);		if (debug)			log_d("fork_request: dup2(%d, 2) = %d", efd, rv);		rv = fcntl(0, F_SETFL, 0);		if (debug)			log_d("fork_request: fcntl(0, F_SETFL, 0) = %d", rv);		rv = fcntl(1, F_SETFL, 0);		if (debug)			log_d("fork_request: fcntl(1, F_SETFL, 0) = %d", rv);		if (efd == fd) {			rv = fcntl(2, F_SETFL, 0);			if (debug)				log_d("fork_request: fcntl(2, F_SETFL, 0) = %d", rv);		}		rv = close(fd);		if (debug)			log_d("fork_request: close(%d) = %d", fd, rv);		if (efd != fd) {			rv = close(efd);			if (debug)				log_d("fork_request: close(%d) = %d", efd, rv);		}		rv = f(r);		if (debug)			log_d("fork_request: _exit(%d)", rv);		_exit(rv);		break;	case -1:		lerror("fork");		return 503;	default:		log_d("child process %d created", pid);		r->status_line = "---";	}	return -1;}