Skip site navigation (1)Skip section navigation (2)

  
 
  

home | help
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 appropri-
     ate 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 "nbd-
     kit_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 ".er-
     rno_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.

   Interaction with --log option
     The nbdkit --log option controls where error messages are sent.  The de-
     fault is to send error messages to stderr, unless nbdkit forks into the
     background in which case they are sent to syslog.	For more information
     read the description in nbdkit(1).

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.  "nbd-
     kit_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 modifi-
     cation, 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 no-
	 tice, this list of conditions and the following disclaimer in the docu-
	 mentation 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 EX-
     PRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS-
     CLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DI-
     RECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SER-
     VICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABIL-
     ITY, 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 DAM-
     AGE.

nbdkit-1.46.2			   2026-08-30			 nbdkit_error(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=nbdkit_set_error&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help