Lines Matching refs:httpd

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