Glibc (at least) provides the warn_unused_result attribute on write,
(if optimizing and _FORTIFY_SOURCE is defined). So we explicitly
ignore the return value in our signal handler, where we couldn't do
anything anyway.
Compile with:
make CFLAGS="-O -D_FORTIFY_SOURCE"
before this commit to see the warning.
static void
handle_sigint (unused (int sig))
{
+ ssize_t ignored;
static char msg[] = "Stopping... \n";
- write(2, msg, sizeof(msg)-1);
+
+ ignored = write(2, msg, sizeof(msg)-1);
interrupted = 1;
}
static void
handle_sigint (unused (int sig))
{
+ ssize_t ignored;
+
static char msg[] = "Stopping... \n";
- write(2, msg, sizeof(msg)-1);
+ ignored = write(2, msg, sizeof(msg)-1);
interrupted = 1;
}