Repository navigation
Expand file tree
/
Copy pathmisc.c
More file actions
124 lines (101 loc) · 2.97 KB
/
Copy pathmisc.c
File metadata and controls
124 lines (101 loc) · 2.97 KB
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
/* Miscellaneous system calls. Author: Kees J. Bot
* 31 Mar 2000
*
* The entry points into this file are:
* do_reboot: kill all processes, then reboot system
* do_svrctl: memory manager control
*/
#include "mm.h"
#include <minix/callnr.h>
#include <signal.h>
#include <sys/svrctl.h>
#include "mproc.h"
#include "param.h"
/*=====================================================================*
* do_reboot *
*=====================================================================*/
PUBLIC int do_reboot()
{
register struct mproc *rmp = mp;
char monitor_code[32*sizeof(char *)];
if (rmp->mp_effuid != SUPER_USER) return(EPERM);
switch (reboot_flag) {
case RBT_HALT:
case RBT_REBOOT:
case RBT_PANIC:
case RBT_RESET:
break;
case RBT_MONITOR:
if (reboot_size >= sizeof(monitor_code)) return(EINVAL);
if (sys_copy(who, D, (phys_bytes) reboot_code,
MM_PROC_NR, D, (phys_bytes) monitor_code,
(phys_bytes) (reboot_size+1)) != OK) return(EFAULT);
if (monitor_code[reboot_size] != 0) return(EINVAL);
break;
default:
return(EINVAL);
}
/* Kill all processes except init. */
check_sig(-1, SIGKILL);
tell_fs(REBOOT,0,0,0); /* tell FS to prepare for shutdown */
sys_abort(reboot_flag, MM_PROC_NR, monitor_code, reboot_size);
/* NOTREACHED */
}
/*=====================================================================*
* do_svrctl *
*=====================================================================*/
PUBLIC int do_svrctl()
{
int req;
vir_bytes ptr;
req = svrctl_req;
ptr = (vir_bytes) svrctl_argp;
/* Is the request for the kernel? */
if (((req >> 8) & 0xFF) == 'S') {
return(sys_sysctl(who, req, mp->mp_effuid == SUPER_USER, ptr));
}
switch(req) {
case MMSIGNON: {
/* A user process becomes a task. Simulate an exit by
* releasing a waiting parent and disinheriting children.
*/
struct mproc *rmp;
pid_t pidarg;
if (mp->mp_effuid != SUPER_USER) return(EPERM);
rmp = &mproc[mp->mp_parent];
tell_fs(EXIT, who, 0, 0);
pidarg = rmp->mp_wpid;
if ((rmp->mp_flags & WAITING) && (pidarg == -1
|| pidarg == mp->mp_pid || -pidarg == mp->mp_procgrp))
{
/* Wake up the parent. */
rmp->reply_res2 = 0;
setreply(mp->mp_parent, mp->mp_pid);
rmp->mp_flags &= ~WAITING;
}
/* Disinherit children. */
for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
if (rmp->mp_flags & IN_USE && rmp->mp_parent == who) {
rmp->mp_parent = INIT_PROC_NR;
}
}
/* Become like MM and FS. */
mp->mp_pid = mp->mp_procgrp = 0;
mp->mp_parent = 0;
return(OK); }
#if ENABLE_SWAP
case MMSWAPON: {
struct mmswapon swapon;
if (mp->mp_effuid != SUPER_USER) return(EPERM);
if (sys_copy(who, D, (phys_bytes) ptr,
MM_PROC_NR, D, (phys_bytes) &swapon,
(phys_bytes) sizeof(swapon)) != OK) return(EFAULT);
return(swap_on(swapon.file, swapon.offset, swapon.size)); }
case MMSWAPOFF: {
if (mp->mp_effuid != SUPER_USER) return(EPERM);
return(swap_off()); }
#endif /* SWAP */
default:
return(EINVAL);
}
}