Skip to contentSkip to conversation

linux-user: syscall: Add SO_LINGER for setsockopt

PATCH In review [email protected] 2 participants 2 messages Jan 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 linux-user: syscall: Add SO_LINGER for setsockopt

From: Chen Gang <[email protected]>

Just implement it according to the other features implementations.

---
 linux-user/syscall.c      | 18 +++++++++++++++++-
 linux-user/syscall_defs.h |  5 +++++
 2 files changed, 22 insertions(+), 1 deletion(-)
linux-user/syscall.c +17 -1
index 4c68800..fcdca2a 100644
@@ -1410,6 +1410,9 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
     int val;
     struct ip_mreqn *ip_mreq;
     struct ip_mreq_source *ip_mreq_source;
+    struct linger lg;
+    struct target_linger *tlg;
+
 
     switch(level) {
     case SOL_TCP:
@@ -1661,7 +1664,20 @@ set_timeout:
         case TARGET_SO_RCVLOWAT:
 		optname = SO_RCVLOWAT;
 		break;
-            break;
+        case TARGET_SO_LINGER:
+            optname = SO_LINGER;
+            if (optlen != sizeof(struct target_linger)) {
+                return -TARGET_EINVAL;
+            }
+            if (!lock_user_struct(VERIFY_READ, tlg, optval_addr, 1)) {
+                return -TARGET_EFAULT;
+            }
+            __get_user(lg.l_onoff, &tlg->l_onoff);
+            __get_user(lg.l_linger, &tlg->l_linger);
+            ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname,
+                            &lg, sizeof(lg)));
+            unlock_user_struct(tlg, optval_addr, 0);
+            return ret;
         default:
             goto unimplemented;
         }
linux-user/syscall_defs.h +5 -0
index f996acf..6591e74 100644
@@ -166,6 +166,11 @@ struct target_ip_mreq_source {
     uint32_t imr_sourceaddr;
 };
 
+struct target_linger {
+    abi_int l_onoff;        /* Linger active                */
+    abi_int l_linger;       /* How long to linger for       */
+};
+
 struct target_timeval {
     abi_long tv_sec;
     abi_long tv_usec;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 33 lines · Le 11/01/2016 07:47, [email protected] a écrit :

From: Chen Gang <[email protected]>

Just implement it according to the other features implementations.

---
 linux-user/syscall.c      | 18 +++++++++++++++++-
 linux-user/syscall_defs.h |  5 +++++
 2 files changed, 22 insertions(+), 1 deletion(-)
linux-user/syscall.c +7 -1
index 4c68800..fcdca2a 100644
@@ -1410,6 +1410,9 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
     int val;
     struct ip_mreqn *ip_mreq;
     struct ip_mreq_source *ip_mreq_source;
+    struct linger lg;
+    struct target_linger *tlg;
+
 
     switch(level) {
     case SOL_TCP:
@@ -1661,7 +1664,20 @@ set_timeout:
         case TARGET_SO_RCVLOWAT:
 		optname = SO_RCVLOWAT;
 		break;
-            break;
+        case TARGET_SO_LINGER:
+            optname = SO_LINGER;
+            if (optlen != sizeof(struct target_linger)) {
+                return -TARGET_EINVAL;

linux-user/syscall.c set_timeout: · line 1680

Quoted 10 lines
linux-user/syscall.c +10 -0
+            }
+            if (!lock_user_struct(VERIFY_READ, tlg, optval_addr, 1)) {
+                return -TARGET_EFAULT;
+            }
+            __get_user(lg.l_onoff, &tlg->l_onoff);
+            __get_user(lg.l_linger, &tlg->l_linger);
+            ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname,
+                            &lg, sizeof(lg)));
+            unlock_user_struct(tlg, optval_addr, 0);
+            return ret;

I think it should be moved before the "/* Options with 'int' argument */" comment.

Except that, it is good.

Quoted 20 lines
linux-user/syscall.c +0 -0
         default:
             goto unimplemented;
         }
linux-user/syscall_defs.h +5 -0
index f996acf..6591e74 100644
@@ -166,6 +166,11 @@ struct target_ip_mreq_source {
     uint32_t imr_sourceaddr;
 };
 
+struct target_linger {
+    abi_int l_onoff;        /* Linger active                */
+    abi_int l_linger;       /* How long to linger for       */
+};
+
 struct target_timeval {
     abi_long tv_sec;
     abi_long tv_usec;