nbdkit_error - Man Page

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

License

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

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.

Referenced By

NBDKit(3), nbdkit_debug(3), nbdkit-error-filter(1), nbdkit_export_name(3), nbdkit-filter(3), nbdkit_is_tls(3), nbdkit_nanosleep(3), nbdkit_parse_bool(3), nbdkit_parse_delay(3), nbdkit_parse_int(3), nbdkit_parse_probability(3), nbdkit_parse_size(3), nbdkit_peer_name(3), nbdkit_peer_tls_dn(3), nbdkit-plugin(3), nbdkit_read_password(3), nbdkit_realpath(3), nbdkit_strdup_intern(3).

The man pages nbdkit_set_error(3) and nbdkit_verror(3) are aliases of nbdkit_error(3).

2024-10-14 nbdkit-1.41.8