errno is currently set to a suitable value if nbdkit_extents_new returns an error, but this was not documented so I added that documentation. Set errno to a suitable value if nbdkit_add_extent returns an error, and also document that. Thanks: Eric Blake for spotting the problem. --- docs/nbdkit-filter.pod | 3 ++- docs/nbdkit-plugin.pod | 2 +- server/extents.c | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/nbdkit-filter.pod b/docs/nbdkit-filter.pod index 9e51c68..6aeaa7b 100644 --- a/docs/nbdkit-filter.pod +++ b/docs/nbdkit-filter.pod @@ -571,7 +571,8 @@ the end, but for filters which adjust offsets, they should pass in the adjusted offset. On error this function can return C<NULL>. In this case it calls -C<nbdkit_error> and/or C<nbdkit_set_error> as required. +C<nbdkit_error> and/or C<nbdkit_set_error> as required. C<errno> will +be set to a suitable value. void nbdkit_extents_free (struct nbdkit_extents *); diff --git a/docs/nbdkit-plugin.pod b/docs/nbdkit-plugin.pod index 272ec67..e9dc34f 100644 --- a/docs/nbdkit-plugin.pod +++ b/docs/nbdkit-plugin.pod @@ -812,7 +812,7 @@ guarantee that trimmed blocks read back as zeroes. C<nbdkit_extent_add> returns C<0> on success or C<-1> on failure. On failure C<nbdkit_error> and/or C<nbdkit_set_error> has already been -called. +called. C<errno> will be set to a suitable value. =head1 THREADS diff --git a/server/extents.c b/server/extents.c index 105c4a7..d3d1a15 100644 --- a/server/extents.c +++ b/server/extents.c @@ -154,6 +154,7 @@ nbdkit_add_extent (struct nbdkit_extents *exts, nbdkit_error ("nbdkit_add_extent: " "extents must be added in ascending order and " "must be contiguous"); + errno = ERANGE; return -1; } exts->next = offset + length; @@ -186,6 +187,7 @@ nbdkit_add_extent (struct nbdkit_extents *exts, nbdkit_error ("nbdkit_add_extent: " "first extent must not be > start (%" PRIu64 ")", exts->start); + errno = ERANGE; return -1; } -- 2.20.1