include $(TOPDIR)/rules.mk
PKG_NAME:=uhttpd
-PKG_RELEASE:=3
+PKG_RELEASE:=4
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
FD_SET(wfd[1], &writer);
/* wait until we can read or write or both */
- if( select(fd_max, &reader,
+ if( select_intr(fd_max, &reader,
(content_length > -1) ? &writer : NULL, NULL,
(header_sent < 1) ? &timeout : NULL) > 0
) {
FD_SET(wfd[1], &writer);
/* wait until we can read or write or both */
- if( select(fd_max, &reader,
+ if( select_intr(fd_max, &reader,
(content_length > -1) ? &writer : NULL, NULL,
(data_sent < 1) ? &timeout : NULL) > 0
) {
return NULL;
}
+/* interruptable select() */
+int select_intr(int n, fd_set *r, fd_set *w, fd_set *e, struct timeval *t)
+{
+ int rv;
+ sigset_t ssn, sso;
+
+ /* unblock SIGCHLD */
+ sigemptyset(&ssn);
+ sigaddset(&ssn, SIGCHLD);
+ sigprocmask(SIG_UNBLOCK, &ssn, &sso);
+
+ rv = select(n, r, w, e, t);
+
+ /* restore signal mask */
+ sigprocmask(SIG_SETMASK, &sso, NULL);
+
+ return rv;
+}
+
int uh_tcp_send(struct client *cl, const char *buf, int len)
{
char *strfind(char *haystack, int hslen, const char *needle, int ndlen);
+int select_intr(int n, fd_set *r, fd_set *w, fd_set *e, struct timeval *t);
+
int uh_tcp_send(struct client *cl, const char *buf, int len);
int uh_tcp_peek(struct client *cl, char *buf, int len);
int uh_tcp_recv(struct client *cl, char *buf, int len);
struct sigaction sa;
struct config conf;
+ /* signal mask */
+ sigset_t ss;
+
/* maximum file descriptor number */
int new_fd, cur_fd, max_fd = 0;
FD_ZERO(&serv_fds);
FD_ZERO(&read_fds);
- /* handle SIGPIPE, SIGCHILD */
+ /* handle SIGPIPE, SIGINT, SIGTERM, SIGCHLD */
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
+ /* defer SIGCHLD */
+ sigemptyset(&ss);
+ sigaddset(&ss, SIGCHLD);
+ sigprocmask(SIG_BLOCK, &ss, NULL);
+
/* prepare addrinfo hints */
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;