diff mbox

[v2] linux-user: correct setsockopt()

Message ID 1357064651-30072-1-git-send-email-laurent@vivier.eu
State New
Headers show

Commit Message

Laurent Vivier Jan. 1, 2013, 6:24 p.m. UTC
From: Laurent Vivier <Laurent@Vivier.EU>

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>
---
v2: pass checkpatch.pl

 linux-user/syscall.c |   28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

Comments

Laurent Vivier Jan. 19, 2013, 11:32 p.m. UTC | #1
ping ?

Le mardi 01 janvier 2013 à 19:24 +0100, Laurent Vivier a écrit :
> From: Laurent Vivier <Laurent@Vivier.EU>
> 
> 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>
> ---
> v2: pass checkpatch.pl
> 
>  linux-user/syscall.c |   28 ++++++++++++++++++++++------
>  1 file changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index e99adab..2b2bd2b 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -1491,6 +1491,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;
> @@ -1542,12 +1564,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;
Laurent Vivier Jan. 26, 2013, 11:24 a.m. UTC | #2
Le dimanche 20 janvier 2013 à 00:32 +0100, Laurent Vivier a écrit :
> ping ?

ping

> Le mardi 01 janvier 2013 à 19:24 +0100, Laurent Vivier a écrit :
> > From: Laurent Vivier <Laurent@Vivier.EU>
> > 
> > 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>
> > ---
> > v2: pass checkpatch.pl
> > 
> >  linux-user/syscall.c |   28 ++++++++++++++++++++++------
> >  1 file changed, 22 insertions(+), 6 deletions(-)
> > 
> > diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> > index e99adab..2b2bd2b 100644
> > --- a/linux-user/syscall.c
> > +++ b/linux-user/syscall.c
> > @@ -1491,6 +1491,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;
> > @@ -1542,12 +1564,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;
>
Peter Maydell Jan. 26, 2013, 11:50 a.m. UTC | #3
On 1 January 2013 18:24, Laurent Vivier <laurent@vivier.eu> wrote:
> From: Laurent Vivier <Laurent@Vivier.EU>
>
> 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>

(indent on the case is dodgy but it matches the rest of
the switch statement, so I'll let it pass.)

-- PMM
Riku Voipio Jan. 30, 2013, 8:45 a.m. UTC | #4
Hi,

On Sat, Jan 26, 2013 at 12:24:56PM +0100, Laurent Vivier wrote:
> Le dimanche 20 janvier 2013 à 00:32 +0100, Laurent Vivier a écrit :
> > ping ?
> 
> ping

I'm really not managing to find time for qemu linux-user maintainance
at the moment. I suggest you send the patches directly as pull request.

Riku
 
> > Le mardi 01 janvier 2013 à 19:24 +0100, Laurent Vivier a écrit :
> > > From: Laurent Vivier <Laurent@Vivier.EU>
> > > 
> > > 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>
> > > ---
> > > v2: pass checkpatch.pl
> > > 
> > >  linux-user/syscall.c |   28 ++++++++++++++++++++++------
> > >  1 file changed, 22 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> > > index e99adab..2b2bd2b 100644
> > > --- a/linux-user/syscall.c
> > > +++ b/linux-user/syscall.c
> > > @@ -1491,6 +1491,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;
> > > @@ -1542,12 +1564,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;
> > 
> 
> -- 
> "Just play. Have fun. Enjoy the game."
> - Michael Jordan
> "Just play. Have fun. Enjoy the game."
> - Michael Jordan
Peter Maydell Jan. 30, 2013, 10:42 a.m. UTC | #5
On 30 January 2013 08:45, Riku Voipio <riku.voipio@iki.fi> wrote:
> On Sat, Jan 26, 2013 at 12:24:56PM +0100, Laurent Vivier wrote:
>> Le dimanche 20 janvier 2013 à 00:32 +0100, Laurent Vivier a écrit :
>> > ping ?
>>
>> ping
>
> I'm really not managing to find time for qemu linux-user maintainance
> at the moment. I suggest you send the patches directly as pull request.

...but only the ones somebody has reviewed, please.

-- PMM
Laurent Vivier Jan. 30, 2013, 11:15 a.m. UTC | #6
Le 30 janvier 2013 à 11:42, Peter Maydell <peter.maydell@linaro.org> a écrit :
> On 30 January 2013 08:45, Riku Voipio <riku.voipio@iki.fi> wrote:
> > On Sat, Jan 26, 2013 at 12:24:56PM +0100, Laurent Vivier wrote:
> >> Le dimanche 20 janvier 2013 à 00:32 +0100, Laurent Vivier a écrit :
> >> > ping ?
> >>
> >> ping
> >
> > I'm really not managing to find time for qemu linux-user maintainance
> > at the moment. I suggest you send the patches directly as pull request.
>
> ...but only the ones somebody has reviewed, please.
>

Yes, I will ask for a pull only patches with a Reviewed-by .

Regards,
Laurent
diff mbox

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e99adab..2b2bd2b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1491,6 +1491,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;
@@ -1542,12 +1564,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;