Clean-up compiler warnings about ignoring return values
authorJustin Pettit <jpettit@nicira.com>
Tue, 15 Dec 2009 07:08:10 +0000 (23:08 -0800)
committerJustin Pettit <jpettit@nicira.com>
Tue, 15 Dec 2009 08:14:32 +0000 (00:14 -0800)
Some systems complain when certain functions' return values are not
checked.  This commit fixes those warnings.

Creating ignore() function suggested by Ben Pfaff.

lib/daemon.c
lib/process.c
lib/signals.c
lib/util.c
lib/util.h
ofproto/executer.c
ovsdb/log.c
ovsdb/ovsdb-server.c
tests/test-vconn.c

index 0dcc66f..50cc335 100644 (file)
@@ -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();
index 0c7f424..12168f7 100644 (file)
@@ -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
index d8e51b6..eabbcc3 100644 (file)
@@ -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;
     }
 }
index 65cb360..e928480 100644 (file)
@@ -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) { }
index 9e7b88f..0101bf7 100644 (file)
@@ -127,6 +127,8 @@ int hexit_value(int c);
 
 char *dir_name(const char *file_name);
 
+void ignore(bool x UNUSED);
+
 #ifdef  __cplusplus
 }
 #endif
index cdbe5bd..f78ec33 100644 (file)
@@ -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
index 9c2e277..c8dac10 100644 (file)
@@ -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;
     }
index b86a504..d3a332e 100644 (file)
@@ -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;
index 1bcd8c6..34c2930 100644 (file)
@@ -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));