1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
|
.\"
.\" libexplain - a library of system-call-specific strerror replacements
.\" Copyright (C) 2010, 2011 Peter Miller
.\" Written by Peter Miller <pmiller@opensource.org.au>
.\"
.\" This program is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation; either version 3 of the License, or
.\" (at your option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
.\" General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program. If not, see <http://www.gnu.org/licenses/>.
.\"
.ds n) explain_output
.cp 0 \" Solaris defaults to ''.cp 1'', sheesh.
.TH explain_output 3
.SH NAME
explain_output \- output error messages
.if require_index \{
.XX "explain_output(3)" "output error messages"
.\}
.SH SYNOPSIS
.ft CW
#include <libexplain/output.h>
.ft R
.SH DESCRIPTION
These functions may be used to write error messages.
.SS explain_output_message
.ad l
.ft CW
void explain_output_message(const char *text);
.ft R
.ad b
.PP
The explain_output_message function is used to print
text. It is printed via the registered output class, see
\f[I]explain_output_register\fP(3) for how.
.TP 8n
\f[I]text\fP
The text of the message to be printed.
It has not been wrapped (yet).
.SS explain_output_error
.ad l
.ft CW
void explain_output_error(const char *fmt, ...);
.ft R
.ad b
.PP
The explain_output_error function is used to print a formatted error
message. The printing is done via the \f[I]explain_output_message\fP(3)
function.
.TP 8n
\f[I]fmt\fP
The format text of the message to be printed.
See \f[I]printf\fP(3) for more information.
.SS explain_output_error_and_die
.ad l
.ft CW
void explain_output_error_and_die(const char *fmt, ...);
.ft R
.ad b
.PP
The explain_output_error_and_die function is used to print
text, and then terminate immediately. The printing is
done via the \f[I]explain_output_message\fP(3) function,
process termination is via the
\f[I]explain_output_exit_failure\fP(3) function.
.TP 8n
\f[I]fmt\fP
The format text of the message to be printed.
See printf(3) for more information.
.SS explain_output_warning
.ad l
.ft CW
void explain_output_warning(const char *fmt, ...);
.ft R
.ad b
.PP
The explain_output_warning function is used to print a formatted
error message, including the word \[lq]warning\[rq]. The printing is done
via the \f[I]explain_output_message\fP(3) function.
.TP 8n
\f[I]fmt\fP
The format text of the message to be printed.
See \f[I]printf\fP(3) for more information.
.SS explain_output_exit
.ad l
.ft CW
void explain_output_exit(int status);
.ft R
.ad b
.PP
The explain_output_exit function is used to terminate
execution. It is executed via the registered output class,
\f[I]explain_output_register\fP(3) for how.
.TP 8n
\f[I]status\fP
The exist status requested.
.SS explain_output_exit_failure
.ad l
.ft CW
void explain_output_exit_failure(void);
.ft R
.ad b
.PP
The explain_output_exit_failure function is used to terminate
execution, with exit status EXIT_FAILURE. It is executed via the
registered output class, see \f[I]explain_output_register\fP(3) for how.
.SS explain_option_hanging_indent_set
.ad l
.ft CW
void explain_option_hanging_indent_set(int columns);
.ft R
.ad b
.PP
The explain_option_hanging_indent_set function is used to cause
the output wrapping to use hanging indents. By default no hanging
indent is used, but this can sometimes obfuscate the end of one
error message and the beginning of another. A hanging indent
results in continuation lines starting with white space, similar to
RFC822 headers.
.PP
This can be set using the \[lq]\f[CW]hanging\[hy]indent=\fP\f[I]n\fP\[rq]
string in the EXPLAIN_OPTIONS environment variable.
See \f[I]explain\fP(3) for more information.
.PP
Using this function will override any environment variable setting.
.TP 8n
\f[I]columns\fP
The number of columns of hanging indent to be used. A value of
0 means no hanging indent (all lines flush with left margin).
A common value to use is 4: it doesn't consume too much of each
line, and it is a clear indent.
.SH OUTPUT REDIRECTION
It is possible to change how and where libexplain sends its output,
and even how it calls the \f[I]exit\fP(2) function. This functionality is
used by the \f[CW]explain_*_or_die\fP and \f[CW]explain_*_on_error\fP functions.
.PP
By default, libexplain will wrap and print error messages on stderr,
and call the \f[I]exit\fP(2) system call to terminate execution.
.PP
Clients of the libexplain library may choose to use some message
handling facilities provided by libexplain, or they may choose to
implement their own.
.TP 8n
\f[B]syslog\fP
.RS
To cause all output to be sent to syslog, use
.PP
.RS
.ft CW
explain_output_register(explain_output_syslog_new());
.ft R
.RE
.PP
This is useful for servers and daemons.
.RE
.TP 8n
\f[B]stderr and syslog\fP
.RS
The \[lq]tee\[rq] output class can be used to duplicate output.
To cause all output to be sent to both stderr and syslog, use
.PP
.RS
.nf
.ft CW
explain_output_register
(
explain_output_tee_new
(
explain_output_stderr_new(),
explain_output_syslog_new()
)
);
.ft R
.fi
.RE
.PP
If you need more than two, use several instances of \[lq]tee\[rq], cascaded.
.RE
.TP 8n
\f[B]stderr and a file\fP
.RS
To cause all output to be sent to both stderr and a regular file, use
.PP
.RS
.nf
.ft CW
explain_output_register
(
explain_output_tee_new
(
explain_output_stderr_new(),
explain_output_file_new(filename, 0)
)
);
.ft R
.fi
.RE
.RE
.PP
See the \f[CW]<libexplain/output.h>\fP file for extensive documentation.
.SS explain_output_new
.ad l
.ft CW
explain_output_t *explain_output_new(const explain_output_vtable_t *vtable);
.ft R
.ad b
.PP
The explain_output_new function may be used to create a new
dynamically allocated instance of explain_output_t.
.TP 8n
\f[I]vtable\fP
The struct containing the pointers to the methods of the derived
class.
.TP 8n
\f[I]returns\fP
NULL on error (i.e. malloc failed), or a pointer to a new
dynamically allocated instance of the class.
.SS explain_output_stderr_new
.ad l
.ft CW
explain_output_t *explain_output_stderr_new(void);
.ft R
.ad b
.PP
The explain_output_stderr_new function may be used to create a new
dynamically allocated instance of an explain_output_t
class that writes to stderr, and exits via \f[I]exit\fP(2);
.PP
This is the default output handler.
.TP 8n
\f[I]returns\fP
NULL on error (i.e. malloc failed), or a pointer to a new
dynamically allocated instance of the stderr class.
.SS explain_output_syslog_new
.ad l
.ft CW
explain_output_t *explain_output_syslog_new(void);
.ft R
.ad b
.PP
The explain_output_syslog_new function may be used to create a new
dynamically allocated instance of an explain_output_t
class that writes to syslog, and exits via \f[I]exit\fP(2);
.PP
The following values are used:
.PP
.RS
.nf
.ft CW
option = 0
facility = LOG_USER
level = LOG_ERR
.ft R
.fi
.RE
.PP
See \f[I]syslog\fP(3) for more information.
.TP 8n
\f[I]returns\fP
NULL on error (i.e. \f[I]malloc\fP(3) failed), or a pointer to a new
dynamically allocated instance of the syslog class.
.SS explain_output_syslog_new1
.ad l
.ft CW
explain_output_t *explain_output_syslog_new1(int level);
.ft R
.ad b
.PP
The explain_output_syslog_new1 function may be used to create a new
dynamically allocated instance of an explain_output_t class that
writes to syslog, and exits via \f[I]exit\fP(2);
.PP
The following values are used:
.PP
.RS
.nf
.ft CW
option = 0
facility = LOG_USER
.ft R
.fi
.RE
.PP
See \f[I]syslog\fP(3) for more information.
.TP 8n
\f[I]level\fP
The syslog level to be used, see syslog(3) for a definition.
.TP 8n
\f[I]returns\fP
NULL on error (i.e. \f[I]malloc\fP(3) failed), or a pointer to a new
dynamically allocated instance of the syslog class.
.SS explain_output_syslog_new3
.ad l
.ft CW
explain_output_t *explain_output_syslog_new3(int option, int facility,
int level);
.ft R
.ad b
.PP
The explain_output_syslog_new3 function may be used to create a new
dynamically allocated instance of an explain_output_t class that
writes to syslog, and exits via \f[I]exit\fP(2);
.PP
If you want different facilities or levels, create multiple instances.
.TP 8n
\f[I]option\fP
The syslog option to be used, see syslog(3) for a definition.
.TP 8n
\f[I]facility\fP
The syslog facility to be used, see syslog(3) for a definition.
.TP 8n
\f[I]level\fP
The syslog level to be used, see syslog(3) for a definition.
.TP 8n
\f[I]returns\fP
NULL on error (i.e. \f[I]malloc\fP(3) failed), or a pointer to a new
dynamically allocated instance of the syslog class.
.SS explain_output_file_new
.ad l
.ft CW
explain_output_t *explain_output_file_new(const char *filename, int append);
.ft R
.ad b
.PP
The explain_output_file_new function may be used to create a new
dynamically allocated instance of an explain_output_t class that
writes to a file, and exits via \f[I]exit\fP(2).
.TP 8n
\f[I]filename\fP
The file to be opened and written to.
.TP 8n
\f[I]append\fP
true (non\[hy]zero) if messages are to be appended to the file,
false (zero) if the file is to be replaced with new contents.
.TP 8n
\f[I]returns\fP
NULL on error (i.e. \f[I]malloc\fP(3) or \f[I]open\fP(2) failed), or a
pointer to a new dynamically allocated instance of the syslog class.
.SS explain_output_tee_new
.ad l
.ft CW
explain_output_t *explain_output_tee_new(explain_output_t *first,
explain_output_t *second);
.ft R
.ad b
.PP
The explain_output_tee_new function may be used to create a new
dynamically allocated instance of an explain_output_t class that
writes to \f[B]two\fP other output classes.
.TP 8n
\f[I]first
The first output class to write to.
.TP 8n
\f[I]second
The second output class to write to.
.TP 8n
\f[I]returns
NULL on error (i.e. \f[I]malloc\fP(3) failed), or a pointer to a new
dynamically allocated instance of the syslog class.
.PP
The output subsystem will \[lq]own\[rq] the \f[I]first\fP and
\f[I]second\fP objects after this call. You may not make any reference
to these pointers ever again. The output subsystem will destroy these
objects and free the memory when it feels like it.
.SS explain_output_register
.ad l
.ft CW
void explain_output_register(explain_output_t *op);
.ft R
.ad b
.PP
The explain_output_register function is used to change libexplain's
default output handling facilities with something else. The NULL
pointer restores libexplain's default processing.
.PP
If no output class is registered, the default is to wrap and print
to stderr, and to exit via the \f[I]exit\fP(2) system call.
.TP 8n
\f[I]op\fP
Pointer to the explain_output_t instance to be operated on.
.PP
The output subsystem will \[lq]own\[rq] the pointer after this call.
You may not make any reference to this pointer ever again. The output
subsystem will destroy the object and free the memory when it feels like
it.
.SH COPYRIGHT
.so etc/version.so
.if n .ds C) (C)
.if t .ds C) \(co
libexplain version \*(v)
.br
Copyright \*(C) 2010 Peter Miller
.SH AUTHOR
Written by Peter Miller <pmiller@opensource.org.au>
|