From: Justin Pettit Date: Tue, 15 Dec 2009 07:08:10 +0000 (-0800) Subject: Clean-up compiler warnings about ignoring return values X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18b9283b986ab65f64385981f4ba8e237f658c0d;p=openvswitch Clean-up compiler warnings about ignoring return values Some systems complain when certain functions' return values are not checked. This commit fixes those warnings. Creating ignore() function suggested by Ben Pfaff. --- diff --git a/lib/daemon.c b/lib/daemon.c index 0dcc66ff..50cc3352 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -232,11 +232,11 @@ daemonize(void) /* Child process. */ close(fds[0]); make_pidfile(); - write(fds[1], &c, 1); + ignore(write(fds[1], &c, 1)); close(fds[1]); setsid(); if (chdir_) { - chdir("/"); + ignore(chdir("/")); } time_postfork(); lockfile_postfork(); diff --git a/lib/process.c b/lib/process.c index 0c7f424f..12168f7e 100644 --- a/lib/process.c +++ b/lib/process.c @@ -289,7 +289,7 @@ process_exited(struct process *p) return true; } else { char buf[_POSIX_PIPE_BUF]; - read(fds[0], buf, sizeof buf); + ignore(read(fds[0], buf, sizeof buf)); return false; } } @@ -617,7 +617,7 @@ sigchld_handler(int signr UNUSED) } } } - write(fds[1], "", 1); + ignore(write(fds[1], "", 1)); } static bool diff --git a/lib/signals.c b/lib/signals.c index d8e51b64..eabbcc38 100644 --- a/lib/signals.c +++ b/lib/signals.c @@ -98,7 +98,7 @@ bool signal_poll(struct signal *s) { char buf[_POSIX_PIPE_BUF]; - read(fds[0], buf, sizeof buf); + ignore(read(fds[0], buf, sizeof buf)); if (signaled[s->signr]) { signaled[s->signr] = 0; return true; @@ -122,7 +122,7 @@ static void signal_handler(int signr) { if (signr >= 1 && signr < N_SIGNALS) { - write(fds[1], "", 1); + ignore(write(fds[1], "", 1)); signaled[signr] = true; } } diff --git a/lib/util.c b/lib/util.c index 65cb3608..e9284809 100644 --- a/lib/util.c +++ b/lib/util.c @@ -383,3 +383,9 @@ dir_name(const char *file_name) return xmemdup0(file_name, len); } } + +/* Pass a value to this function if it is marked with + * __attribute__((warn_unused_result)) and you genuinely want to ignore + * its return value. (Note that every scalar type can be implicitly + * converted to bool.) */ +void ignore(bool x UNUSED) { } diff --git a/lib/util.h b/lib/util.h index 9e7b88f0..0101bf7b 100644 --- a/lib/util.h +++ b/lib/util.h @@ -127,6 +127,8 @@ int hexit_value(int c); char *dir_name(const char *file_name); +void ignore(bool x UNUSED); + #ifdef __cplusplus } #endif diff --git a/ofproto/executer.c b/ofproto/executer.c index cdbe5bd9..f78ec338 100644 --- a/ofproto/executer.c +++ b/ofproto/executer.c @@ -434,7 +434,7 @@ executer_rconn_closing(struct executer *e, struct rconn *rconn) static void sigchld_handler(int signr UNUSED) { - write(signal_fds[1], "", 1); + ignore(write(signal_fds[1], "", 1)); } int diff --git a/ovsdb/log.c b/ovsdb/log.c index 9c2e277c..c8dac10c 100644 --- a/ovsdb/log.c +++ b/ovsdb/log.c @@ -337,7 +337,7 @@ ovsdb_log_write(struct ovsdb_log *file, struct json *json) /* Remove any partially written data, ignoring errors since there is * nothing further we can do. */ - ftruncate(fileno(file->stream), file->offset); + ignore(ftruncate(fileno(file->stream), file->offset)); goto error; } diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index b86a504b..d3a332e7 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -126,7 +126,7 @@ main(int argc, char *argv[]) unixctl_command_register("exit", ovsdb_server_exit, &exiting); if (do_chdir) { - chdir("/"); + ignore(chdir("/")); } exiting = false; diff --git a/tests/test-vconn.c b/tests/test-vconn.c index 1bcd8c62..34c2930a 100644 --- a/tests/test-vconn.c +++ b/tests/test-vconn.c @@ -224,7 +224,7 @@ test_send_hello(const char *type, const void *out, size_t out_size, fd = fpv_accept(&fpv); fpv_destroy(&fpv); - write(fd, out, out_size); + assert(write(fd, out, out_size) == out_size); assert(!set_nonblocking(fd));