]> git.proxmox.com Git - qemu.git/commitdiff
linux-user: correct setsockopt()
authorLaurent Vivier <Laurent@Vivier.EU>
Tue, 1 Jan 2013 08:24:11 +0000 (08:24 +0000)
committerLaurent Vivier <laurent@vivier.eu>
Wed, 30 Jan 2013 11:13:21 +0000 (12:13 +0100)
SO_SNDTIMEO and SO_RCVTIMEO take a struct timeval, not an int

To test this, you can use :

QEMU_STRACE= ping localhost 2>&1 |grep TIMEO
568 setsockopt(3,SOL_SOCKET,SO_SNDTIMEO,{1,0},8) = 0
568 setsockopt(3,SOL_SOCKET,SO_RCVTIMEO,{1,0},8) = 0

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
linux-user/syscall.c

index a6f42718c860913e5d792bbaba58da9e5f4579ce..151f4f32726c62f65b1fb69e8b1cb33f0a6b85d7 100644 (file)
@@ -1489,6 +1489,28 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
         break;
     case TARGET_SOL_SOCKET:
         switch (optname) {
+        case TARGET_SO_RCVTIMEO:
+        {
+                struct timeval tv;
+
+                optname = SO_RCVTIMEO;
+
+set_timeout:
+                if (optlen != sizeof(struct target_timeval)) {
+                    return -TARGET_EINVAL;
+                }
+
+                if (copy_from_user_timeval(&tv, optval_addr)) {
+                    return -TARGET_EFAULT;
+                }
+
+                ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname,
+                                &tv, sizeof(tv)));
+                return ret;
+        }
+        case TARGET_SO_SNDTIMEO:
+                optname = SO_SNDTIMEO;
+                goto set_timeout;
             /* Options with 'int' argument.  */
         case TARGET_SO_DEBUG:
                optname = SO_DEBUG;
@@ -1540,12 +1562,6 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
         case TARGET_SO_RCVLOWAT:
                optname = SO_RCVLOWAT;
                break;
-        case TARGET_SO_RCVTIMEO:
-               optname = SO_RCVTIMEO;
-               break;
-        case TARGET_SO_SNDTIMEO:
-               optname = SO_SNDTIMEO;
-               break;
             break;
         default:
             goto unimplemented;