From 657f94698c7fc7d4f9838cbcf3b4b78e38939d5c Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 9 Oct 2023 04:22:51 -0500 Subject: [PATCH] Add some (void) typecasts to shut up busybody compiler "unused result" warnings. If watchdog writes fail, the system is about to reboot. No recovery possible. If the init task can't dup() stdin to create stdout and stderr (when we just closed the old ones, if any), your kernel has bigger problems. The fgets() in netstat are reading /proc data produced directly by the kernel. Each is discarding a line of input from /proc (because the kernel devs decided to put a pointless header line on the data to make it harder to machine parse the output, breaking multiple rules from half of The Art of Unix Programming), and in each case it's immediately followed by a loop reading the rest of the lines of input, which DOES respond to each result. Not only do we know the kernel is generating this for us, but if the first read somehow returns error but the second read produces good data... what did that error mean exactly? We _explicitly_ do not care about these return results. There's no useful "error handling" we could put in any of these places, so SHUT UP about it. --- toys/net/netstat.c | 6 +++--- toys/other/oneit.c | 4 ++-- toys/other/watchdog.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/toys/net/netstat.c b/toys/net/netstat.c index 9470e8e1..fe012c31 100644 --- a/toys/net/netstat.c +++ b/toys/net/netstat.c @@ -136,7 +136,7 @@ static void show_ip(char *fname) FILE *fp = xfopen(fname, "r"); // Skip header. - fgets(toybuf, sizeof(toybuf), fp); + (void)fgets(toybuf, sizeof(toybuf), fp); while (fgets(toybuf, sizeof(toybuf), fp)) { char lip[256], rip[256]; @@ -206,7 +206,7 @@ static void show_unix_sockets(void) FILE *fp = xfopen("/proc/net/unix", "r"); // Skip header. - fgets(toybuf, sizeof(toybuf), fp); + (void)fgets(toybuf, sizeof(toybuf), fp); while (fscanf(fp, "%*p: %lX %*X %lX %lX %lX %lu%m[^\n]", &refcount, &flags, &type, &state, &inode, &filename) >= 5) { @@ -287,7 +287,7 @@ static void display_routes(void) FILE *fp = xfopen("/proc/net/route", "r"); // Skip header. - fgets(toybuf, sizeof(toybuf), fp); + (void)fgets(toybuf, sizeof(toybuf), fp); printf("Kernel IP routing table\n" "Destination\tGateway \tGenmask \tFlags %s Iface\n", diff --git a/toys/other/oneit.c b/toys/other/oneit.c index c0b0c09d..45eb1fb5 100644 --- a/toys/other/oneit.c +++ b/toys/other/oneit.c @@ -90,9 +90,9 @@ void oneit_main(void) close(0); xopen_stdio(TT.c ? : "/dev/tty0", O_RDWR|O_CLOEXEC); close(1); - dup(0); + (void)dup(0); close(2); - dup(0); + (void)dup(0); if (FLAG(3)) { // Ensure next available filehandles are #3 and #4 diff --git a/toys/other/watchdog.c b/toys/other/watchdog.c index c3268a14..fb49b010 100644 --- a/toys/other/watchdog.c +++ b/toys/other/watchdog.c @@ -31,7 +31,7 @@ GLOBALS( static void safe_shutdown(int ignored) { - write(TT.fd, "V", 1); + (void)write(TT.fd, "V", 1); close(TT.fd); error_exit("safely exited watchdog."); } @@ -45,7 +45,7 @@ void watchdog_main(void) // Now that we've got the watchdog device open, kick it periodically. for (;;) { - write(TT.fd, "", 1); + (void)write(TT.fd, "", 1); sleep(TT.t); } } -- 2.39.2