reboot.c 865 Bytes
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
/* 
Jeff Dike's avatar
Jeff Dike committed
2
 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Linus Torvalds's avatar
Linus Torvalds committed
3
4
5
6
 * Licensed under the GPL
 */

#include "linux/sched.h"
Jeff Dike's avatar
Jeff Dike committed
7
#include "kern_util.h"
Linus Torvalds's avatar
Linus Torvalds committed
8
#include "os.h"
9
#include "skas.h"
Linus Torvalds's avatar
Linus Torvalds committed
10

11
12
void (*pm_power_off)(void);

Linus Torvalds's avatar
Linus Torvalds committed
13
14
static void kill_off_processes(void)
{
Jeff Dike's avatar
Jeff Dike committed
15
	if (proc_mm)
16
17
18
19
20
21
22
23
24
		/*
		 * FIXME: need to loop over userspace_pids
		 */
		os_kill_ptraced_process(userspace_pid[0], 1);
	else {
		struct task_struct *p;
		int pid, me;

		me = os_getpid();
Jeff Dike's avatar
Jeff Dike committed
25
26
		for_each_process(p) {
			if (p->mm == NULL)
27
28
				continue;

29
			pid = p->mm->context.id.u.pid;
30
31
32
			os_kill_ptraced_process(pid, 1);
		}
	}
Linus Torvalds's avatar
Linus Torvalds committed
33
34
35
36
}

void uml_cleanup(void)
{
Jeff Dike's avatar
Jeff Dike committed
37
	kmalloc_ok = 0;
Linus Torvalds's avatar
Linus Torvalds committed
38
	do_uml_exitcalls();
39
	kill_off_processes();
Linus Torvalds's avatar
Linus Torvalds committed
40
41
42
43
}

void machine_restart(char * __unused)
{
Jeff Dike's avatar
Jeff Dike committed
44
	uml_cleanup();
Jeff Dike's avatar
Jeff Dike committed
45
	reboot_skas();
Linus Torvalds's avatar
Linus Torvalds committed
46
47
48
49
}

void machine_power_off(void)
{
Jeff Dike's avatar
Jeff Dike committed
50
	uml_cleanup();
Jeff Dike's avatar
Jeff Dike committed
51
	halt_skas();
Linus Torvalds's avatar
Linus Torvalds committed
52
53
54
55
56
57
}

void machine_halt(void)
{
	machine_power_off();
}