diff options
author | Alex Dowad <alexinbeijing@gmail.com> | 2014-04-07 12:02:29 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2014-04-25 10:17:03 +0300 |
commit | 827c2c3823ba1923d3fb01e191997f6b9edd21a5 (patch) | |
tree | d31b88c51a37de478973dc7981588d0c916ec20f | |
parent | 751bbc05d4dd72bdbe7e57f6724de865cd7c0bd9 (diff) | |
download | squark-827c2c3823ba1923d3fb01e191997f6b9edd21a5.tar.bz2 squark-827c2c3823ba1923d3fb01e191997f6b9edd21a5.tar.xz |
all: report errors if calls to write() fail
This also quiets compiler warnings for "ignored return values".
-rw-r--r-- | src/squark-auth-ip.c | 5 | ||||
-rw-r--r-- | src/squark-auth-snmp.c | 4 | ||||
-rw-r--r-- | src/squark-filter.c | 11 |
3 files changed, 15 insertions, 5 deletions
diff --git a/src/squark-auth-ip.c b/src/squark-auth-ip.c index 677c008..20c7d35 100644 --- a/src/squark-auth-ip.c +++ b/src/squark-auth-ip.c @@ -13,6 +13,8 @@ #include <time.h> #include <stdio.h> #include <unistd.h> +#include <errno.h> +#include <string.h> #include "config.h" #include "blob.h" @@ -65,7 +67,8 @@ static void handle_line(blob_t line) } b = blob_pushed(BLOB_BUF(reply), b); - write(STDOUT_FILENO, b.ptr, b.len); + if(write(STDOUT_FILENO, b.ptr, b.len) < 0) + report_error("Error occurred while writing to stdout: %s", strerror(errno)); } static void read_input(void) diff --git a/src/squark-auth-snmp.c b/src/squark-auth-snmp.c index 05832d4..e9fabbe 100644 --- a/src/squark-auth-snmp.c +++ b/src/squark-auth-snmp.c @@ -21,6 +21,7 @@ #include <stdio.h> #include <string.h> #include <unistd.h> +#include <errno.h> #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> @@ -620,7 +621,8 @@ static void auth_completed(struct auth_context *auth) report_private_message(REPORT_WARNING, "%s failed: %s", addr_print(&auth->addr), auth->status_msg); } b = blob_pushed(BLOB_BUF(tmp), b); - write(STDOUT_FILENO, b.ptr, b.len); + if(write(STDOUT_FILENO, b.ptr, b.len) < 0) + report_error("Error occurred while writing to stdout: %s", strerror(errno)); auth_free(auth); num_queries--; diff --git a/src/squark-filter.c b/src/squark-filter.c index 19c3583..9eed4a7 100644 --- a/src/squark-filter.c +++ b/src/squark-filter.c @@ -15,6 +15,7 @@ #include <ctype.h> #include <string.h> #include <unistd.h> +#include <errno.h> #include <cmph.h> @@ -330,7 +331,8 @@ static void send_ok(blob_t tag, blob_t categ, int override) blob_push(&b, lf); b = blob_pushed(BLOB_BUF(buffer), b); - write(STDOUT_FILENO, b.ptr, b.len); + if(write(STDOUT_FILENO, b.ptr, b.len) < 0) + report_error("Error occurred while writing to stdout: %s\n", strerror(errno)); } static void send_redirect(blob_t redirect_page, blob_t tag, blob_t url, blob_t categ, blob_t username) @@ -353,7 +355,8 @@ static void send_redirect(blob_t redirect_page, blob_t tag, blob_t url, blob_t c blob_push(&b, lf); b = blob_pushed(BLOB_BUF(buffer), b); - write(STDOUT_FILENO, b.ptr, b.len); + if(write(STDOUT_FILENO, b.ptr, b.len) < 0) + report_error("Error occurred while writing to stdout: %s\n", strerror(errno)); } static void read_input(struct sqdb *db) @@ -372,8 +375,10 @@ static void read_input(struct sqdb *db) left = BLOB_BUF(buffer); r = read(STDIN_FILENO, left.ptr, left.len); - if (r < 0) + if (r < 0) { + report_error("Error occurred while reading from stdin: %s\n", strerror(errno)); return; + } if (r == 0) { running = 0; return; |