-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop.c
More file actions
31 lines (29 loc) · 1004 Bytes
/
stop.c
File metadata and controls
31 lines (29 loc) · 1004 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/reboot.h>
#include <unistd.h>
int main(int argc, char **argv) {
if (argc == 2 && !strcmp(argv[1], "halt"))
return reboot(RB_HALT_SYSTEM) < 0;
else if (argc == 2 && !strcmp(argv[1], "kexec"))
return reboot(RB_KEXEC) < 0;
else if (argc == 2 && !strcmp(argv[1], "poweroff"))
return reboot(RB_POWER_OFF) < 0;
else if (argc == 2 && !strcmp(argv[1], "reboot"))
return reboot(RB_AUTOBOOT) < 0;
else if (argc == 2 && !strcmp(argv[1], "suspend"))
return reboot(RB_SW_SUSPEND) < 0;
fprintf(stderr, "\
Usage: %s ACTION\n\
Actions:\n\
halt halt the machine\n\
kexec jump to a new kernel loaded for kexec\n\
poweroff switch off the machine\n\
reboot restart the machine\n\
suspend hibernate the machine to disk\n\
All actions are performed immediately without flushing buffers or a\n\
graceful shutdown. Data may be lost on unsynced mounted filesystems.\n\
", argv[0]);
return 64;
}