Project

General

Profile

Bug #647 » vkhalt-HEAD.patch

c.turner, 06/17/2007 04:26 PM

View differences:

share/man/man7/vkernel.7 17 Jun 2007 04:05:58 -0000
202 206
.Xr tap 4
203 207
device.
204 208
.Sh SIGNALS
205
The virtual kernel enables all terminal signals while in
206
.Xr ddb 4
207
mode but only enables
209
The virtual kernel only enables 
210
.Dv SIGQUIT
211
and 
212
.Dv SIGTERM 
213
while operating in regular console mode. 
214
Sending 
208 215
.Ql \&^\e
209 216
.Pq Dv SIGQUIT
210
while operating as a console which causes the virtual kernel to enter its
211
internal
217
to the virtual kernel causes the virtual kernel to enter its internal
212 218
.Xr ddb 4
213
debugger.
219
debugger and re-enable all other terminal signals. 
220
Sending
221
.Dv SIGTERM 
222
to the virtual kernel triggers a clean shutdown by passing a 
223
.Dv SIGUSR2 
224
to the virtual kernel's 
225
.Xr init 8
226
process.
214 227
.Sh DEBUGGING
215 228
It is possible to directly gdb the virtual kernel's process.
216 229
It is recommended that you do a
sys/platform/vkernel/i386/exception.c 16 Jun 2007 23:08:05 -0000
39 39
#include <sys/types.h>
40 40
#include <sys/systm.h>
41 41
#include <sys/kernel.h>
42
#include <sys/kthread.h>
43
#include <sys/reboot.h>
42 44
#include <ddb/ddb.h>
43 45

  
44 46
#include <sys/thread2.h>
......
56 58
static void exc_debugger(int signo, siginfo_t *info, void *ctx);
57 59
#endif
58 60

  
61
/* signal shutdown thread misc. */
62

  
63
static void sigshutdown_daemon( void );
64
static struct thread *sigshutdown_thread;
65
static struct kproc_desc sigshut_kp = {
66
	"sigshutdown", sigshutdown_daemon, &sigshutdown_thread
67
};
68

  
59 69
void
60 70
init_exceptions(void)
61 71
{
......
67 77
	sigemptyset(&sa.sa_mask);
68 78
	sigaction(SIGSEGV, &sa, NULL);
69 79
	sigaction(SIGTRAP, &sa, NULL);
80

  
70 81
#ifdef DDB
71 82
	sa.sa_sigaction = exc_debugger;
72 83
	sigaction(SIGQUIT, &sa, NULL);
73 84
#endif
85

  
86
	bzero(&sa, sizeof(sa));
87
	sigemptyset(&sa.sa_mask);
88
	sa.sa_flags |= SA_MAILBOX | SA_NODEFER;
89
	sa.sa_mailbox = &mdcpu->gd_shutdown;
90
	sigaction(SIGTERM, &sa, NULL);
74 91
}
75 92

  
76 93
/*
......
95 112
	splz();
96 113
}
97 114

  
115
/*
116
 * This function runs in a thread dedicated to external shutdown signals.
117
 *
118
 * Currently, when a vkernel recieves a SIGTERM, either the VKERNEL init(8) 
119
 * is signaled with SIGUSR2, or the VKERNEL simply shuts down, preventing
120
 * fsck's when the VKERNEL is restarted.
121
 */ 
122
static void
123
sigshutdown_daemon( void )
124
{
125
	while (mdcpu->gd_shutdown == 0) {
126
		tsleep(&mdcpu->gd_shutdown, 0, "sswait", 0);
127
	}
128
	mdcpu->gd_shutdown = 0;
129
	kprintf("Caught SIGTERM from host system. Shutting down...\n");
130
	if (initproc != NULL) {
131
		ksignal(initproc, SIGUSR2);
132
	}
133
	else {
134
		reboot(RB_POWEROFF);
135
	}	
136
}
137
SYSINIT(sigshutdown, SI_BOOT2_PROC0, SI_ORDER_ANY, 
138
	kproc_start, &sigshut_kp); 
139

  
98 140
#ifdef DDB
99 141

  
100 142
static void
sys/platform/vkernel/include/globaldata.h 10 Jun 2007 21:10:26 -0000
83 83
	int		gd_spending;	/* software interrupt pending */
84 84
	int		gd_sdelayed;	/* delayed software ints */
85 85
	int		gd_currentldt;
86
	int		gd_mailbox;	/* signal delivery mailbox */
86
	int		gd_mailbox;	/* I/O signal delivery mailbox */
87
	int		gd_shutdown;    /* Shutdown signal delivery mailbox */
87 88
	u_int		unused001;
88 89
	u_int		gd_other_cpus;
89 90
	u_int		gd_ss_eflags;
sys/platform/vkernel/platform/kqueue.c 17 Jun 2007 16:19:18 -0000
107 107
	int n;
108 108
	int i;
109 109

  
110
	/*
111
	 * we only need to wake up our shutdown thread once.  
112
	 * Keep it non-zero so the shutdown thread can detect it.
113
	 */
114

  
115
	if (mdcpu->gd_shutdown > 0) {
116
		mdcpu->gd_shutdown = -1;
117
		wakeup(&mdcpu->gd_shutdown);
118
	}
119

  
110 120
	if (gd->gd_mailbox == 0)
111 121
		return;
112 122
	gd->gd_mailbox = 0;
(4-4/4)