Tue, 14 Feb 2017 12:56:23 +0100
adds wrapper for close syscall with error handling
--- a/src/server/daemon/httplistener.c Sat Feb 04 10:06:25 2017 +0100 +++ b/src/server/daemon/httplistener.c Tue Feb 14 12:56:23 2017 +0100 @@ -50,6 +50,7 @@ #include "../util/atomic.h" #include "httplistener.h" +#include "netsite.h" #include "session.h" #include "configmanager.h" @@ -422,7 +423,7 @@ log_ereport(LOG_VERBOSE, "SSL accept error[%d]: %s", error, errstr); free(conn); conn = NULL; - close(clientfd); + system_close(clientfd); } else { conn->ssl = ssl; conn->read = connection_ssl_read;
--- a/src/server/daemon/netsite.h Sat Feb 04 10:06:25 2017 +0100 +++ b/src/server/daemon/netsite.h Tue Feb 14 12:56:23 2017 +0100 @@ -142,6 +142,8 @@ /* --- End public functions --- */ +int system_close(int fd); + #ifdef __cplusplus } #endif
--- a/src/server/daemon/sessionhandler.c Sat Feb 04 10:06:25 2017 +0100 +++ b/src/server/daemon/sessionhandler.c Tue Feb 14 12:56:23 2017 +0100 @@ -60,6 +60,7 @@ log_ereport(LOG_VERBOSE, "connection close failed: %s", strerror(errno)); break; } + log_ereport(LOG_VERBOSE, "connection close: EINTR"); } } @@ -92,6 +93,7 @@ log_ereport(LOG_VERBOSE, "connection close failed: %s", strerror(errno)); break; } + log_ereport(LOG_VERBOSE, "connection close: EINTR"); } }
--- a/src/server/daemon/vfs.c Sat Feb 04 10:06:25 2017 +0100 +++ b/src/server/daemon/vfs.c Tue Feb 14 12:56:23 2017 +0100 @@ -32,10 +32,10 @@ #include <stdlib.h> #include <unistd.h> #include <sys/types.h> - #include <ucx/map.h> #include "../util/pool.h" +#include "netsite.h" #include "acl.h" #include "vfs.h" @@ -146,7 +146,7 @@ if(((oflags & O_CREAT) == O_CREAT) && sysacl.user_uid != -1) { if(fchown(fd, sysacl.user_uid, sysacl.user_gid)) { perror("vfs_open: fchown"); - close(fd); + system_close(fd); return NULL; } } @@ -155,7 +155,7 @@ VFSFile *file = pool ? pool_malloc(pool, sizeof(VFSFile)) : malloc(sizeof(VFSFile)); if(!file) { - close(fd); + system_close(fd); return NULL; } file->ctx = ctx; @@ -487,7 +487,7 @@ } void sys_file_close(SYS_FILE fd) { - close(fd->fd); + system_close(fd->fd); } int sys_dir_read(VFS_DIR dir, VFS_ENTRY *entry, int getstat) {
--- a/src/server/safs/cgi.c Sat Feb 04 10:06:25 2017 +0100 +++ b/src/server/safs/cgi.c Tue Feb 14 12:56:23 2017 +0100 @@ -39,7 +39,7 @@ #include "../util/util.h" #include "../util/pblock.h" #include "../../ucx/string.h" - +#include "../daemon/netsite.h" #include "../util/io.h" #include "cgiutils.h" @@ -126,7 +126,7 @@ n += r; } } - close(cgip.in[1]); + system_close(cgip.in[1]); cgip.in[1] = -1; // read from child @@ -238,13 +238,13 @@ // we need to close this unused pipe // otherwise stdin cannot reach EOF - close(p->in[1]); + system_close(p->in[1]); // execute program exit(execve(script.ptr, argv, envp)); } else { // parent - close(p->out[1]); + system_close(p->out[1]); p->out[1] = -1; } @@ -256,16 +256,16 @@ waitpid(p->pid, &status, 0); if(p->in[0] != -1) { - close(p->in[0]); + system_close(p->in[0]); } if(p->in[1] != -1) { - close(p->in[1]); + system_close(p->in[1]); } if(p->out[0] != -1) { - close(p->out[0]); + system_close(p->out[0]); } if(p->out[1] != -1) { - close(p->out[1]); + system_close(p->out[1]); } return 0; @@ -433,4 +433,4 @@ return 1; } } -} \ No newline at end of file +}
--- a/src/server/util/io.c Sat Feb 04 10:06:25 2017 +0100 +++ b/src/server/util/io.c Tue Feb 14 12:56:23 2017 +0100 @@ -64,6 +64,7 @@ #include "../daemon/vfs.h" #include "io.h" #include "pool.h" +#include "../daemon/netsite.h" #include "ucx/utils.h" IOStream native_io_funcs = { @@ -167,7 +168,7 @@ #endif void net_sys_close(SysStream *st) { - close(st->fd); + system_close(st->fd); } #elif defined(XP_WIN32) @@ -334,7 +335,7 @@ if(ret != 1) { st->error = SSL_get_error(st->ssl, ret); } - close(SSL_get_fd(st->ssl)); + system_close(SSL_get_fd(st->ssl)); } void net_ssl_finish(SSLStream *st) {
--- a/src/server/util/system.c Sat Feb 04 10:06:25 2017 +0100 +++ b/src/server/util/system.c Tue Feb 14 12:56:23 2017 +0100 @@ -328,6 +328,17 @@ return dir; } +int system_close(int fd) { + while(close(fd)) { + if(errno != EINTR) { + return -1; + } else { + log_ereport(LOG_VERBOSE, "close interrupted by signal"); // TODO: use debug log level + } + } + return 0; +} + NSAPI_PUBLIC int getThreadMallocKey(void) {