qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] osdep: Fix runtime failure on older Linux kernels
@ 2009-12-18  9:45 Andre Przywara
  2009-12-18 10:42 ` [Qemu-devel] " Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Andre Przywara @ 2009-12-18  9:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andre Przywara

If QEMU finds newer kernel header files on compilation time, it will use
advertised features like pipe2 or SOCK_CLOEXEC by just doing a compile test.
If later the executables are executed on an older kernel (<2.6.27,
like Xen Dom0 2.6.18), then QEMU will fail on opening sockets and creating
pipes and returns the rather unspecific "qemu_init_main_loop failed".
This patch fixes this by checking the return values of these calls
for EINVAL and ENOSYS and falling back to the older versions automatically.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
---
 osdep.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/osdep.c b/osdep.c
index 7509c5b..9949606 100644
--- a/osdep.c
+++ b/osdep.c
@@ -262,13 +262,15 @@ int qemu_pipe(int pipefd[2])
 
 #ifdef CONFIG_PIPE2
     ret = pipe2(pipefd, O_CLOEXEC);
-#else
+    if (ret != -1 || errno != ENOSYS) {
+        return ret;
+    }
+#endif
     ret = pipe(pipefd);
     if (ret == 0) {
         qemu_set_cloexec(pipefd[0]);
         qemu_set_cloexec(pipefd[1]);
     }
-#endif
 
     return ret;
 }
@@ -283,12 +285,14 @@ int qemu_socket(int domain, int type, int protocol)
 
 #ifdef SOCK_CLOEXEC
     ret = socket(domain, type | SOCK_CLOEXEC, protocol);
-#else
+    if (ret != -1 || errno != EINVAL) {
+        return ret;
+    }
+#endif
     ret = socket(domain, type, protocol);
     if (ret >= 0) {
         qemu_set_cloexec(ret);
     }
-#endif
 
     return ret;
 }
@@ -302,12 +306,14 @@ int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
 
 #ifdef CONFIG_ACCEPT4
     ret = accept4(s, addr, addrlen, SOCK_CLOEXEC);
-#else
+    if (ret != -1 || errno != EINVAL) {
+        return ret;
+    }
+#endif
     ret = accept(s, addr, addrlen);
     if (ret >= 0) {
         qemu_set_cloexec(ret);
     }
-#endif
 
     return ret;
 }
-- 
1.6.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] Re: [PATCH] osdep: Fix runtime failure on older Linux kernels
  2009-12-18  9:45 [Qemu-devel] [PATCH] osdep: Fix runtime failure on older Linux kernels Andre Przywara
@ 2009-12-18 10:42 ` Paolo Bonzini
  2009-12-18 11:32 ` [Qemu-devel] " Kevin Wolf
  2009-12-18 12:37 ` [Qemu-devel] [PATCH v2] " Andre Przywara
  2 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2009-12-18 10:42 UTC (permalink / raw)
  To: Andre Przywara; +Cc: qemu-devel

On 12/18/2009 10:45 AM, Andre Przywara wrote:
> If QEMU finds newer kernel header files on compilation time, it will use
> advertised features like pipe2 or SOCK_CLOEXEC by just doing a compile test.
> If later the executables are executed on an older kernel (<2.6.27,
> like Xen Dom0 2.6.18), then QEMU will fail on opening sockets and creating
> pipes and returns the rather unspecific "qemu_init_main_loop failed".
> This patch fixes this by checking the return values of these calls
> for EINVAL and ENOSYS and falling back to the older versions automatically.

Agreed, most other apps that use *_CLOEXEC do this (including glibc 
itself and gnulib; the notable exception is APR and there were quite 
some flames about this).

Paolo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] osdep: Fix runtime failure on older Linux kernels
  2009-12-18  9:45 [Qemu-devel] [PATCH] osdep: Fix runtime failure on older Linux kernels Andre Przywara
  2009-12-18 10:42 ` [Qemu-devel] " Paolo Bonzini
@ 2009-12-18 11:32 ` Kevin Wolf
  2009-12-18 12:33   ` Andre Przywara
  2009-12-18 12:37 ` [Qemu-devel] [PATCH v2] " Andre Przywara
  2 siblings, 1 reply; 6+ messages in thread
From: Kevin Wolf @ 2009-12-18 11:32 UTC (permalink / raw)
  To: Andre Przywara; +Cc: qemu-devel

Am 18.12.2009 10:45, schrieb Andre Przywara:
> If QEMU finds newer kernel header files on compilation time, it will use
> advertised features like pipe2 or SOCK_CLOEXEC by just doing a compile test.
> If later the executables are executed on an older kernel (<2.6.27,
> like Xen Dom0 2.6.18), then QEMU will fail on opening sockets and creating
> pipes and returns the rather unspecific "qemu_init_main_loop failed".
> This patch fixes this by checking the return values of these calls
> for EINVAL and ENOSYS and falling back to the older versions automatically.
> 
> Signed-off-by: Andre Przywara <andre.przywara@amd.com>
> ---
>  osdep.c |   18 ++++++++++++------
>  1 files changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/osdep.c b/osdep.c
> index 7509c5b..9949606 100644
> --- a/osdep.c
> +++ b/osdep.c
> @@ -262,13 +262,15 @@ int qemu_pipe(int pipefd[2])
>  
>  #ifdef CONFIG_PIPE2
>      ret = pipe2(pipefd, O_CLOEXEC);
> -#else
> +    if (ret != -1 || errno != ENOSYS) {
> +        return ret;
> +    }
> +#endif
>      ret = pipe(pipefd);
>      if (ret == 0) {
>          qemu_set_cloexec(pipefd[0]);
>          qemu_set_cloexec(pipefd[1]);
>      }
> -#endif
>  
>      return ret;
>  }
> @@ -283,12 +285,14 @@ int qemu_socket(int domain, int type, int protocol)
>  
>  #ifdef SOCK_CLOEXEC
>      ret = socket(domain, type | SOCK_CLOEXEC, protocol);
> -#else
> +    if (ret != -1 || errno != EINVAL) {
> +        return ret;
> +    }
> +#endif
>      ret = socket(domain, type, protocol);
>      if (ret >= 0) {
>          qemu_set_cloexec(ret);
>      }
> -#endif
>  
>      return ret;
>  }
> @@ -302,12 +306,14 @@ int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
>  
>  #ifdef CONFIG_ACCEPT4
>      ret = accept4(s, addr, addrlen, SOCK_CLOEXEC);
> -#else
> +    if (ret != -1 || errno != EINVAL) {

Shouldn't this be an ENOSYS?

Kevin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] osdep: Fix runtime failure on older Linux kernels
  2009-12-18 11:32 ` [Qemu-devel] " Kevin Wolf
@ 2009-12-18 12:33   ` Andre Przywara
  0 siblings, 0 replies; 6+ messages in thread
From: Andre Przywara @ 2009-12-18 12:33 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel

Kevin Wolf wrote:
 >>....
>> @@ -302,12 +306,14 @@ int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
>>  
>>  #ifdef CONFIG_ACCEPT4
>>      ret = accept4(s, addr, addrlen, SOCK_CLOEXEC);
>> -#else
>> +    if (ret != -1 || errno != EINVAL) {
> 
> Shouldn't this be an ENOSYS?
Oh, right you are. This was the untested part, because my glibc didn't 
have accept4. I only saw the SOCK_CLOEXEC name on this...
Fixed patch follows...

Regards,
Andre.

-- 
Andre Przywara
AMD-OSRC (Dresden)
Tel: x29712

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH v2] osdep: Fix runtime failure on older Linux kernels
  2009-12-18  9:45 [Qemu-devel] [PATCH] osdep: Fix runtime failure on older Linux kernels Andre Przywara
  2009-12-18 10:42 ` [Qemu-devel] " Paolo Bonzini
  2009-12-18 11:32 ` [Qemu-devel] " Kevin Wolf
@ 2009-12-18 12:37 ` Andre Przywara
  2009-12-18 12:49   ` [Qemu-devel] " Kevin Wolf
  2 siblings, 1 reply; 6+ messages in thread
From: Andre Przywara @ 2009-12-18 12:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Andre Przywara

If QEMU finds newer kernel header files on compilation time, it will use
advertised features like pipe2 or SOCK_CLOEXEC by just doing a compile test.
If later the executables are executed on an older kernel (<2.6.27,
like Xen Dom0 2.6.18), then QEMU will fail on opening sockets and creating
pipes and returns the rather unspecific "qemu_init_main_loop failed".
This patch fixes this by checking the return values of these calls
for EINVAL and ENOSYS and falling back to the older versions automatically.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
---
 osdep.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

v2 changed the errno check from EINVAL to ENOSYS for accept4

diff --git a/osdep.c b/osdep.c
index 7509c5b..60469ed 100644
--- a/osdep.c
+++ b/osdep.c
@@ -262,13 +262,15 @@ int qemu_pipe(int pipefd[2])
 
 #ifdef CONFIG_PIPE2
     ret = pipe2(pipefd, O_CLOEXEC);
-#else
+    if (ret != -1 || errno != ENOSYS) {
+        return ret;
+    }
+#endif
     ret = pipe(pipefd);
     if (ret == 0) {
         qemu_set_cloexec(pipefd[0]);
         qemu_set_cloexec(pipefd[1]);
     }
-#endif
 
     return ret;
 }
@@ -283,12 +285,14 @@ int qemu_socket(int domain, int type, int protocol)
 
 #ifdef SOCK_CLOEXEC
     ret = socket(domain, type | SOCK_CLOEXEC, protocol);
-#else
+    if (ret != -1 || errno != EINVAL) {
+        return ret;
+    }
+#endif
     ret = socket(domain, type, protocol);
     if (ret >= 0) {
         qemu_set_cloexec(ret);
     }
-#endif
 
     return ret;
 }
@@ -302,12 +306,14 @@ int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
 
 #ifdef CONFIG_ACCEPT4
     ret = accept4(s, addr, addrlen, SOCK_CLOEXEC);
-#else
+    if (ret != -1 || errno != ENOSYS) {
+        return ret;
+    }
+#endif
     ret = accept(s, addr, addrlen);
     if (ret >= 0) {
         qemu_set_cloexec(ret);
     }
-#endif
 
     return ret;
 }
-- 
1.6.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] Re: [PATCH v2] osdep: Fix runtime failure on older Linux kernels
  2009-12-18 12:37 ` [Qemu-devel] [PATCH v2] " Andre Przywara
@ 2009-12-18 12:49   ` Kevin Wolf
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin Wolf @ 2009-12-18 12:49 UTC (permalink / raw)
  To: Andre Przywara; +Cc: qemu-devel

Am 18.12.2009 13:37, schrieb Andre Przywara:
> If QEMU finds newer kernel header files on compilation time, it will use
> advertised features like pipe2 or SOCK_CLOEXEC by just doing a compile test.
> If later the executables are executed on an older kernel (<2.6.27,
> like Xen Dom0 2.6.18), then QEMU will fail on opening sockets and creating
> pipes and returns the rather unspecific "qemu_init_main_loop failed".
> This patch fixes this by checking the return values of these calls
> for EINVAL and ENOSYS and falling back to the older versions automatically.
> 
> Signed-off-by: Andre Przywara <andre.przywara@amd.com>
> ---
>  osdep.c |   18 ++++++++++++------
>  1 files changed, 12 insertions(+), 6 deletions(-)
> 
> v2 changed the errno check from EINVAL to ENOSYS for accept4

Acked-by: Kevin Wolf <kwolf@redhat.com>

I think this patch even qualifies for stable, though this might mean
0.12.1 now.

Kevin

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-12-18 12:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-18  9:45 [Qemu-devel] [PATCH] osdep: Fix runtime failure on older Linux kernels Andre Przywara
2009-12-18 10:42 ` [Qemu-devel] " Paolo Bonzini
2009-12-18 11:32 ` [Qemu-devel] " Kevin Wolf
2009-12-18 12:33   ` Andre Przywara
2009-12-18 12:37 ` [Qemu-devel] [PATCH v2] " Andre Przywara
2009-12-18 12:49   ` [Qemu-devel] " Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).