[BusyBox-cvs] busybox/init Config.in, 1.5, 1.6 halt.c, 1.22, 1.23 init_shared.c, 1.1, 1.2 init_shared.h, 1.1, 1.2 poweroff.c, 1.19, 1.20 reboot.c, 1.29, 1.30

Erik Andersen andersen at busybox.net
Tue Jul 22 09:41:44 UTC 2003


Update of /var/cvs/busybox/init
In directory winder:/tmp/cvs-serv29521/init

Modified Files:
	Config.in halt.c init_shared.c init_shared.h poweroff.c 
	reboot.c 
Log Message:
Support reboot, halt, and poweroff independent of busybox init.
Simplify and fixup some logic.
 -Erik


Index: Config.in
===================================================================
RCS file: /var/cvs/busybox/init/Config.in,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Config.in	14 Jul 2003 19:36:57 -0000	1.5
+++ Config.in	22 Jul 2003 09:41:39 -0000	1.6
@@ -27,7 +27,7 @@
 
 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 @@
 	  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,

Index: halt.c
===================================================================
RCS file: /var/cvs/busybox/init/halt.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- halt.c	14 Jul 2003 21:20:53 -0000	1.22
+++ halt.c	22 Jul 2003 09:41:39 -0000	1.23
@@ -2,7 +2,6 @@
 /*
  * Mini halt implementation for busybox
  *
- * Copyright (C) 1995, 1996 by Bruce Perens <bruce at pixar.com>.
  * Copyright (C) 1999-2003 by Erik Andersen <andersen at codepoet.org>
  *
  * 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
 }

Index: init_shared.c
===================================================================
RCS file: /var/cvs/busybox/init/init_shared.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- init_shared.c	27 Jun 2003 17:08:15 -0000	1.1
+++ init_shared.c	22 Jul 2003 09:41:39 -0000	1.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 <andersen at codepoet.org>
+ *
+ * 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 @@
 	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
+

Index: init_shared.h
===================================================================
RCS file: /var/cvs/busybox/init/init_shared.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- init_shared.h	27 Jun 2003 17:08:15 -0000	1.1
+++ init_shared.h	22 Jul 2003 09:41:39 -0000	1.2
@@ -1 +1,3 @@
 extern int kill_init(int sig);
+extern int bb_shutdown_system(unsigned long magic);
+

Index: poweroff.c
===================================================================
RCS file: /var/cvs/busybox/init/poweroff.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- poweroff.c	14 Jul 2003 21:20:53 -0000	1.19
+++ poweroff.c	22 Jul 2003 09:41:39 -0000	1.20
@@ -2,7 +2,6 @@
 /*
  * Mini poweroff implementation for busybox
  *
- * Copyright (C) 1995, 1996 by Bruce Perens <bruce at pixar.com>.
  * Copyright (C) 1999-2003 by Erik Andersen <andersen at codepoet.org>
  *
  * 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:
+*/

Index: reboot.c
===================================================================
RCS file: /var/cvs/busybox/init/reboot.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- reboot.c	22 Jul 2003 08:56:45 -0000	1.29
+++ reboot.c	22 Jul 2003 09:41:39 -0000	1.30
@@ -2,7 +2,6 @@
 /*
  * Mini reboot implementation for busybox
  *
- * Copyright (C) 1995, 1996 by Bruce Perens <bruce at pixar.com>.
  * Copyright (C) 1999-2003 by Erik Andersen <andersen at codepoet.org>
  *
  * 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 @@
 		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
 }
 




More information about the busybox-cvs mailing list