blob: 5ca8b588a15a56361b3afad1e054c351eb7aecdb [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersenc4996011999-10-20 22:08:37 +00002/*
3 * Mini reboot implementation for busybox
4 *
Eric Andersenc4996011999-10-20 22:08:37 +00005 * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
Eric Andersencb81e642003-07-14 21:21:08 +00006 * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
Eric Andersenc4996011999-10-20 22:08:37 +00007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
Eric Andersencc8ed391999-10-05 16:24:54 +000024#include <signal.h>
Eric Andersen34fd00a2002-09-17 08:40:12 +000025#include <stdlib.h>
26#include <unistd.h>
27#include <getopt.h>
Eric Andersen85e5e722003-07-22 08:56:55 +000028#include <sys/reboot.h>
Glenn L McGrath4e05b9b2002-12-07 23:14:40 +000029#include "busybox.h"
Eric Andersenb01ed652003-06-27 17:08:15 +000030#include "init_shared.h"
31
Glenn L McGrath4e05b9b2002-12-07 23:14:40 +000032
Eric Andersen34fd00a2002-09-17 08:40:12 +000033#ifndef RB_ENABLE_CAD
34static const int RB_ENABLE_CAD = 0x89abcdef;
35static const int RB_AUTOBOOT = 0x01234567;
36#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000037
Erik Andersene49d5ec2000-02-08 19:58:47 +000038extern int reboot_main(int argc, char **argv)
Eric Andersencc8ed391999-10-05 16:24:54 +000039{
Eric Andersenb01ed652003-06-27 17:08:15 +000040 char *delay; /* delay in seconds before rebooting */
Eric Andersen34fd00a2002-09-17 08:40:12 +000041
Eric Andersenb01ed652003-06-27 17:08:15 +000042 if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
43 sleep(atoi(delay));
Eric Andersen34fd00a2002-09-17 08:40:12 +000044 }
45
Eric Andersen34fd00a2002-09-17 08:40:12 +000046#ifdef CONFIG_USER_INIT
47 /* Don't kill ourself */
48 signal(SIGTERM,SIG_IGN);
49 signal(SIGHUP,SIG_IGN);
50 setpgrp();
51
52 /* Allow Ctrl-Alt-Del to reboot system. */
Eric Andersen85e5e722003-07-22 08:56:55 +000053 reboot(RB_ENABLE_CAD);
Eric Andersen34fd00a2002-09-17 08:40:12 +000054
55 message(CONSOLE|LOG, "\n\rThe system is going down NOW !!\n");
56 sync();
57
58 /* Send signals to every process _except_ pid 1 */
59 message(CONSOLE|LOG, "\rSending SIGTERM to all processes.\n");
60 kill(-1, SIGTERM);
61 sleep(1);
62 sync();
63
64 message(CONSOLE|LOG, "\rSending SIGKILL to all processes.\n");
65 kill(-1, SIGKILL);
66 sleep(1);
67
68 sync();
Eric Andersen34fd00a2002-09-17 08:40:12 +000069
Eric Andersen85e5e722003-07-22 08:56:55 +000070 reboot(RB_AUTOBOOT);
Eric Andersenb01ed652003-06-27 17:08:15 +000071 return 0; /* Shrug */
Eric Andersen34fd00a2002-09-17 08:40:12 +000072#else
Eric Andersenb01ed652003-06-27 17:08:15 +000073 return kill_init(SIGTERM);
Eric Andersen34fd00a2002-09-17 08:40:12 +000074#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000075}
Erik Andersen029011b2000-03-04 21:19:32 +000076
77/*
78Local Variables:
79c-file-style: "linux"
80c-basic-offset: 4
81tab-width: 4
82End:
83*/