* [PATCH] libxfs: don't pass negative errnos to strerror()
@ 2016-01-14 16:35 Eric Sandeen
2016-01-14 16:47 ` Carlos Maiolino
0 siblings, 1 reply; 2+ messages in thread
From: Eric Sandeen @ 2016-01-14 16:35 UTC (permalink / raw)
To: xfs
The error negation work in 12b5319 tripped up a little bit
when we're reporting errors via strerror(). By negating
the error before passing it to strerror, we get i.e.
mkfs.xfs: pwrite64 failed: Unknown error -22
Keep the error positive, but return -error, just as we
do in the else clauses in these functions.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 7a04985..7b23394 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -913,12 +913,12 @@ __read_buf(int fd, void *buf, int len, off64_t offset, int flags)
sts = pread64(fd, buf, len, offset);
if (sts < 0) {
- int error = -errno;
+ int error = errno;
fprintf(stderr, _("%s: read failed: %s\n"),
progname, strerror(error));
if (flags & LIBXFS_EXIT_ON_FAILURE)
exit(1);
- return error;
+ return -error;
} else if (sts != len) {
fprintf(stderr, _("%s: error - read only %d of %d bytes\n"),
progname, sts, len);
@@ -1081,12 +1081,12 @@ __write_buf(int fd, void *buf, int len, off64_t offset, int flags)
sts = pwrite64(fd, buf, len, offset);
if (sts < 0) {
- int error = -errno;
+ int error = errno;
fprintf(stderr, _("%s: pwrite64 failed: %s\n"),
progname, strerror(error));
if (flags & LIBXFS_B_EXIT)
exit(1);
- return error;
+ return -error;
} else if (sts != len) {
fprintf(stderr, _("%s: error - pwrite64 only %d of %d bytes\n"),
progname, sts, len);
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] libxfs: don't pass negative errnos to strerror()
2016-01-14 16:35 [PATCH] libxfs: don't pass negative errnos to strerror() Eric Sandeen
@ 2016-01-14 16:47 ` Carlos Maiolino
0 siblings, 0 replies; 2+ messages in thread
From: Carlos Maiolino @ 2016-01-14 16:47 UTC (permalink / raw)
To: Eric Sandeen; +Cc: xfs
This looks good to me, and simple enough.
consider it
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
On Thu, Jan 14, 2016 at 10:35:53AM -0600, Eric Sandeen wrote:
> The error negation work in 12b5319 tripped up a little bit
> when we're reporting errors via strerror(). By negating
> the error before passing it to strerror, we get i.e.
>
> mkfs.xfs: pwrite64 failed: Unknown error -22
>
> Keep the error positive, but return -error, just as we
> do in the else clauses in these functions.
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
>
> diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
> index 7a04985..7b23394 100644
> --- a/libxfs/rdwr.c
> +++ b/libxfs/rdwr.c
> @@ -913,12 +913,12 @@ __read_buf(int fd, void *buf, int len, off64_t offset, int flags)
>
> sts = pread64(fd, buf, len, offset);
> if (sts < 0) {
> - int error = -errno;
> + int error = errno;
> fprintf(stderr, _("%s: read failed: %s\n"),
> progname, strerror(error));
> if (flags & LIBXFS_EXIT_ON_FAILURE)
> exit(1);
> - return error;
> + return -error;
> } else if (sts != len) {
> fprintf(stderr, _("%s: error - read only %d of %d bytes\n"),
> progname, sts, len);
> @@ -1081,12 +1081,12 @@ __write_buf(int fd, void *buf, int len, off64_t offset, int flags)
>
> sts = pwrite64(fd, buf, len, offset);
> if (sts < 0) {
> - int error = -errno;
> + int error = errno;
> fprintf(stderr, _("%s: pwrite64 failed: %s\n"),
> progname, strerror(error));
> if (flags & LIBXFS_B_EXIT)
> exit(1);
> - return error;
> + return -error;
> } else if (sts != len) {
> fprintf(stderr, _("%s: error - pwrite64 only %d of %d bytes\n"),
> progname, sts, len);
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
--
Carlos
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-01-14 16:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-14 16:35 [PATCH] libxfs: don't pass negative errnos to strerror() Eric Sandeen
2016-01-14 16:47 ` Carlos Maiolino
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox