table of contents
nbdkit_error(3) | NBDKIT | nbdkit_error(3) |
NAME¶
nbdkit_error, nbdkit_verror, nbdkit_set_error - return an error from nbdkit plugins
SYNOPSIS¶
#include <nbdkit-plugin.h> void nbdkit_error (const char *fs, ...); void nbdkit_verror (const char *fs, va_list args); void nbdkit_set_error (int err);
DESCRIPTION¶
If there is an error in your plugin, the plugin should call "nbdkit_error" to report an error message. Then the callback should return the appropriate error indication, eg. "NULL" or -1.
"nbdkit_error" works like printf(3). "nbdkit_verror" works like vprintf(3).
For convenience, "nbdkit_error" preserves the value of "errno", and also supports the glibc extension of a single %m in a format string expanding to strerror(errno), even on platforms that don't support that natively.
Example¶
int my_pread (void *handle, void *buf, uint32_t count, uint64_t offset, uint32_t flags) { char *bounce_buffer = malloc (SECTOR_SIZE); if (bounce_buffer == NULL) { nbdkit_error ("malloc: %m"); return -1; } //... }
Setting errno¶
For callbacks which serve data to the client, the plugin may call "nbdkit_set_error" to influence the errno that will be sent back to the client.
If the call to "nbdkit_set_error" is omitted while serving data, then the global variable "errno" may be used. For plugins which have ".errno_is_preserved != 0" the server will use "errno". In plugins written in non-C languages, we usually cannot trust that "errno" will be preserved when returning from that language to C. In that case, either the plugin must call "nbdkit_set_error" or hard-coded "EIO" is used.
LANGUAGE BINDINGS¶
Most language bindings do not expose these functions explicitly. Instead you are expected to throw an exception on error which is implicitly turned into a call to "nbdkit_error". Read the documentation for the language binding to find out how errors are handled.
HISTORY¶
"nbdkit_error" and "nbdkit_verror" were present in nbdkit 0.1.0. "nbdkit_set_error" was added in nbdkit 1.2.
SEE ALSO¶
nbdkit(1), nbdkit_debug(3), nbdkit-plugin(3), nbdkit-filter(3).
AUTHORS¶
Eric Blake
Richard W.M. Jones
COPYRIGHT¶
Copyright Red Hat
LICENSE¶
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Red Hat nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2024-10-30 | nbdkit-1.40.4 |