-
Notifications
You must be signed in to change notification settings - Fork 0
/
halt.patch
79 lines (78 loc) · 1.82 KB
/
halt.patch
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
--- kinit/Makefile.fix6 2010-06-01 17:39:37.000000000 +0400
+++ kinit/Makefile 2010-06-01 17:40:23.000000000 +0400
@@ -15,8 +15,9 @@ subdirs += fstype
subdirs += resume
subdirs += md_run
subdirs += replace
subdirs += showenv
+subdirs += halt
# Additional include paths files
CFLAGS += -I$(srctree)/$(src)/fstype \
-I$(srctree)/$(src)/ipconfig \
--- /dev/null 2010-05-31 14:10:14.991006661 +0400
+++ kinit/halt/Makefile 2010-06-01 17:41:49.000000000 +0400
@@ -0,0 +1,4 @@
+prog = halt
+objs = halt.o
+
+include $(CURDIR)/../rules.mk
--- /dev/null 2010-05-31 14:10:14.991006661 +0400
+++ kinit/halt/halt.c 2010-06-01 17:37:39.000000000 +0400
@@ -0,0 +1,57 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <linux/reboot.h>
+
+static usage(void)
+{
+ static char mesg[] = "Usage: {halt|reboot|poweroff} [-n]\n";
+ write(2, mesg, sizeof(mesg) - 1);
+ exit(1);
+}
+
+int main(int argc, char *argv[])
+{
+ int cmd = 0; /* initalize to shut gcc up */
+ int do_sync = 1;
+ char *ptr, *ptr2;
+
+ /* Which action (program name)? */
+ ptr2 = ptr = argv[0];
+ while (*ptr2)
+ if (*ptr2++ == '/')
+ ptr = ptr2;
+ if (*ptr == 'r')
+ cmd = LINUX_REBOOT_CMD_RESTART;
+ else if (*ptr == 'h')
+ cmd = LINUX_REBOOT_CMD_HALT;
+ else if (*ptr == 'p')
+ cmd = LINUX_REBOOT_CMD_POWER_OFF;
+ else
+ usage();
+
+ /* Walk options */
+ while (*++argv && **argv == '-')
+ switch (*++*argv) {
+ case 'f':
+ break; /* -f assumed */
+ case 'n':
+ do_sync = 0;
+ break;
+ default:
+ usage();
+ }
+ if (*argv)
+ usage(); /* any args == error */
+
+ if (do_sync)
+ sync();
+ reboot(LINUX_REBOOT_CMD_CAD_OFF); /* Enable CTRL+ALT+DEL */
+ if (!reboot(cmd)) {
+ /* Success. Currently, CMD_HALT returns, so stop the world */
+ /* kill(-1, SIGSTOP); */
+ kill(getpid(), SIGSTOP);
+ }
+ write(2, "failed.\n", 8);
+ return 1;
+}