2 * Copyright (C) 2013-2017 Red Hat Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of Red Hat nor the names of its contributors may be
17 * used to endorse or promote products derived from this software without
18 * specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 #include "nbdkit-plugin.h"
47 /* Used to group piecemeal message construction into atomic output. */
48 static pthread_mutex_t errors_lock
= PTHREAD_MUTEX_INITIALIZER
;
53 int r
= pthread_mutex_lock (&errors_lock
);
60 int r
= pthread_mutex_unlock (&errors_lock
);
64 /* Called with lock taken. */
66 prologue (const char *type
)
68 const char *name
= threadlocal_get_name ();
69 size_t instance_num
= threadlocal_get_instance_num ();
71 fprintf (stderr
, "%s: ", program_name
);
74 fprintf (stderr
, "%s", name
);
76 fprintf (stderr
, "[%zu]", instance_num
);
77 fprintf (stderr
, ": ");
80 fprintf (stderr
, "%s: ", type
);
83 /* Note: preserves the previous value of errno. */
85 nbdkit_vdebug (const char *fs
, va_list args
)
95 vfprintf (stderr
, fs
, args
);
97 fprintf (stderr
, "\n");
103 /* Note: preserves the previous value of errno. */
105 nbdkit_debug (const char *fs
, ...)
117 vfprintf (stderr
, fs
, args
);
120 fprintf (stderr
, "\n");
126 /* Note: preserves the previous value of errno. */
128 nbdkit_verror (const char *fs
, va_list args
)
135 vfprintf (stderr
, fs
, args
);
137 fprintf (stderr
, "\n");
143 /* Note: preserves the previous value of errno. */
145 nbdkit_error (const char *fs
, ...)
154 vfprintf (stderr
, fs
, args
);
157 fprintf (stderr
, "\n");
164 nbdkit_set_error (int err
)
166 threadlocal_set_error (err
);