| 881 | |
| 882 | static struct strvec cld_argv = STRVEC_INIT; |
| 883 | static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen) |
| 884 | { |
| 885 | struct child_process cld = CHILD_PROCESS_INIT; |
| 886 | |
| 887 | if (max_connections && live_children >= max_connections) { |
| 888 | kill_some_child(); |
| 889 | sleep(1); /* give it some time to die */ |
| 890 | check_dead_children(); |
| 891 | if (live_children >= max_connections) { |
| 892 | close(incoming); |
| 893 | logerror("Too many children, dropping connection"); |
| 894 | return; |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | if (addr->sa_family == AF_INET) { |
| 899 | char buf[128] = ""; |
| 900 | struct sockaddr_in *sin_addr = (void *) addr; |
| 901 | inet_ntop(addr->sa_family, &sin_addr->sin_addr, buf, sizeof(buf)); |
| 902 | strvec_pushf(&cld.env, "REMOTE_ADDR=%s", buf); |
| 903 | strvec_pushf(&cld.env, "REMOTE_PORT=%d", |
| 904 | ntohs(sin_addr->sin_port)); |
| 905 | #ifndef NO_IPV6 |
| 906 | } else if (addr->sa_family == AF_INET6) { |
| 907 | char buf[128] = ""; |
| 908 | struct sockaddr_in6 *sin6_addr = (void *) addr; |
| 909 | inet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(buf)); |
| 910 | strvec_pushf(&cld.env, "REMOTE_ADDR=[%s]", buf); |
| 911 | strvec_pushf(&cld.env, "REMOTE_PORT=%d", |
| 912 | ntohs(sin6_addr->sin6_port)); |
| 913 | #endif |
| 914 | } |
| 915 | |
| 916 | strvec_pushv(&cld.args, cld_argv.v); |
| 917 | cld.in = incoming; |
| 918 | cld.out = dup(incoming); |
| 919 | |
| 920 | if (start_command(&cld)) |
| 921 | logerror("unable to fork"); |
| 922 | else |
| 923 | add_child(&cld, addr, addrlen); |
| 924 | } |
| 925 | |
| 926 | static void child_handler(int signo UNUSED) |
| 927 | { |
no test coverage detected