diff mbox

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

Message ID 1307417650-12955-1-git-send-email-cerbere@gmail.com
State New
Headers show

Commit Message

Alexandre Raymond June 7, 2011, 3:34 a.m. UTC
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>
---
 osdep.h       |    1 +
 oslib-posix.c |   15 +++++++++++++++
 qemu-nbd.c    |    2 +-
 3 files changed, 17 insertions(+), 1 deletions(-)

Comments

Andreas Färber June 9, 2011, 6:47 p.m. UTC | #1
Am 07.06.2011 um 05:34 schrieb Alexandre Raymond:

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

Acked-by: Andreas Färber <andreas.faerber@web.de>

Blue, do you want this to go through the cocoa queue (please ack then)  
or do you want to apply this directly?

I have two further issues on my radar, 1) Alexandre's handleEvent:  
warning and 2) the big sigfd issue, and would then send a pull request.

Andreas

> ---
> osdep.h       |    1 +
> oslib-posix.c |   15 +++++++++++++++
> qemu-nbd.c    |    2 +-
> 3 files changed, 17 insertions(+), 1 deletions(-)
>
> diff --git a/osdep.h b/osdep.h
> index 970d767..6eb9a49 100644
> --- a/osdep.h
> +++ b/osdep.h
> @@ -88,6 +88,7 @@
> # define QEMU_GNUC_PREREQ(maj, min) 0
> #endif
>
> +int qemu_daemon(int nochdir, int noclose);
> void *qemu_memalign(size_t alignment, size_t size);
> void *qemu_vmalloc(size_t size);
> void qemu_vfree(void *ptr);
> diff --git a/oslib-posix.c b/oslib-posix.c
> index 7bc5f7c..5392e25 100644
> --- a/oslib-posix.c
> +++ b/oslib-posix.c
> @@ -26,11 +26,26 @@
>  * 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 "sysemu.h"
> #include "trace.h"
> #include "qemu_socket.h"
>
> +
> +
> +int qemu_daemon(int nochdir, int noclose) {
> +    return daemon(nochdir, noclose);
> +}
> +
> void *qemu_oom_check(void *ptr)
> {
>     if (ptr == NULL) {
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index e858033..e65cc6c 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -359,7 +359,7 @@ int main(int argc, char **argv)
>
>         if (!verbose) {
>             /* detach client and server */
> -            if (daemon(0, 0) == -1) {
> +            if (qemu_daemon(0, 0) == -1) {
>                 err(EXIT_FAILURE, "Failed to daemonize");
>             }
>         }
> -- 
> 1.7.5
>
>
Andreas Färber June 9, 2011, 7:30 p.m. UTC | #2
Am 09.06.2011 um 20:47 schrieb Andreas Färber:

> Am 07.06.2011 um 05:34 schrieb Alexandre Raymond:
>
>> 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>
>
> Acked-by: Andreas Färber <andreas.faerber@web.de>
>
> Blue, do you want this to go through the cocoa queue (please ack  
> then) or do you want to apply this directly?
>
> I have two further issues on my radar, 1) Alexandre's handleEvent:  
> warning and 2) the big sigfd issue, and would then send a pull  
> request.

>> diff --git a/oslib-posix.c b/oslib-posix.c
>> index 7bc5f7c..5392e25 100644
>> --- a/oslib-posix.c
>> +++ b/oslib-posix.c
>> @@ -26,11 +26,26 @@
>> * THE SOFTWARE.
>> */
>>
>> +/* The following block of code temporarily renames the daemon()  
>> function so the

This line had a trailing whitespace btw.

Andreas
Blue Swirl June 13, 2011, 8:20 p.m. UTC | #3
On Thu, Jun 9, 2011 at 9:47 PM, Andreas Färber <andreas.faerber@web.de> wrote:
> Am 07.06.2011 um 05:34 schrieb Alexandre Raymond:
>
>> 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>
>
> Acked-by: Andreas Färber <andreas.faerber@web.de>
>
> Blue, do you want this to go through the cocoa queue (please ack then) or do
> you want to apply this directly?

I have a minor style comment, but otherwise this could go via cocoa queue.

> I have two further issues on my radar, 1) Alexandre's handleEvent: warning
> and 2) the big sigfd issue, and would then send a pull request.
>
> Andreas
>
>> ---
>> osdep.h       |    1 +
>> oslib-posix.c |   15 +++++++++++++++
>> qemu-nbd.c    |    2 +-
>> 3 files changed, 17 insertions(+), 1 deletions(-)
>>
>> diff --git a/osdep.h b/osdep.h
>> index 970d767..6eb9a49 100644
>> --- a/osdep.h
>> +++ b/osdep.h
>> @@ -88,6 +88,7 @@
>> # define QEMU_GNUC_PREREQ(maj, min) 0
>> #endif
>>
>> +int qemu_daemon(int nochdir, int noclose);
>> void *qemu_memalign(size_t alignment, size_t size);
>> void *qemu_vmalloc(size_t size);
>> void qemu_vfree(void *ptr);
>> diff --git a/oslib-posix.c b/oslib-posix.c
>> index 7bc5f7c..5392e25 100644
>> --- a/oslib-posix.c
>> +++ b/oslib-posix.c
>> @@ -26,11 +26,26 @@
>>  * 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 "sysemu.h"
>> #include "trace.h"
>> #include "qemu_socket.h"
>>
>> +
>> +
>> +int qemu_daemon(int nochdir, int noclose) {

Here the brace should be on a new line. This is C, not Java.

>> +    return daemon(nochdir, noclose);
>> +}
>> +
>> void *qemu_oom_check(void *ptr)
>> {
>>    if (ptr == NULL) {
>> diff --git a/qemu-nbd.c b/qemu-nbd.c
>> index e858033..e65cc6c 100644
>> --- a/qemu-nbd.c
>> +++ b/qemu-nbd.c
>> @@ -359,7 +359,7 @@ int main(int argc, char **argv)
>>
>>        if (!verbose) {
>>            /* detach client and server */
>> -            if (daemon(0, 0) == -1) {
>> +            if (qemu_daemon(0, 0) == -1) {
>>                err(EXIT_FAILURE, "Failed to daemonize");
>>            }
>>        }
>> --
>> 1.7.5
>>
>>
>
>
Andreas Färber June 14, 2011, 1:24 a.m. UTC | #4
Am 13.06.2011 um 22:20 schrieb Blue Swirl:

> On Thu, Jun 9, 2011 at 9:47 PM, Andreas Färber  
> <andreas.faerber@web.de> wrote:
>> Am 07.06.2011 um 05:34 schrieb Alexandre Raymond:
>>
>>> 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>
>>
>> Acked-by: Andreas Färber <andreas.faerber@web.de>
>>
>> Blue, do you want this to go through the cocoa queue (please ack  
>> then) or do
>> you want to apply this directly?
>
> I have a minor style comment, but otherwise this could go via cocoa  
> queue.
>
>> I have two further issues on my radar, 1) Alexandre's handleEvent:  
>> warning
>> and 2) the big sigfd issue, and would then send a pull request.
>>
>> Andreas
>>
>>> diff --git a/oslib-posix.c b/oslib-posix.c
>>> index 7bc5f7c..5392e25 100644

>>> +int qemu_daemon(int nochdir, int noclose) {
>
> Here the brace should be on a new line.

Fixed.

Andreas
diff mbox

Patch

diff --git a/osdep.h b/osdep.h
index 970d767..6eb9a49 100644
--- a/osdep.h
+++ b/osdep.h
@@ -88,6 +88,7 @@ 
 # define QEMU_GNUC_PREREQ(maj, min) 0
 #endif
 
+int qemu_daemon(int nochdir, int noclose);
 void *qemu_memalign(size_t alignment, size_t size);
 void *qemu_vmalloc(size_t size);
 void qemu_vfree(void *ptr);
diff --git a/oslib-posix.c b/oslib-posix.c
index 7bc5f7c..5392e25 100644
--- a/oslib-posix.c
+++ b/oslib-posix.c
@@ -26,11 +26,26 @@ 
  * 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 "sysemu.h"
 #include "trace.h"
 #include "qemu_socket.h"
 
+
+
+int qemu_daemon(int nochdir, int noclose) {
+    return daemon(nochdir, noclose);
+}
+
 void *qemu_oom_check(void *ptr)
 {
     if (ptr == NULL) {
diff --git a/qemu-nbd.c b/qemu-nbd.c
index e858033..e65cc6c 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -359,7 +359,7 @@  int main(int argc, char **argv)
 
         if (!verbose) {
             /* detach client and server */
-            if (daemon(0, 0) == -1) {
+            if (qemu_daemon(0, 0) == -1) {
                 err(EXIT_FAILURE, "Failed to daemonize");
             }
         }