summaryrefslogtreecommitdiff
path: root/package/sash/src/reboot.c
blob: 8342ec992163430cc32e214503d3eaf48b6ed92c (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* shutdown.c:
 *
 * Copyright (C) 1998  Kenneth Albanowski <kjahds@kjahds.com>,
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * JUN/99 -- copied from shutdown.c to make new reboot command.
 *           (gerg@snapgear.com)
 * AUG/99 -- added delay option to reboot
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>

#include <sys/stat.h>
#include <dirent.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <signal.h>
#include <unistd.h>

#include <getopt.h>

#if __GNU_LIBRARY__ > 5
#include <sys/reboot.h>
#endif

int main(int argc, char *argv[])
{
	int delay = 0; /* delay in seconds before rebooting */
	int rc;
	int force = 0;
  
	while ((rc = getopt(argc, argv, "h?d:f")) > 0) {
		switch (rc) {
		case 'd':
			delay = atoi(optarg);
			break;
		case 'f':
			force = 1;
			break;
		case 'h':
		case '?':
		default:
			printf("usage: reboot [-h] [-d <delay>] [-f]\n");
			exit(0);
			break;
		}
	}

	if(delay > 0)
		sleep(delay);
#ifdef CONFIG_DISKtel
	printf("unmounting /home\n");
	if(umount("/home") != 0){
		printf("unmounting failed!!!\n");
	}
#endif

#ifdef CONFIG_USER_FLATFSD_FLATFSD
	if (!force) {
		/* Ask flatfsd to reboot us safely */
		execlp("flatfsd", "flatfsd", "-b", NULL);
		/* if this returns,  then force a reboot */
	}
#endif

	kill(1, SIGTSTP);
	sync();
	signal(SIGTERM,SIG_IGN);
	signal(SIGHUP,SIG_IGN);
	setpgrp();
	kill(-1, SIGTERM);
	sleep(1);
	kill(-1, SIGHUP);
	sleep(1);
	sync();
	sleep(1);
#if __GNU_LIBRARY__ > 5
	reboot(0x01234567);
#else
	reboot(0xfee1dead, 672274793, 0x01234567);
#endif
	exit(0); /* Shrug */
}