fixed NetBSD build and an uninitialized struct member

Mon, 02 Nov 2015 11:13:38 +0000

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 02 Nov 2015 11:13:38 +0000
changeset 111
c93be34fde76
parent 109
8a0a7754f123
child 112
b962d83124bc

fixed NetBSD build and an uninitialized struct member

src/server/daemon/event_bsd.c file | annotate | diff | comparison | revisions
src/server/daemon/httplistener.c file | annotate | diff | comparison | revisions
src/server/daemon/ldap_auth.c file | annotate | diff | comparison | revisions
src/server/util/io.c file | annotate | diff | comparison | revisions
src/server/util/io.h file | annotate | diff | comparison | revisions
--- a/src/server/daemon/event_bsd.c	Sat Oct 31 20:10:21 2015 +0100
+++ b/src/server/daemon/event_bsd.c	Mon Nov 02 11:13:38 2015 +0000
@@ -101,7 +101,7 @@
         }
         
         for(int i=0;i<nev;i++) {
-            event_t *event = events[i].udata;
+            event_t *event = (event_t*)events[i].udata;
             if(event->fn) {
                 if(event->fn(ev, event)) {
                     // TODO: reassociate?               
--- a/src/server/daemon/httplistener.c	Sat Oct 31 20:10:21 2015 +0100
+++ b/src/server/daemon/httplistener.c	Mon Nov 02 11:13:38 2015 +0000
@@ -79,7 +79,7 @@
         return http_listener_new(conf);
     }
     
-    HttpListener* newls = malloc(sizeof(HttpListener));
+    HttpListener* newls = calloc(1, sizeof(HttpListener));
     if(newls == NULL) {
         // TODO: error
     }
@@ -329,6 +329,7 @@
                 conn->close = connection_ssl_close;
             }
         } else {
+            conn->ssl = NULL;
             conn->read = connection_read;
             conn->write = connection_write;
             conn->close = connection_close;
--- a/src/server/daemon/ldap_auth.c	Sat Oct 31 20:10:21 2015 +0100
+++ b/src/server/daemon/ldap_auth.c	Mon Nov 02 11:13:38 2015 +0000
@@ -33,6 +33,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/time.h>
 
 #include <ucx/utils.h>
 
--- a/src/server/util/io.c	Sat Oct 31 20:10:21 2015 +0100
+++ b/src/server/util/io.c	Mon Nov 02 11:13:38 2015 +0000
@@ -34,9 +34,16 @@
 #include <stdlib.h>
 #include <sys/uio.h>
 #include <sys/uio.h>
+
 #ifndef BSD
 #include <sys/sendfile.h>
+#else
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#define WS_NO_SENDFILE
+#define net_stream_sendfile net_fallback_sendfile
 #endif
+#endif
+
 #include <limits.h> /* asprintf */
 
 #include "../daemon/vfs.h"
@@ -145,6 +152,7 @@
     return r;
 }
 
+#ifndef WS_NO_SENDFILE
 ssize_t net_stream_sendfile(NetIOStream *st, sendfiledata *sfd) {  
     ssize_t ret = 0;
     off_t fileoffset = sfd->offset;
@@ -191,6 +199,7 @@
     
     return ret;
 }
+#endif
 
 void net_stream_close(NetIOStream *st) {
     close(st->fd);
@@ -285,66 +294,7 @@
     } else {
         // stream/file does not support sendfile
         // do regular copy
-        char *buf = malloc(4096);
-        if(!buf) {
-            // TODO: out of memory error
-            return IO_ERROR;
-        }
-        char *header = (char*)sfd->header;
-        int hlen = sfd->hlen;
-        char *trailer = (char*)sfd->trailer;
-        int tlen = sfd->tlen;
-        if(header == NULL) {
-            hlen = 0;
-        }
-        if(trailer == NULL) {
-            tlen = 0;
-        }
-        
-        ssize_t r;
-        while(hlen > 0) {
-            r = out->st.write(fd, header, hlen);
-            header += r;
-            hlen -= r;
-            if(r <= 0) {
-                free(buf);
-                return IO_ERROR;
-            }
-        }
-        
-        if(system_lseek(sfd->fd, sfd->offset, SEEK_SET) == -1) {
-            free(buf);
-            return IO_ERROR;
-        }
-        
-        size_t length = sfd->len;
-        while(length > 0) {
-            if((r = system_fread(sfd->fd, buf, 4096)) <= 0) {
-                break;
-            }
-            char *write_buf = buf;
-            while(r > 0) {
-                ssize_t w = out->st.write(fd, write_buf, r);
-                r -= w;
-                length -= w;
-                write_buf += w;
-            }
-        }
-        free(buf);
-        if(length > 0) {
-            return IO_ERROR;
-        }
-        
-        while(tlen > 0) {
-            r = out->st.write(fd, trailer, tlen);
-            trailer += r;
-            tlen -= r;
-            if(r <= 0) {
-                return IO_ERROR;
-            }
-        }
-        
-        return sfd->hlen + sfd->len + sfd->tlen;
+        return net_fallback_sendfile(fd, sfd);
     }
     return IO_ERROR;
 }
@@ -363,6 +313,72 @@
 }
 
 
+ssize_t net_fallback_sendfile(NetIOStream *st, sendfiledata *sfd) { 
+    SYS_NETFD fd = st;
+    
+    char *buf = malloc(4096);
+    if(!buf) {
+        // TODO: out of memory error
+        return IO_ERROR;
+    }
+    char *header = (char*)sfd->header;
+    int hlen = sfd->hlen;
+    char *trailer = (char*)sfd->trailer;
+    int tlen = sfd->tlen;
+    if(header == NULL) {
+        hlen = 0;
+    }
+    if(trailer == NULL) {
+        tlen = 0;
+    }
+
+    ssize_t r;
+    while(hlen > 0) {
+        r = st->st.write(fd, header, hlen);
+        header += r;
+        hlen -= r;
+        if(r <= 0) {
+            free(buf);
+            return IO_ERROR;
+        }
+    }
+
+    if(system_lseek(sfd->fd, sfd->offset, SEEK_SET) == -1) {
+        free(buf);
+        return IO_ERROR;
+    }
+
+    size_t length = sfd->len;
+    while(length > 0) {
+        if((r = system_fread(sfd->fd, buf, 4096)) <= 0) {
+            break;
+        }
+        char *write_buf = buf;
+        while(r > 0) {
+            ssize_t w = st->st.write(fd, write_buf, r);
+            r -= w;
+            length -= w;
+            write_buf += w;
+        }
+    }
+    free(buf);
+    if(length > 0) {
+        return IO_ERROR;
+    }
+
+    while(tlen > 0) {
+        r = st->st.write(fd, trailer, tlen);
+        trailer += r;
+        tlen -= r;
+        if(r <= 0) {
+            return IO_ERROR;
+        }
+    }
+
+    return sfd->hlen + sfd->len + sfd->tlen;
+}
+
+
 /* iovec buffer */
 iovec_buf_t *iovec_buf_create(pool_handle_t *pool) {
     iovec_buf_t *buf = pool_malloc(pool, sizeof(iovec_buf_t));
--- a/src/server/util/io.h	Sat Oct 31 20:10:21 2015 +0100
+++ b/src/server/util/io.h	Mon Nov 02 11:13:38 2015 +0000
@@ -83,6 +83,8 @@
 void    net_close(SYS_NETFD fd);
 void    net_finish(SYS_NETFD fd);
 
+ssize_t net_fallback_sendfile(NetIOStream *st, sendfiledata *sfd);
+
 /* iovec buffer */
 typedef struct iovec_buf{
     struct iovec   *iov;

mercurial