tools/9pfsd: Fix build error caused by strerror_r
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
@@ -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
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 errorsFix it by adding a return value and check it properly.
Signed-off-by Henry Wang <[email protected]>--- tools/9pfsd/io.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)tools/9pfsd/io.c +0
-0@@ -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
-5unsigned 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)