Skip to contentSkip to conversation

linux-user: Fix SO_ERROR return code of getsockopt()

PATCH Superseded Helge Deller 3 participants 8 messages Dec 16, 2022 – Jan 30, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: Fix SO_ERROR return code of getsockopt()

Add translation for the host error return code of:

    getsockopt(19, SOL_SOCKET, SO_ERROR, [ECONNREFUSED], [4]) = 0

This fixes the testsuite of the cockpit debian package with a hppa-linux guest on a x86-64 host.

---
 linux-user/syscall.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
linux-user/syscall.c +3 -2
index e541fbe09a..52693b4239 100644
@@ -2809,8 +2809,9 @@ get_timeout:
         ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
         if (ret < 0)
             return ret;
-        if (optname == SO_TYPE) {
-            val = host_to_target_sock_type(val);
+        switch (optname) {
+        case SO_TYPE:   val = host_to_target_sock_type(val);    break;
+        case SO_ERROR:  val = host_to_target_errno(val);        break;
         }
         if (len > lv)
             len = lv;

--
2.38.1

#1 lore raw

Le 16/12/2022 à 11:10, Helge Deller a écrit :

Quoted 16 lines

Add translation for the host error return code of:

     getsockopt(19, SOL_SOCKET, SO_ERROR, [ECONNREFUSED], [4]) = 0

This fixes the testsuite of the cockpit debian package with a hppa-linux guest on a x86-64 host.

---
  linux-user/syscall.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
linux-user/syscall.c +0 -0
index e541fbe09a..52693b4239 100644

linux-user/syscall.c get_timeout: · line 2814

Quoted 8 lines
linux-user/syscall.c +3 -2
@@ -2809,8 +2809,9 @@ get_timeout:
          ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
          if (ret < 0)
              return ret;
-        if (optname == SO_TYPE) {
-            val = host_to_target_sock_type(val);
+        switch (optname) {
+        case SO_TYPE:   val = host_to_target_sock_type(val);    break;
+        case SO_ERROR:  val = host_to_target_errno(val);        break;

It looks good but I think compiler will complain if you don't have a default case.

perhaps "if (optname == SO_TYPE) { } else if (optname == SO_ERROR) { }" would be better.

Thanks,
Laurent

Quoted 7 lines
linux-user/syscall.c +0 -1
          }
          if (len > lv)
              len = lv;
--

2.38.1

#2 lore raw
Quoted 12 lines · Laurent Vivier

Le 16/12/2022 à 11:10, Helge Deller a écrit :

Quoted 11 lines

Add translation for the host error return code of:
     getsockopt(19, SOL_SOCKET, SO_ERROR, [ECONNREFUSED], [4]) = 0

This fixes the testsuite of the cockpit debian package with a hppa-linux guest on a x86-64 host.

---
  linux-user/syscall.c | 5 +++--

  1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 15 lines

linux-user/syscall.c get_timeout: · line 2814

Quoted 13 lines
linux-user/syscall.c +3 -2
index e541fbe09a..52693b4239 100644
@@ -2809,8 +2809,9 @@ get_timeout:
           ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
           if (ret < 0)
               return ret;
-        if (optname == SO_TYPE) {
-            val = host_to_target_sock_type(val);
+        switch (optname) {
+        case SO_TYPE:   val = host_to_target_sock_type(val);    break;
+        case SO_ERROR:  val = host_to_target_errno(val);        break;

It looks good but I think compiler will complain if you don't have a default case.

It didn't for me, but I'm not sure for others.

Quoted 1 line

perhaps "if (optname == SO_TYPE) { } else if (optname == SO_ERROR) { }" would be better.

Personally I do prefer this type of switch statement here (which actually avoids such nested "if" statements). But I'm not religious about it, so if you want it as nested "if"s I can send a new patch which will be larger and less readable... Please let me know.

Helge

Quoted 11 lines

Thanks,
Laurent

Quoted 7 lines
linux-user/syscall.c +0 -1
           }
           if (len > lv)
               len = lv;
--

2.38.1

#3 lore raw

Le 26/01/2023 à 19:27, Helge Deller a écrit :

Quoted 29 lines · Laurent Vivier
Quoted 12 lines

Le 16/12/2022 à 11:10, Helge Deller a écrit :

Quoted 11 lines

Add translation for the host error return code of:
     getsockopt(19, SOL_SOCKET, SO_ERROR, [ECONNREFUSED], [4]) = 0

This fixes the testsuite of the cockpit debian package with a hppa-linux guest on a x86-64 host.

---
  linux-user/syscall.c | 5 +++--

  1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 15 lines

linux-user/syscall.c get_timeout: · line 2814

Quoted 13 lines
linux-user/syscall.c +3 -2
index e541fbe09a..52693b4239 100644
@@ -2809,8 +2809,9 @@ get_timeout:
           ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
           if (ret < 0)
               return ret;
-        if (optname == SO_TYPE) {
-            val = host_to_target_sock_type(val);
+        switch (optname) {
+        case SO_TYPE:   val = host_to_target_sock_type(val);    break;
+        case SO_ERROR:  val = host_to_target_errno(val);        break;

It looks good but I think compiler will complain if you don't have a default case.

Quoted 1 line

It didn't for me, but I'm not sure for others.

It's ok. No errors reported by gcc.

however checkscript.sh is not happy:

ERROR: trailing statements should be on next line
#30: FILE: linux-user/syscall.c:2762:
+ case SO_TYPE: val = host_to_target_sock_type(val); break;

ERROR: trailing statements should be on next line
#31: FILE: linux-user/syscall.c:2763:
+ case SO_ERROR: val = host_to_target_errno(val); break;

Thanks,
Laurent

#4 lore raw

PATCH v2 1/1 linux-user: Fix SO_ERROR return code of getsockopt()

Add translation for the host error return code of:

    getsockopt(19, SOL_SOCKET, SO_ERROR, [ECONNREFUSED], [4]) = 0

This fixes the testsuite of the cockpit debian package with a hppa-linux guest on a x86-64 host.

---
v2: Fix indenting to make checkscript.sh happy

linux-user/syscall.c +6 -1
index dac0cfe6c4..06e8612675 100644
@@ -2809,8 +2809,13 @@ get_timeout:
         ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
         if (ret < 0)
             return ret;
-        if (optname == SO_TYPE) {
+        switch (optname) {
+        case SO_TYPE:
             val = host_to_target_sock_type(val);
+            break;
+        case SO_ERROR:
+            val = host_to_target_errno(val);
+            break;
         }
         if (len > lv)
             len = lv;
Reviewed-by on v2 1/1
#6 lore raw
In reply to Helge Deller

Le 27/01/2023 à 21:25, Helge Deller a écrit :

Quoted 21 lines

Add translation for the host error return code of:

     getsockopt(19, SOL_SOCKET, SO_ERROR, [ECONNREFUSED], [4]) = 0

This fixes the testsuite of the cockpit debian package with a hppa-linux guest on a x86-64 host.

---
v2: Fix indenting to make checkscript.sh happy

linux-user/syscall.c +0 -1
index dac0cfe6c4..06e8612675 100644
@@ -2809,8 +2809,13 @@ get_timeout:
          ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
          if (ret < 0)
              return ret;
-        if (optname == SO_TYPE) {

linux-user/syscall.c get_timeout: · line 2821

Quoted 10 lines
linux-user/syscall.c +6 -0
+        switch (optname) {
+        case SO_TYPE:
              val = host_to_target_sock_type(val);
+            break;
+        case SO_ERROR:
+            val = host_to_target_errno(val);
+            break;
          }
          if (len > lv)
              len = lv;
#7 lore raw
In reply to Helge Deller

Le 27/01/2023 à 21:25, Helge Deller a écrit :

Quoted 21 lines

Add translation for the host error return code of:

     getsockopt(19, SOL_SOCKET, SO_ERROR, [ECONNREFUSED], [4]) = 0

This fixes the testsuite of the cockpit debian package with a hppa-linux guest on a x86-64 host.

---
v2: Fix indenting to make checkscript.sh happy

linux-user/syscall.c +0 -1
index dac0cfe6c4..06e8612675 100644
@@ -2809,8 +2809,13 @@ get_timeout:
          ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
          if (ret < 0)
              return ret;
-        if (optname == SO_TYPE) {

linux-user/syscall.c get_timeout: · line 2821

Quoted 10 lines
linux-user/syscall.c +6 -0
+        switch (optname) {
+        case SO_TYPE:
              val = host_to_target_sock_type(val);
+            break;
+        case SO_ERROR:
+            val = host_to_target_errno(val);
+            break;
          }
          if (len > lv)
              len = lv;

Applied to my linux-user-for-8.0 branch.

Thanks,
Laurent