-
Notifications
You must be signed in to change notification settings - Fork 0
/
stop.c
32 lines (30 loc) · 1.01 KB
/
stop.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.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);
else if (argc == 2 && !strcmp(argv[1], "kexec"))
return reboot(RB_KEXEC);
else if (argc == 2 && !strcmp(argv[1], "poweroff"))
return fork() > 0 ? pause() : reboot(RB_POWER_OFF);
else if (argc == 2 && !strcmp(argv[1], "reboot"))
return reboot(RB_AUTOBOOT);
else if (argc == 2 && !strcmp(argv[1], "suspend"))
return reboot(RB_SW_SUSPEND);
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 EX_USAGE;
}