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