Lines Matching refs:httpd
100 create_pidfile(bozohttpd_t *httpd)
106 if (httpd->pidfile == NULL)
110 bozoerr(httpd, 1, "Failed to install pidfile handler");
112 if ((file = fopen(httpd->pidfile, "w")) == NULL)
113 bozoerr(httpd, 1, "Failed to create pidfile '%s'",
114 httpd->pidfile);
118 pidfile_path = httpd->pidfile;
121 debug((httpd, DEBUG_FAT, "Created pid file '%s' for pid %d",
126 bozo_daemon_init(bozohttpd_t *httpd)
132 if (!httpd->background && !httpd->foreground)
135 if (!httpd->background)
136 httpd->background = 1;
138 portnum = (httpd->bindport) ? httpd->bindport : "http";
144 e = getaddrinfo(httpd->bindaddress, portnum, &h, &r0);
146 bozoerr(httpd, 1, "getaddrinfo([%s]:%s): %s",
147 httpd->bindaddress ? httpd->bindaddress : "*",
150 httpd->nsock++;
151 httpd->sock = bozomalloc(httpd, httpd->nsock * sizeof(*httpd->sock));
152 httpd->fds = bozomalloc(httpd, httpd->nsock * sizeof(*httpd->fds));
154 httpd->sock[i] = socket(r->ai_family, SOCK_STREAM, 0);
155 if (httpd->sock[i] == -1)
157 if (setsockopt(httpd->sock[i], SOL_SOCKET, SO_REUSEADDR, &on,
159 bozowarn(httpd, "setsockopt SO_REUSEADDR: %s",
161 if (bind(httpd->sock[i], r->ai_addr, r->ai_addrlen) == -1)
163 if (listen(httpd->sock[i], SOMAXCONN) == -1)
165 httpd->fds[i].events = POLLIN | POLLPRI | POLLRDNORM |
167 httpd->fds[i].fd = httpd->sock[i];
171 bozoerr(httpd, 1, "could not find any addresses to bind");
172 httpd->nsock = i;
175 if (httpd->foreground == 0)
178 create_pidfile(httpd);
180 bozowarn(httpd, "started in daemon mode as `%s' port `%s' root `%s'",
181 httpd->virthostname, portnum, httpd->slashdir);
191 bozo_daemon_closefds(bozohttpd_t *httpd)
195 for (i = 0; i < httpd->nsock; i++)
196 close(httpd->sock[i]);
200 daemon_runchild(bozohttpd_t *httpd, int fd)
202 httpd->request_times++;
212 daemon_poll_err(bozohttpd_t *httpd, int idx)
214 if ((httpd->fds[idx].revents & (POLLNVAL|POLLERR|POLLHUP)) == 0)
217 bozowarn(httpd, "poll on fd %d pid %d revents %d: %s",
218 httpd->fds[idx].fd, getpid(), httpd->fds[idx].revents,
220 bozowarn(httpd, "nsock = %d", httpd->nsock);
221 close(httpd->sock[idx]);
222 httpd->nsock--;
223 bozowarn(httpd, "nsock now = %d", httpd->nsock);
225 if (httpd->nsock == 0)
228 if (httpd->nsock != idx) {
229 memmove(&httpd->fds[idx], &httpd->fds[idx+1],
230 (httpd->nsock - idx) * sizeof(*httpd->fds));
231 memmove(&httpd->sock[idx], &httpd->sock[idx+1],
232 (httpd->nsock - idx) * sizeof(*httpd->sock));
243 bozo_daemon_fork(bozohttpd_t *httpd)
247 debug((httpd, DEBUG_FAT, "%s: pid %u request_times %d",
249 httpd->request_times));
251 if (httpd->request_times > 5 ||
252 (httpd->background == 2 && httpd->request_times > 0))
256 if (httpd->request_times > 0)
260 while (httpd->background) {
265 if (httpd->nsock == 0)
275 if (poll(httpd->fds, (unsigned)httpd->nsock, INFTIM) == -1) {
279 bozoerr(httpd, 1, "poll: %s",
290 for (i = 0; i < httpd->nsock; i++) {
291 if (daemon_poll_err(httpd, i))
293 if (httpd->fds[i].revents == 0)
297 fd = accept(httpd->fds[i].fd,
302 bozoerr(httpd, 1, "accept: %s",
317 if (httpd->request_times > 0) {
318 daemon_runchild(httpd, fd);
325 bozowarn(httpd, "fork() failed, sleeping for "
332 daemon_runchild(httpd, fd);