Skip to contentSkip to conversation

tools/9pfsd: Fix build error caused by strerror_r

PATCH Superseded Henry Wang 2 participants 2 messages Mar 7, 2024

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Henry Wang

author
#0 lore raw

PATCH 1/1 tools/9pfsd: Fix build error caused by strerror_r

Below error can be seen when doing Yocto build of the toolstack:

| io.c: In function 'p9_error':
| io.c:684:5: error: ignoring return value of 'strerror_r' declared
with attribute 'warn_unused_result' [-Werror=unused-result]

|   684 |     strerror_r(err, ring->buffer, ring->ring_size);
|       |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| cc1: all warnings being treated as errors

Fix it by adding a return value and check it properly.

---
 tools/9pfsd/io.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
tools/9pfsd/io.c +11 -5
index adb887c7d9..163eee6ecc 100644
@@ -681,11 +681,17 @@ static void p9_error(struct ring *ring, uint16_t tag, uint32_t err)
 {
     unsigned int erroff;
 
-    strerror_r(err, ring->buffer, ring->ring_size);
-    erroff = add_string(ring, ring->buffer, strlen(ring->buffer));
-    fill_buffer(ring, P9_CMD_ERROR, tag, "SU",
-                erroff != ~0 ? ring->str + erroff : "cannot allocate memory",
-                &err);
+    char *ret = strerror_r(err, ring->buffer, ring->ring_size);
+
+    if ( ret )
+    {
+        erroff = add_string(ring, ring->buffer, strlen(ring->buffer));
+        fill_buffer(ring, P9_CMD_ERROR, tag, "SU",
+                    erroff != ~0 ?
+                             ring->str + erroff :
+                             "cannot allocate memory",
+                    &err);
+    }
 }
 
 static void p9_version(struct ring *ring, struct p9_header *hdr)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 22 lines · Henry Wang

Below error can be seen when doing Yocto build of the toolstack:

| io.c: In function 'p9_error':
| io.c:684:5: error: ignoring return value of 'strerror_r' declared
with attribute 'warn_unused_result' [-Werror=unused-result]

|   684 |     strerror_r(err, ring->buffer, ring->ring_size);
|       |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| cc1: all warnings being treated as errors

Fix it by adding a return value and check it properly.

---
 tools/9pfsd/io.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
tools/9pfsd/io.c +0 -0
index adb887c7d9..163eee6ecc 100644
@@ -681,11 +681,17 @@ static void p9_error(struct ring *ring, uint16_t tag, uint32_t err)
 {

tools/9pfsd/io.c static void p9_error(struct ring *ring, uint16_t tag, uint32_t err) · line 686

Quoted 10 lines
tools/9pfsd/io.c +3 -5
     unsigned int erroff;
 
-    strerror_r(err, ring->buffer, ring->ring_size);
-    erroff = add_string(ring, ring->buffer, strlen(ring->buffer));
-    fill_buffer(ring, P9_CMD_ERROR, tag, "SU",
-                erroff != ~0 ? ring->str + erroff : "cannot allocate memory",
-                &err);
+    char *ret = strerror_r(err, ring->buffer, ring->ring_size);
+
+    if ( ret )

While you're checking the return value, this looks to be the only use of "ret". Which looks wrong for the GNU form of the function. But an up front question is whether we can expect all host OSes / libc implementations to actually support the GNU form. Using _GNU_SOURCE may, after all, then not be appropriate for a component using this function. Jürgen, thoughts?

tools/9pfsd/io.c static void p9_error(struct ring *ring, uint16_t tag, uint32_t err) · line 692

Quoted 6 lines
tools/9pfsd/io.c +6 -0
+    {
+        erroff = add_string(ring, ring->buffer, strlen(ring->buffer));
+        fill_buffer(ring, P9_CMD_ERROR, tag, "SU",
+                    erroff != ~0 ?
+                             ring->str + erroff :
+                             "cannot allocate memory",

Indentation looks questionable to me here, albeit tools/ may have different preferences than xen/.

Jan

Quoted 5 lines
tools/9pfsd/io.c +2 -0
+                    &err);
+    }
 }
 
 static void p9_version(struct ring *ring, struct p9_header *hdr)