[PATCH] remove compiler warning

0 views
Skip to first unread message

Victor Seva

unread,
Jan 30, 2026, 4:34:49 AM (5 days ago) Jan 30
to proso...@googlegroups.com
While building prosody I noticed this build warning

> x86_64-linux-gnu-gcc -std=c99 -fPIC -std=c99 -Wall -pedantic -Wextra -Wshadow -Wformat=2 -g -O2 -Werror=implicit-function-declaration -ffile-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -I/usr/include/lua5.4 -Wdate-time -D_FORTIFY_SOURCE=2 -c -o pposix.o pposix.c
> pposix.c: In function ‘lc_daemonize’:
> pposix.c:126:9: warning: ignoring return value of ‘freopen’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
> 126 | freopen("/dev/null", "r", stdin);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> pposix.c:127:9: warning: ignoring return value of ‘freopen’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
> 127 | freopen("/dev/null", "w", stdout);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> pposix.c:128:9: warning: ignoring return value of ‘freopen’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
> 128 | freopen("/dev/null", "w", stderr);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

That can be easily be removed with


diff -r 64cd905cb1de util-src/pposix.c
--- a/util-src/pposix.c Thu Jan 22 17:54:30 2026 +0100
+++ b/util-src/pposix.c Fri Jan 30 09:25:25 2026 +0100
@@ -123,9 +123,12 @@
        }

        /* Make sure accidental use of FDs 0, 1, 2 don't cause weirdness */
-       freopen("/dev/null", "r", stdin);
-       freopen("/dev/null", "w", stdout);
-       freopen("/dev/null", "w", stderr);
+       if(!freopen("/dev/null", "r", stdin))
+               fprintf(stderr, "Failed to redirect stdin to /dev/null");
+       if(!freopen("/dev/null", "w", stdout))
+               fprintf(stderr, "Failed to redirect stdout to /dev/null");
+       if(!freopen("/dev/null", "w", stderr))
+               fprintf(stderr, "Failed to redirect stderr to /dev/null");

        /* Final fork, use it wisely */
        if(fork()) {

Reply all
Reply to author
Forward
0 new messages