← Commit list

024622235

Eric Andersen
Eric Andersen
2003-07-22
FAILED Duration: 91s

Subject

Support reboot, halt, and poweroff independent of busybox init. Simplify and fixup some logic. -Erik

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

init/Config.in+3 -6
@@ -27,7 +27,7 @@ config CONFIG_FEATURE_INITRD
config CONFIG_FEATURE_INIT_COREDUMPS
bool " Support dumping core for child processes (debugging only)?"
- default y
+ default n
depends on CONFIG_INIT
help
If this option is enabled and the file /.init_enable_core
@@ -43,31 +43,28 @@ config CONFIG_FEATURE_EXTRA_QUIET
Prevent init from logging some messages to the console
during boot.
-# Some apps that are meaningless without BusyBox running as init
config CONFIG_HALT
bool "halt"
default y
- depends on CONFIG_INIT
help
- 'halt' tells the kernel to stop all processes and halt the system.
+ Stop all processes and halt the system.
config CONFIG_POWEROFF
bool "poweroff"
default y
- depends on CONFIG_INIT
help
Stop all processes and (try to) power off the system.
config CONFIG_REBOOT
bool "reboot"
default y
- depends on CONFIG_INIT
help
Stop all processes and reboot the system.
config CONFIG_MINIT
bool "minit"
default n
+ depends on ! CONFIG_INIT
help
Minimal init, based on minit v0.9.1. This is a simple
init replacement that handles starting/stopping services,
init/halt.c+18 -2
@@ -2,7 +2,6 @@
/*
* Mini halt implementation for busybox
*
- * Copyright (C) 1995, 1996 by Bruce Perens <[email protected]>.
* Copyright (C) 1999-2003 by Erik Andersen <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,12 +20,29 @@
*
*/
-#include "busybox.h"
#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <sys/reboot.h>
+#include "busybox.h"
#include "init_shared.h"
extern int halt_main(int argc, char **argv)
{
+ char *delay; /* delay in seconds before rebooting */
+
+ if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
+ sleep(atoi(delay));
+ }
+
+#ifndef CONFIG_INIT
+#ifndef RB_HALT_SYSTEM
+#define RB_HALT_SYSTEM 0xcdef0123
+#endif
+ return(bb_shutdown_system(RB_HALT_SYSTEM));
+#else
return kill_init(SIGUSR1);
+#endif
}
init/init_shared.c+79 -2
@@ -1,9 +1,35 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Stuff shared between init, reboot, halt, and poweroff
+ *
+ * Copyright (C) 1999-2003 by Erik Andersen <[email protected]>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <sys/reboot.h>
+#include <sys/reboot.h>
+#include <sys/syslog.h>
#include "busybox.h"
-
#include "init_shared.h"
-
extern int kill_init(int sig)
{
#ifdef CONFIG_FEATURE_INITRD
@@ -19,3 +45,54 @@ extern int kill_init(int sig)
return(kill(1, sig));
#endif
}
+
+#ifndef CONFIG_INIT
+#define LOG 0x1
+#define CONSOLE 0x2
+extern int bb_shutdown_system(unsigned long magic)
+{
+ int pri = LOG_KERN|LOG_NOTICE|LOG_FACMASK;
+ char *message;
+
+ /* Don't kill ourself */
+ signal(SIGTERM,SIG_IGN);
+ signal(SIGHUP,SIG_IGN);
+ setpgrp();
+
+ /* Allow Ctrl-Alt-Del to reboot system. */
+#ifndef RB_ENABLE_CAD
+#define RB_ENABLE_CAD 0x89abcdef
+#endif
+ reboot(RB_ENABLE_CAD);
+
+ openlog("shutdown", 0, pri);
+
+ message = "\n\rThe system is going down NOW !!\n";
+ syslog(pri, "%s", message);
+ fprintf(stdout, "%s", message);
+
+ sync();
+
+ /* Send signals to every process _except_ pid 1 */
+ message = "\rSending SIGTERM to all processes.\n";
+ syslog(pri, "%s", message);
+ fprintf(stdout, "%s", message);
+
+ kill(-1, SIGTERM);
+ sleep(1);
+ sync();
+
+ message = "\rSending SIGKILL to all processes.\n";
+ syslog(pri, "%s", message);
+ fprintf(stdout, "%s", message);
+
+ kill(-1, SIGKILL);
+ sleep(1);
+
+ sync();
+
+ reboot(magic);
+ return 0; /* Shrug */
+}
+#endif
+
init/init_shared.h+2 -0
@@ -1 +1,3 @@
extern int kill_init(int sig);
+extern int bb_shutdown_system(unsigned long magic);
+
init/poweroff.c+28 -2
@@ -2,7 +2,6 @@
/*
* Mini poweroff implementation for busybox
*
- * Copyright (C) 1995, 1996 by Bruce Perens <[email protected]>.
* Copyright (C) 1999-2003 by Erik Andersen <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,10 +20,37 @@
*
*/
-#include "busybox.h"
#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <sys/reboot.h>
+#include "busybox.h"
+#include "init_shared.h"
+
extern int poweroff_main(int argc, char **argv)
{
+ char *delay; /* delay in seconds before rebooting */
+
+ if(bb_getopt_ulflags(argc, argv, "d:", &delay)) {
+ sleep(atoi(delay));
+ }
+
+#ifndef CONFIG_INIT
+#ifndef RB_POWER_OFF
+#define RB_POWER_OFF 0x4321fedc
+#endif
+ return(bb_shutdown_system(RB_POWER_OFF));
+#else
return kill_init(SIGUSR2);
+#endif
}
+
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
init/reboot.c+6 -33
@@ -2,7 +2,6 @@
/*
* Mini reboot implementation for busybox
*
- * Copyright (C) 1995, 1996 by Bruce Perens <[email protected]>.
* Copyright (C) 1999-2003 by Erik Andersen <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
@@ -30,11 +29,6 @@
#include "init_shared.h"
-#ifndef RB_ENABLE_CAD
-static const int RB_ENABLE_CAD = 0x89abcdef;
-static const int RB_AUTOBOOT = 0x01234567;
-#endif
-
extern int reboot_main(int argc, char **argv)
{
char *delay; /* delay in seconds before rebooting */
@@ -43,34 +37,13 @@ extern int reboot_main(int argc, char **argv)
sleep(atoi(delay));
}
-#ifdef CONFIG_USER_INIT
- /* Don't kill ourself */
- signal(SIGTERM,SIG_IGN);
- signal(SIGHUP,SIG_IGN);
- setpgrp();
-
- /* Allow Ctrl-Alt-Del to reboot system. */
- reboot(RB_ENABLE_CAD);
-
- message(CONSOLE|LOG, "\n\rThe system is going down NOW !!\n");
- sync();
-
- /* Send signals to every process _except_ pid 1 */
- message(CONSOLE|LOG, "\rSending SIGTERM to all processes.\n");
- kill(-1, SIGTERM);
- sleep(1);
- sync();
-
- message(CONSOLE|LOG, "\rSending SIGKILL to all processes.\n");
- kill(-1, SIGKILL);
- sleep(1);
-
- sync();
-
- reboot(RB_AUTOBOOT);
- return 0; /* Shrug */
+#ifndef CONFIG_INIT
+#ifndef RB_AUTOBOOT
+#define RB_AUTOBOOT 0x01234567
+#endif
+ return(bb_shutdown_system(RB_AUTOBOOT));
#else
- return kill_init(SIGTERM);
+ return kill_init(SIGUSR2);
#endif
}