[hamradio-commits] [dump1090] 373/373: merge changes from my debian package back into upstream for submission.

Matthew Ernisse mernisse-guest at moszumanska.debian.org
Thu Oct 23 14:58:38 UTC 2014


This is an automated email from the git hooks/post-receive script.

mernisse-guest pushed a commit to branch backport
in repository dump1090.

commit c7054fa656756ac9d7e6a7bcdd9d97d2d660a9da
Author: Matthew Ernisse <mernisse at ub3rgeek.net>
Date:   Tue Oct 21 21:07:39 2014 -0400

    merge changes from my debian package back into upstream for submission.
    
    * Makefile now honors CFLAGS and DESTDIR from debhelper
    * Have anetWrite() handle EAGAIN/EWOULDBLOCK errors.
    * Use anetWrite() for the HTTP thread so I can serve files larger than SO_SNDBUF from dump1090.
---
 Makefile     |  16 +++++++++++-----
 anet.c       |   7 +++++--
 coaa1090.obj | Bin 0 -> 33004 bytes
 net_io.c     |  28 ++++++++++++++++++++++------
 4 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/Makefile b/Makefile
index 6bfe9ee..2d6185c 100644
--- a/Makefile
+++ b/Makefile
@@ -5,16 +5,21 @@
 PROGNAME=dump1090
 
 ifdef PREFIX
-BINDIR=$(PREFIX)/bin
-SHAREDIR=$(PREFIX)/share/$(PROGNAME)
-EXTRACFLAGS=-DHTMLPATH=\"$(SHAREDIR)\"
+	BINDIR=$(PREFIX)/bin
+	SBINDIR=$(PREFIX)/sbin
+	SHAREDIR=$(PREFIX)/share/$(PROGNAME)
+	EXTRACFLAGS=-DHTMLPATH=\"$(SHAREDIR)\"
+else
+	BINDIR=$(DESTDIR)/usr/bin
+	SBINDIR=$(DESTDIR)/usr/sbin
+	SHAREDIR=$(DESTDIR)/usr/share/$(PROGNAME)
+	EXTRACFLAGS+=-DHTMLPATH=\"$(SHAREDIR)/public_html\"
 endif
 
-CFLAGS=-O2 -g -Wall -W `pkg-config --cflags librtlsdr`
+CFLAGS+=-O2 -g -Wall -W `pkg-config --cflags librtlsdr`
 LIBS=`pkg-config --libs librtlsdr` -lpthread -lm
 CC=gcc
 
-
 all: dump1090 view1090
 
 %.o: %.c
@@ -28,3 +33,4 @@ view1090: view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o
 
 clean:
 	rm -f *.o dump1090 view1090
+
diff --git a/anet.c b/anet.c
index 859c98c..9eba20f 100644
--- a/anet.c
+++ b/anet.c
@@ -221,14 +221,17 @@ int anetRead(int fd, char *buf, int count)
 }
 
 /* Like write(2) but make sure 'count' is read before to return
- * (unless error is encountered) */
+ * (unless error other than EAGAIN/EWOULDBLOCK is encountered) */
 int anetWrite(int fd, char *buf, int count)
 {
     int nwritten, totlen = 0;
     while(totlen != count) {
         nwritten = write(fd,buf,count-totlen);
         if (nwritten == 0) return totlen;
-        if (nwritten == -1) return -1;
+        if (nwritten == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
+		return -1;
+		continue;
+	}
         totlen += nwritten;
         buf += nwritten;
     }
diff --git a/coaa1090.obj b/coaa1090.obj
new file mode 100644
index 0000000..ea337ca
Binary files /dev/null and b/coaa1090.obj differ
diff --git a/net_io.c b/net_io.c
index f3a8397..83ce20b 100644
--- a/net_io.c
+++ b/net_io.c
@@ -686,6 +686,8 @@ char *aircraftsToJson(int *len) {
 //
 //=========================================================================
 //
+#define HTTP_OK "200 OK"
+#define HTTP_NOTFOUND "404 Not Found"
 #define MODES_CONTENT_TYPE_HTML "text/html;charset=utf-8"
 #define MODES_CONTENT_TYPE_CSS  "text/css;charset=utf-8"
 #define MODES_CONTENT_TYPE_JSON "application/json;charset=utf-8"
@@ -701,6 +703,7 @@ char *aircraftsToJson(int *len) {
 int handleHTTPRequest(struct client *c, char *p) {
     char hdr[512];
     int clen, hdrlen;
+    char *httpcode = HTTP_OK;
     int httpver, keepalive;
     char *url, *content;
     char ctype[48];
@@ -752,13 +755,17 @@ int handleHTTPRequest(struct client *c, char *p) {
         if (stat(getFile, &sbuf) != -1 && (fd = open(getFile, O_RDONLY)) != -1) {
             content = (char *) malloc(sbuf.st_size);
             if (read(fd, content, sbuf.st_size) == -1) {
-                snprintf(content, sbuf.st_size, "Error reading from file: %s", strerror(errno));
+                snprintf(content, sbuf.st_size, "Error reading from %s: %s",
+                    getFile, strerror(errno));
+            httpcode = HTTP_NOTFOUND;
             }
             clen = sbuf.st_size;
         } else {
             char buf[128];
-            clen = snprintf(buf,sizeof(buf),"Error opening HTML file: %s", strerror(errno));
+            clen = snprintf(buf, sizeof(buf), "Error opening %s: %s",
+                getFile, strerror(errno));
             content = strdup(buf);
+            httpcode = HTTP_NOTFOUND;
         }
         
         if (fd != -1) {
@@ -782,7 +789,7 @@ int handleHTTPRequest(struct client *c, char *p) {
 
     // Create the header and send the reply
     hdrlen = snprintf(hdr, sizeof(hdr),
-        "HTTP/1.1 200 OK\r\n"
+        "HTTP/1.1 %s\r\n"
         "Server: Dump1090\r\n"
         "Content-Type: %s\r\n"
         "Connection: %s\r\n"
@@ -790,6 +797,7 @@ int handleHTTPRequest(struct client *c, char *p) {
         "Cache-Control: no-cache, must-revalidate\r\n"
         "Expires: Sat, 26 Jul 1997 05:00:00 GMT\r\n"
         "\r\n",
+        httpstatus,
         ctype,
         keepalive ? "keep-alive" : "close",
         clen);
@@ -800,15 +808,23 @@ int handleHTTPRequest(struct client *c, char *p) {
 
     // Send header and content.
 #ifndef _WIN32
-    if ( (write(c->fd, hdr, hdrlen) != hdrlen) 
-      || (write(c->fd, content, clen) != clen) ) {
+    if (anetWrite(c->fd, hdr, hdrlen) != hdrlen) {
+        perror("HTTP short write of reply header");
+        free(content);
+        return 1;
+    }
+    if (anetWrite(c->fd, content, clen) != clen) {
+        perror("HTTP short write of content");
+        free(content);
+        return 1;
+    }
 #else
     if ( (send(c->fd, hdr, hdrlen, 0) != hdrlen) 
       || (send(c->fd, content, clen, 0) != clen) ) {
-#endif
         free(content);
         return 1;
     }
+#endif
     free(content);
     Modes.stat_http_requests++;
     return !keepalive;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/dump1090.git



More information about the pkg-hamradio-commits mailing list