Browse Source

close fds on error and add CLOEXEC to FDs which stay open for a longer time

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@794 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.7
Jan Kneschke 17 years ago
parent
commit
ff29203dba
  1. 3
      src/mod_compress.c
  2. 12
      src/network_linux_sendfile.c
  3. 1
      src/network_openssl.c
  4. 2
      src/network_write.c
  5. 4
      src/network_writev.c

3
src/mod_compress.c

@ -439,6 +439,9 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, bu
}
if (-1 == (r = write(ofd, p->b->ptr, p->b->used))) {
munmap(start, sce->st.st_size);
close(ofd);
close(ifd);
return -1;
}

12
src/network_linux_sendfile.c

@ -146,11 +146,15 @@ int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, int fd,
}
/* open file if not already opened */
if (-1 == c->file.fd &&
-1 == (c->file.fd = open(c->file.name->ptr, O_RDONLY))) {
log_error_write(srv, __FILE__, __LINE__, "ss", "open failed: ", strerror(errno));
if (-1 == c->file.fd) {
if (-1 == (c->file.fd = open(c->file.name->ptr, O_RDONLY))) {
log_error_write(srv, __FILE__, __LINE__, "ss", "open failed: ", strerror(errno));
return -1;
return -1;
}
#ifdef FD_CLOEXEC
fcntl(c->file.fd, F_SETFD, FD_CLOEXEC);
#endif
}
/* Linux sendfile() */

1
src/network_openssl.c

@ -171,6 +171,7 @@ int network_write_chunkqueue_openssl(server *srv, connection *con, SSL *ssl, chu
lseek(ifd, offset, SEEK_SET);
if (-1 == (toSend = read(ifd, local_send_buffer, toSend))) {
close(ifd);
log_error_write(srv, __FILE__, __LINE__, "ss", "read failed: ", strerror(errno));
return -1;
}

2
src/network_write.c

@ -110,7 +110,7 @@ int network_write_chunkqueue_write(server *srv, connection *con, int fd, chunkqu
if ((r = write(fd, p + offset, toSend)) <= 0) {
log_error_write(srv, __FILE__, __LINE__, "ss", "write failed: ", strerror(errno));
munmap(p, sce->st.st_size);
return -1;
}

4
src/network_writev.c

@ -196,7 +196,11 @@ int network_write_chunkqueue_writev(server *srv, connection *con, int fd, chunkq
* 3. use non-blocking IO for file-transfers
* */
if (MAP_FAILED == (c->file.mmap.start = mmap(0, sce->st.st_size, PROT_READ, MAP_SHARED, c->file.fd, 0))) {
/* close it here, otherwise we'd have to set FD_CLOEXEC */
close(c->file.fd);
c->file.fd = -1;
log_error_write(srv, __FILE__, __LINE__, "ssbd", "mmap failed: ",
strerror(errno), c->file.name, c->file.fd);

Loading…
Cancel
Save