Darwin: Fix compilation warning regarding the deprecated daemon() function

Changes since v1: create a wrapper function named qemu_daemon() in oslib-posix.c
instead of putting the OS specific workaround in qemu-nbd.c directly.

On OSX >= 10.5, daemon() is deprecated, resulting in the following warning:
----8<----
qemu-nbd.c: In function ‘main’:
qemu-nbd.c:371: warning: ‘daemon’ is deprecated (declared at /usr/include/stdlib.h:289)
----8<----

The following trick, used in mDNSResponder, takes care of this warning:
http://www.opensource.apple.com/source/mDNSResponder/mDNSResponder-258.18/mDNSPosix/PosixDaemon.c

On OSX, it temporarily renames the daemon() function before including stdlib.h
and declares it manually as an extern function. This way, the compiler does not
see the declaration from stdlib.h and thus does not display the warning.

Signed-off-by: Alexandre Raymond <cerbere@gmail.com>
Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
This commit is contained in:
Alexandre Raymond 2011-06-06 23:34:10 -04:00 committed by Andreas Färber
parent 7fee199cf9
commit f97742d0d3
3 changed files with 18 additions and 1 deletions

View File

@ -88,6 +88,7 @@
# define QEMU_GNUC_PREREQ(maj, min) 0 # define QEMU_GNUC_PREREQ(maj, min) 0
#endif #endif
int qemu_daemon(int nochdir, int noclose);
void *qemu_memalign(size_t alignment, size_t size); void *qemu_memalign(size_t alignment, size_t size);
void *qemu_vmalloc(size_t size); void *qemu_vmalloc(size_t size);
void qemu_vfree(void *ptr); void qemu_vfree(void *ptr);

View File

@ -26,11 +26,27 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
/* The following block of code temporarily renames the daemon() function so the
compiler does not see the warning associated with it in stdlib.h on OSX */
#ifdef __APPLE__
#define daemon qemu_fake_daemon_function
#include <stdlib.h>
#undef daemon
extern int daemon(int, int);
#endif
#include "config-host.h" #include "config-host.h"
#include "sysemu.h" #include "sysemu.h"
#include "trace.h" #include "trace.h"
#include "qemu_socket.h" #include "qemu_socket.h"
int qemu_daemon(int nochdir, int noclose)
{
return daemon(nochdir, noclose);
}
void *qemu_oom_check(void *ptr) void *qemu_oom_check(void *ptr)
{ {
if (ptr == NULL) { if (ptr == NULL) {

View File

@ -359,7 +359,7 @@ int main(int argc, char **argv)
if (!verbose) { if (!verbose) {
/* detach client and server */ /* detach client and server */
if (daemon(0, 0) == -1) { if (qemu_daemon(0, 0) == -1) {
err(EXIT_FAILURE, "Failed to daemonize"); err(EXIT_FAILURE, "Failed to daemonize");
} }
} }