I get this warning while compiling my program. daemon() is declared in unistd.h and its included. How to fix this or make it disappear?
error:
dcron.c: In function 'main':
dcron.c:35:4: warning: implicit declaration of function 'daemon' [-Wimplicit-function-declaration]
if (daemon(1, 0) != 0) {
^
part of program:
if (daemon(1, 0) != 0) {
fprintf(stderr, "error: failed to daemonize\n");
syslog(LOG_NOTICE, "error: failed to daemonize");
return 1;
}
setup: gcc4.8.2, glibc2.19 CFLAGS=-std=c99 -Wall -Wpedantic -Wextra
On Linux daemon()
is made available by #define
ing either
_XOPEN_SOURCE
_BSD_SOURCE
by doing
#define _XOPEN_SOURCE
or
#define _BSD_SOURCE
before #include
ing
#include <unistd.h>
or by adding -D _XOPEN_SOURCE
or -D _BSD_SOURCE
to the compilation command.