xref: /illumos-gate/usr/src/lib/varpd/libvarpd/common/libvarpd_panic.c (revision ed093b41a93e8563e6e1e5dae0768dda2a7bcc27)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2015, Joyent, Inc.
14  */
15 
16 /*
17  * No, 'tis not so deep as a well, nor so wide as a church door; but 'tis
18  * enough, 'twill serve. Ask for me tomorrow, and you shall find me a grave man.
19  *
20  * This file maintains various routines for handling when we die.
21  */
22 
23 #include <stdio.h>
24 #include <stdarg.h>
25 #include <errno.h>
26 #include <thread.h>
27 #include <stdlib.h>
28 
29 /*
30  * Normally these would be static, but if they're static, that throws off lint
31  * because it thinks we never use them, which is kind of the point, because we
32  * only read them in the core...
33  */
34 int varpd_panic_errno;
35 char varpd_panic_buf[1024];
36 thread_t varpd_panic_thread;
37 
38 void
39 libvarpd_panic(const char *fmt, ...)
40 {
41 	va_list ap;
42 
43 	/* Always save errno first! */
44 	varpd_panic_errno = errno;
45 	varpd_panic_thread = thr_self();
46 
47 	if (fmt != NULL) {
48 		va_start(ap, fmt);
49 		(void) vsnprintf(varpd_panic_buf, sizeof (varpd_panic_buf), fmt,
50 		    ap);
51 	}
52 	abort();
53 }
54