Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini reboot implementation for busybox |
| 4 | * |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 5 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. |
Eric Andersen | cb81e64 | 2003-07-14 21:21:08 +0000 | [diff] [blame] | 6 | * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 7 | * |
| 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 Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 24 | #include <signal.h> |
Eric Andersen | 34fd00a | 2002-09-17 08:40:12 +0000 | [diff] [blame] | 25 | #include <stdlib.h> |
| 26 | #include <unistd.h> |
| 27 | #include <getopt.h> |
Eric Andersen | 85e5e72 | 2003-07-22 08:56:55 +0000 | [diff] [blame^] | 28 | #include <sys/reboot.h> |
Glenn L McGrath | 4e05b9b | 2002-12-07 23:14:40 +0000 | [diff] [blame] | 29 | #include "busybox.h" |
Eric Andersen | b01ed65 | 2003-06-27 17:08:15 +0000 | [diff] [blame] | 30 | #include "init_shared.h" |
| 31 | |
Glenn L McGrath | 4e05b9b | 2002-12-07 23:14:40 +0000 | [diff] [blame] | 32 | |
Eric Andersen | 34fd00a | 2002-09-17 08:40:12 +0000 | [diff] [blame] | 33 | #ifndef RB_ENABLE_CAD |
| 34 | static const int RB_ENABLE_CAD = 0x89abcdef; |
| 35 | static const int RB_AUTOBOOT = 0x01234567; |
| 36 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 37 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 38 | extern int reboot_main(int argc, char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 39 | { |
Eric Andersen | b01ed65 | 2003-06-27 17:08:15 +0000 | [diff] [blame] | 40 | char *delay; /* delay in seconds before rebooting */ |
Eric Andersen | 34fd00a | 2002-09-17 08:40:12 +0000 | [diff] [blame] | 41 | |
Eric Andersen | b01ed65 | 2003-06-27 17:08:15 +0000 | [diff] [blame] | 42 | if(bb_getopt_ulflags(argc, argv, "d:", &delay)) { |
| 43 | sleep(atoi(delay)); |
Eric Andersen | 34fd00a | 2002-09-17 08:40:12 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Eric Andersen | 34fd00a | 2002-09-17 08:40:12 +0000 | [diff] [blame] | 46 | #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 Andersen | 85e5e72 | 2003-07-22 08:56:55 +0000 | [diff] [blame^] | 53 | reboot(RB_ENABLE_CAD); |
Eric Andersen | 34fd00a | 2002-09-17 08:40:12 +0000 | [diff] [blame] | 54 | |
| 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 Andersen | 34fd00a | 2002-09-17 08:40:12 +0000 | [diff] [blame] | 69 | |
Eric Andersen | 85e5e72 | 2003-07-22 08:56:55 +0000 | [diff] [blame^] | 70 | reboot(RB_AUTOBOOT); |
Eric Andersen | b01ed65 | 2003-06-27 17:08:15 +0000 | [diff] [blame] | 71 | return 0; /* Shrug */ |
Eric Andersen | 34fd00a | 2002-09-17 08:40:12 +0000 | [diff] [blame] | 72 | #else |
Eric Andersen | b01ed65 | 2003-06-27 17:08:15 +0000 | [diff] [blame] | 73 | return kill_init(SIGTERM); |
Eric Andersen | 34fd00a | 2002-09-17 08:40:12 +0000 | [diff] [blame] | 74 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 75 | } |
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | Local Variables: |
| 79 | c-file-style: "linux" |
| 80 | c-basic-offset: 4 |
| 81 | tab-width: 4 |
| 82 | End: |
| 83 | */ |