Skip to contentSkip to conversation

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

RFC PATCH Superseded Alexandre Raymond 4 participants 5 messages Jun 2, 2011 – Jun 4, 2011

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Darwin: Fix compilation warning regarding the deprecated daemon() function

On OSX > 10.5, daemon() is deprecated, resulting int he 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

---
 qemu-nbd.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
qemu-nbd.c +9 -0
index e858033..10b0791 100644
@@ -16,6 +16,10 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#if __APPLE__
+#define daemon fake_daemon_function
+#endif
+
 #include <qemu-common.h>
 #include "block_int.h"
 #include "nbd.h"
@@ -32,6 +36,11 @@
 #include <signal.h>
 #include <libgen.h>
 
+#if __APPLE__
+#undef daemon
+extern int daemon(int, int);
+#endif
+
 #define SOCKET_PATH    "/var/lock/qemu-nbd-%s"
 
 #define NBD_BUFFER_SIZE (1024*1024)
Signature · 1 line
1.7.5
#1 lore raw

Am 02.06.2011 um 04:45 schrieb Alexandre Raymond:

Quoted 3 lines

On OSX > 10.5, daemon() is deprecated, resulting int he following warning:

= 10.5

http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/daemon.3.html

Quoted 7 lines

----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

Even if apparently applied by Apple themselves, I consider it a bad hack for curing symptoms.

http://developer.apple.com/library/mac/technotes/tn2083/_index.html#//apple_ref/doc/uid/DTS10003794-CH1-SUBSECTION64

Possibly a better fix would be to supply a .plist file for use with launchd/launchctl and to #ifndef __APPLE__ the daemon() functionality?

Further comments inline.

Quoted 14 lines

---
qemu-nbd.c | 9 +++++++++

1 files changed, 9 insertions(+), 0 deletions(-)
qemu-nbd.c +0 -0
index e858033..10b0791 100644
@@ -16,6 +16,10 @@
 *  along with this program; if not, see <http://www.gnu.org/ 

licenses/>.
*/

Quoted 1 line

+#if __APPLE__

#ifdef __APPLE__

qemu-nbd.c line 39

Quoted 11 lines
qemu-nbd.c +3 -0
+#define daemon fake_daemon_function
+#endif
+

#include <qemu-common.h>
#include "block_int.h"
#include "nbd.h"

qemu-nbd.c +1 -0
@@ -32,6 +36,11 @@
 #include <signal.h>
 #include <libgen.h>
 
+#if __APPLE__

dito

qemu-nbd.c line 41

Quoted 2 lines
qemu-nbd.c +2 -0
+#undef daemon
+extern int daemon(int, int);

Blue Swirl has declared war on "extern"... ;)

Quoted 7 lines
qemu-nbd.c +2 -0
+#endif
+
 #define SOCKET_PATH    "/var/lock/qemu-nbd-%s"
 
 #define NBD_BUFFER_SIZE (1024*1024)
Signature · 1 line
1.7.5

Andreas

#2 lore raw

Hi Andreas,

Quoted 14 lines · Andreas Färber

Am 02.06.2011 um 04:45 schrieb Alexandre Raymond:

Quoted 3 lines

On OSX > 10.5, daemon() is deprecated, resulting int he following warning:

= 10.5

http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/daemon.3.html

Quoted 6 lines

----8<----
qemu-nbd.c: In function ‘main’:
qemu-nbd.c:371: warning: ‘daemon’ is deprecated (declared at /usr/include/stdlib.h:289)
----8<----

Quoted 8 lines
Quoted 3 lines

The following trick, used in mDNSResponder, takes care of this warning:

http://www.opensource.apple.com/source/mDNSResponder/mDNSResponder-258.18/mDNSPosix/PosixDaemon.c

Even if apparently applied by Apple themselves, I consider it a bad hack for curing symptoms.

http://developer.apple.com/library/mac/technotes/tn2083/_index.html#//apple_ref/doc/uid/DTS10003794-CH1-SUBSECTION64

I agree that this is a nasty hack. It's really up to you guys. I can try to modify this patch to use launchd instead.

Alexandre

#4 lore raw
In reply to Alexandre Raymond
Quoted 30 lines · Alexandre Raymond

On OSX > 10.5, daemon() is deprecated, resulting int he 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

---
 qemu-nbd.c |    9 +++++++++

 1 files changed, 9 insertions(+), 0 deletions(-)
qemu-nbd.c +4 -0
index e858033..10b0791 100644
@@ -16,6 +16,10 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#if __APPLE__
+#define daemon fake_daemon_function
+#endif
+
  #include <qemu-common.h>
  #include "block_int.h"
  #include "nbd.h"

qemu-nbd.c line 43

Quoted 8 lines
qemu-nbd.c +5 -0
@@ -32,6 +36,11 @@
  #include <signal.h>
  #include <libgen.h>
 
+#if __APPLE__
+#undef daemon
+extern int daemon(int, int);
+#endif
+

Please introduce a wrapper instead, for example in oslib-posix.c. Then the #ifdeffery is not spread to generic files.