From: Andre Przywara Date: Fri, 18 Dec 2009 09:45:07 +0000 (+0100) Subject: osdep: Fix runtime failure on older Linux kernels X-Git-Tag: TizenStudio_2.0_p2.3.2~208^2~9288 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3a03bfa5a219fe06779706315f2555622b51193c;p=sdk%2Femulator%2Fqemu.git osdep: Fix runtime failure on older Linux kernels 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 Signed-off-by: Aurelien Jarno --- 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; }