Magellan Linux

Annotation of /trunk/mkinitrd-magellan/klibc/usr/utils/halt.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (hide annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1552 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 niro 532 #include <stdlib.h>
2     #include <unistd.h>
3     #include <signal.h>
4     #include <sys/reboot.h>
5     #include <klibc/compiler.h>
6    
7     static __noreturn usage(void)
8     {
9     static char mesg[] = "Usage: {halt|reboot|poweroff} [-n]\n";
10     write(2, mesg, sizeof(mesg) - 1);
11     exit(1);
12     }
13    
14     int main(int argc, char *argv[])
15     {
16     int cmd = 0; /* initalize to shut gcc up */
17     int do_sync = 1;
18     char *ptr, *ptr2;
19    
20     /* Which action (program name)? */
21     ptr2 = ptr = argv[0];
22     while (*ptr2)
23     if (*ptr2++ == '/')
24     ptr = ptr2;
25     if (*ptr == 'r')
26     cmd = LINUX_REBOOT_CMD_RESTART;
27     else if (*ptr == 'h')
28     cmd = LINUX_REBOOT_CMD_HALT;
29     else if (*ptr == 'p')
30     cmd = LINUX_REBOOT_CMD_POWER_OFF;
31     else
32     usage();
33    
34     /* Walk options */
35     while (*++argv && **argv == '-')
36     switch (*++*argv) {
37     case 'f': break; /* -f assumed */
38     case 'n': do_sync = 0; break;
39     default:
40     usage();
41     }
42     if (*argv)
43     usage(); /* any args == error */
44    
45     if (do_sync)
46     sync();
47     reboot(LINUX_REBOOT_CMD_CAD_OFF); /* Enable CTRL+ALT+DEL */
48     if (!reboot(cmd)) {
49     /* Success. Currently, CMD_HALT returns, so stop the world */
50     /* kill(-1, SIGSTOP); */
51     kill(getpid(), SIGSTOP);
52     }
53     write(2, "failed.\n", 8);
54     return 1;
55     }