source: trunk/minix/commands/reboot/tinyhalt.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.0 KB
Line 
1/* tinyhalt 1.0 - small forerunner Author: Kees J. Bot
2 *
3 * Disk space on the root file system is a scarce resource. This little
4 * program sits in /sbin. It normally calls the real halt/reboot, but if
5 * that isn't available then it simply calls reboot(). Can't do any logging
6 * of the event anyhow.
7 */
8#define nil 0
9#include <sys/types.h>
10#include <stdlib.h>
11#include <string.h>
12#include <fcntl.h>
13#include <unistd.h>
14#include <signal.h>
15
16int main(int argc, char **argv)
17{
18 int flag;
19 char *prog;
20 char *reboot_code = "delay; boot";
21
22 /* Try to run the real McCoy. */
23#if __minix_vmd
24 execv("/usr/sbin/halt", argv);
25#else
26 execv("/usr/bin/halt", argv);
27#endif
28
29 if ((prog = strrchr(*argv,'/')) == nil) prog= argv[0]; else prog++;
30
31 sleep(1); /* Not too fast. */
32 signal(SIGHUP, SIG_IGN);
33 signal(SIGTERM, SIG_IGN);
34 kill(1, SIGTERM);
35 kill(-1, SIGTERM);
36 sleep(1);
37
38 reboot(strcmp(prog, "reboot") == 0 ? RBT_MONITOR : RBT_HALT,
39 reboot_code, strlen(reboot_code));
40
41 write(2, "reboot call failed\n", 19);
42 return 1;
43}
Note: See TracBrowser for help on using the repository browser.