summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2010-11-02 20:13:03 +0100
committerDenys Vlasenko2010-11-02 20:13:03 +0100
commitdb5fe62b6d9977304b864f961dae71232091b26c (patch)
treee69e9efc17a3b0feae78118eb14d653cfa47e259
parent4d4d1a015f351816982e61a7f7dc861bfe06ca78 (diff)
downloadbusybox-db5fe62b6d9977304b864f961dae71232091b26c.zip
busybox-db5fe62b6d9977304b864f961dae71232091b26c.tar.gz
init: if PID!=1, show clearer error message. move usage text closer to main()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/usage.src.h3
-rw-r--r--init/init.c271
2 files changed, 137 insertions, 137 deletions
diff --git a/include/usage.src.h b/include/usage.src.h
index 6973c93..37b9d07 100644
--- a/include/usage.src.h
+++ b/include/usage.src.h
@@ -2044,9 +2044,6 @@ INSERT
#define linux64_trivial_usage NOUSAGE_STR
#define linux64_full_usage ""
-#define linuxrc_trivial_usage NOUSAGE_STR
-#define linuxrc_full_usage ""
-
#define setarch_trivial_usage \
"personality PROG ARGS"
#define setarch_full_usage "\n\n" \
diff --git a/init/init.c b/init/init.c
index a7bbd5e..0a0d503 100644
--- a/init/init.c
+++ b/init/init.c
@@ -108,138 +108,6 @@
//config: Note that on Linux, init attempts to detect serial terminal and
//config: sets TERM to "vt102" if one is found.
-//usage:#define init_trivial_usage
-//usage: ""
-//usage:#define init_full_usage "\n\n"
-//usage: "Init is the parent of all processes"
-//usage:
-//usage:#define init_notes_usage
-//usage: "This version of init is designed to be run only by the kernel.\n"
-//usage: "\n"
-//usage: "BusyBox init doesn't support multiple runlevels. The runlevels field of\n"
-//usage: "the /etc/inittab file is completely ignored by BusyBox init. If you want\n"
-//usage: "runlevels, use sysvinit.\n"
-//usage: "\n"
-//usage: "BusyBox init works just fine without an inittab. If no inittab is found,\n"
-//usage: "it has the following default behavior:\n"
-//usage: "\n"
-//usage: " ::sysinit:/etc/init.d/rcS\n"
-//usage: " ::askfirst:/bin/sh\n"
-//usage: " ::ctrlaltdel:/sbin/reboot\n"
-//usage: " ::shutdown:/sbin/swapoff -a\n"
-//usage: " ::shutdown:/bin/umount -a -r\n"
-//usage: " ::restart:/sbin/init\n"
-//usage: "\n"
-//usage: "if it detects that /dev/console is _not_ a serial console, it will also run:\n"
-//usage: "\n"
-//usage: " tty2::askfirst:/bin/sh\n"
-//usage: " tty3::askfirst:/bin/sh\n"
-//usage: " tty4::askfirst:/bin/sh\n"
-//usage: "\n"
-//usage: "If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n"
-//usage: "\n"
-//usage: " <id>:<runlevels>:<action>:<process>\n"
-//usage: "\n"
-//usage: " <id>:\n"
-//usage: "\n"
-//usage: " WARNING: This field has a non-traditional meaning for BusyBox init!\n"
-//usage: " The id field is used by BusyBox init to specify the controlling tty for\n"
-//usage: " the specified process to run on. The contents of this field are\n"
-//usage: " appended to \"/dev/\" and used as-is. There is no need for this field to\n"
-//usage: " be unique, although if it isn't you may have strange results. If this\n"
-//usage: " field is left blank, the controlling tty is set to the console. Also\n"
-//usage: " note that if BusyBox detects that a serial console is in use, then only\n"
-//usage: " entries whose controlling tty is either the serial console or /dev/null\n"
-//usage: " will be run. BusyBox init does nothing with utmp. We don't need no\n"
-//usage: " stinkin' utmp.\n"
-//usage: "\n"
-//usage: " <runlevels>:\n"
-//usage: "\n"
-//usage: " The runlevels field is completely ignored.\n"
-//usage: "\n"
-//usage: " <action>:\n"
-//usage: "\n"
-//usage: " Valid actions include: sysinit, respawn, askfirst, wait,\n"
-//usage: " once, restart, ctrlaltdel, and shutdown.\n"
-//usage: "\n"
-//usage: " The available actions can be classified into two groups: actions\n"
-//usage: " that are run only once, and actions that are re-run when the specified\n"
-//usage: " process exits.\n"
-//usage: "\n"
-//usage: " Run only-once actions:\n"
-//usage: "\n"
-//usage: " 'sysinit' is the first item run on boot. init waits until all\n"
-//usage: " sysinit actions are completed before continuing. Following the\n"
-//usage: " completion of all sysinit actions, all 'wait' actions are run.\n"
-//usage: " 'wait' actions, like 'sysinit' actions, cause init to wait until\n"
-//usage: " the specified task completes. 'once' actions are asynchronous,\n"
-//usage: " therefore, init does not wait for them to complete. 'restart' is\n"
-//usage: " the action taken to restart the init process. By default this should\n"
-//usage: " simply run /sbin/init, but can be a script which runs pivot_root or it\n"
-//usage: " can do all sorts of other interesting things. The 'ctrlaltdel' init\n"
-//usage: " actions are run when the system detects that someone on the system\n"
-//usage: " console has pressed the CTRL-ALT-DEL key combination. Typically one\n"
-//usage: " wants to run 'reboot' at this point to cause the system to reboot.\n"
-//usage: " Finally the 'shutdown' action specifies the actions to taken when\n"
-//usage: " init is told to reboot. Unmounting filesystems and disabling swap\n"
-//usage: " is a very good here.\n"
-//usage: "\n"
-//usage: " Run repeatedly actions:\n"
-//usage: "\n"
-//usage: " 'respawn' actions are run after the 'once' actions. When a process\n"
-//usage: " started with a 'respawn' action exits, init automatically restarts\n"
-//usage: " it. Unlike sysvinit, BusyBox init does not stop processes from\n"
-//usage: " respawning out of control. The 'askfirst' actions acts just like\n"
-//usage: " respawn, except that before running the specified process it\n"
-//usage: " displays the line \"Please press Enter to activate this console.\"\n"
-//usage: " and then waits for the user to press enter before starting the\n"
-//usage: " specified process.\n"
-//usage: "\n"
-//usage: " Unrecognized actions (like initdefault) will cause init to emit an\n"
-//usage: " error message, and then go along with its business. All actions are\n"
-//usage: " run in the order they appear in /etc/inittab.\n"
-//usage: "\n"
-//usage: " <process>:\n"
-//usage: "\n"
-//usage: " Specifies the process to be executed and its command line.\n"
-//usage: "\n"
-//usage: "Example /etc/inittab file:\n"
-//usage: "\n"
-//usage: " # This is run first except when booting in single-user mode\n"
-//usage: " #\n"
-//usage: " ::sysinit:/etc/init.d/rcS\n"
-//usage: " \n"
-//usage: " # /bin/sh invocations on selected ttys\n"
-//usage: " #\n"
-//usage: " # Start an \"askfirst\" shell on the console (whatever that may be)\n"
-//usage: " ::askfirst:-/bin/sh\n"
-//usage: " # Start an \"askfirst\" shell on /dev/tty2-4\n"
-//usage: " tty2::askfirst:-/bin/sh\n"
-//usage: " tty3::askfirst:-/bin/sh\n"
-//usage: " tty4::askfirst:-/bin/sh\n"
-//usage: " \n"
-//usage: " # /sbin/getty invocations for selected ttys\n"
-//usage: " #\n"
-//usage: " tty4::respawn:/sbin/getty 38400 tty4\n"
-//usage: " tty5::respawn:/sbin/getty 38400 tty5\n"
-//usage: " \n"
-//usage: " \n"
-//usage: " # Example of how to put a getty on a serial line (for a terminal)\n"
-//usage: " #\n"
-//usage: " #::respawn:/sbin/getty -L ttyS0 9600 vt100\n"
-//usage: " #::respawn:/sbin/getty -L ttyS1 9600 vt100\n"
-//usage: " #\n"
-//usage: " # Example how to put a getty on a modem line\n"
-//usage: " #::respawn:/sbin/getty 57600 ttyS2\n"
-//usage: " \n"
-//usage: " # Stuff to do when restarting the init process\n"
-//usage: " ::restart:/sbin/init\n"
-//usage: " \n"
-//usage: " # Stuff to do before rebooting\n"
-//usage: " ::ctrlaltdel:/sbin/reboot\n"
-//usage: " ::shutdown:/bin/umount -a -r\n"
-//usage: " ::shutdown:/sbin/swapoff -a\n"
-
#include "libbb.h"
#include <syslog.h>
#include <paths.h>
@@ -1095,9 +963,9 @@ int init_main(int argc UNUSED_PARAM, char **argv)
if (!DEBUG_INIT) {
/* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
if (getpid() != 1
- && (!ENABLE_FEATURE_INITRD || !strstr(applet_name, "linuxrc"))
+ && (!ENABLE_FEATURE_INITRD || applet_name[0] != 'l') /* not linuxrc? */
) {
- bb_show_usage();
+ bb_error_msg_and_die("must be run as PID 1");
}
#ifdef RB_DISABLE_CAD
/* Turn off rebooting via CTL-ALT-DEL - we get a
@@ -1286,3 +1154,138 @@ int init_main(int argc UNUSED_PARAM, char **argv)
}
} /* while (1) */
}
+
+//usage:#define linuxrc_trivial_usage NOUSAGE_STR
+//usage:#define linuxrc_full_usage ""
+
+//usage:#define init_trivial_usage
+//usage: ""
+//usage:#define init_full_usage "\n\n"
+//usage: "Init is the parent of all processes"
+//usage:
+//usage:#define init_notes_usage
+//usage: "This version of init is designed to be run only by the kernel.\n"
+//usage: "\n"
+//usage: "BusyBox init doesn't support multiple runlevels. The runlevels field of\n"
+//usage: "the /etc/inittab file is completely ignored by BusyBox init. If you want\n"
+//usage: "runlevels, use sysvinit.\n"
+//usage: "\n"
+//usage: "BusyBox init works just fine without an inittab. If no inittab is found,\n"
+//usage: "it has the following default behavior:\n"
+//usage: "\n"
+//usage: " ::sysinit:/etc/init.d/rcS\n"
+//usage: " ::askfirst:/bin/sh\n"
+//usage: " ::ctrlaltdel:/sbin/reboot\n"
+//usage: " ::shutdown:/sbin/swapoff -a\n"
+//usage: " ::shutdown:/bin/umount -a -r\n"
+//usage: " ::restart:/sbin/init\n"
+//usage: "\n"
+//usage: "if it detects that /dev/console is _not_ a serial console, it will also run:\n"
+//usage: "\n"
+//usage: " tty2::askfirst:/bin/sh\n"
+//usage: " tty3::askfirst:/bin/sh\n"
+//usage: " tty4::askfirst:/bin/sh\n"
+//usage: "\n"
+//usage: "If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n"
+//usage: "\n"
+//usage: " <id>:<runlevels>:<action>:<process>\n"
+//usage: "\n"
+//usage: " <id>:\n"
+//usage: "\n"
+//usage: " WARNING: This field has a non-traditional meaning for BusyBox init!\n"
+//usage: " The id field is used by BusyBox init to specify the controlling tty for\n"
+//usage: " the specified process to run on. The contents of this field are\n"
+//usage: " appended to \"/dev/\" and used as-is. There is no need for this field to\n"
+//usage: " be unique, although if it isn't you may have strange results. If this\n"
+//usage: " field is left blank, the controlling tty is set to the console. Also\n"
+//usage: " note that if BusyBox detects that a serial console is in use, then only\n"
+//usage: " entries whose controlling tty is either the serial console or /dev/null\n"
+//usage: " will be run. BusyBox init does nothing with utmp. We don't need no\n"
+//usage: " stinkin' utmp.\n"
+//usage: "\n"
+//usage: " <runlevels>:\n"
+//usage: "\n"
+//usage: " The runlevels field is completely ignored.\n"
+//usage: "\n"
+//usage: " <action>:\n"
+//usage: "\n"
+//usage: " Valid actions include: sysinit, respawn, askfirst, wait,\n"
+//usage: " once, restart, ctrlaltdel, and shutdown.\n"
+//usage: "\n"
+//usage: " The available actions can be classified into two groups: actions\n"
+//usage: " that are run only once, and actions that are re-run when the specified\n"
+//usage: " process exits.\n"
+//usage: "\n"
+//usage: " Run only-once actions:\n"
+//usage: "\n"
+//usage: " 'sysinit' is the first item run on boot. init waits until all\n"
+//usage: " sysinit actions are completed before continuing. Following the\n"
+//usage: " completion of all sysinit actions, all 'wait' actions are run.\n"
+//usage: " 'wait' actions, like 'sysinit' actions, cause init to wait until\n"
+//usage: " the specified task completes. 'once' actions are asynchronous,\n"
+//usage: " therefore, init does not wait for them to complete. 'restart' is\n"
+//usage: " the action taken to restart the init process. By default this should\n"
+//usage: " simply run /sbin/init, but can be a script which runs pivot_root or it\n"
+//usage: " can do all sorts of other interesting things. The 'ctrlaltdel' init\n"
+//usage: " actions are run when the system detects that someone on the system\n"
+//usage: " console has pressed the CTRL-ALT-DEL key combination. Typically one\n"
+//usage: " wants to run 'reboot' at this point to cause the system to reboot.\n"
+//usage: " Finally the 'shutdown' action specifies the actions to taken when\n"
+//usage: " init is told to reboot. Unmounting filesystems and disabling swap\n"
+//usage: " is a very good here.\n"
+//usage: "\n"
+//usage: " Run repeatedly actions:\n"
+//usage: "\n"
+//usage: " 'respawn' actions are run after the 'once' actions. When a process\n"
+//usage: " started with a 'respawn' action exits, init automatically restarts\n"
+//usage: " it. Unlike sysvinit, BusyBox init does not stop processes from\n"
+//usage: " respawning out of control. The 'askfirst' actions acts just like\n"
+//usage: " respawn, except that before running the specified process it\n"
+//usage: " displays the line \"Please press Enter to activate this console.\"\n"
+//usage: " and then waits for the user to press enter before starting the\n"
+//usage: " specified process.\n"
+//usage: "\n"
+//usage: " Unrecognized actions (like initdefault) will cause init to emit an\n"
+//usage: " error message, and then go along with its business. All actions are\n"
+//usage: " run in the order they appear in /etc/inittab.\n"
+//usage: "\n"
+//usage: " <process>:\n"
+//usage: "\n"
+//usage: " Specifies the process to be executed and its command line.\n"
+//usage: "\n"
+//usage: "Example /etc/inittab file:\n"
+//usage: "\n"
+//usage: " # This is run first except when booting in single-user mode\n"
+//usage: " #\n"
+//usage: " ::sysinit:/etc/init.d/rcS\n"
+//usage: " \n"
+//usage: " # /bin/sh invocations on selected ttys\n"
+//usage: " #\n"
+//usage: " # Start an \"askfirst\" shell on the console (whatever that may be)\n"
+//usage: " ::askfirst:-/bin/sh\n"
+//usage: " # Start an \"askfirst\" shell on /dev/tty2-4\n"
+//usage: " tty2::askfirst:-/bin/sh\n"
+//usage: " tty3::askfirst:-/bin/sh\n"
+//usage: " tty4::askfirst:-/bin/sh\n"
+//usage: " \n"
+//usage: " # /sbin/getty invocations for selected ttys\n"
+//usage: " #\n"
+//usage: " tty4::respawn:/sbin/getty 38400 tty4\n"
+//usage: " tty5::respawn:/sbin/getty 38400 tty5\n"
+//usage: " \n"
+//usage: " \n"
+//usage: " # Example of how to put a getty on a serial line (for a terminal)\n"
+//usage: " #\n"
+//usage: " #::respawn:/sbin/getty -L ttyS0 9600 vt100\n"
+//usage: " #::respawn:/sbin/getty -L ttyS1 9600 vt100\n"
+//usage: " #\n"
+//usage: " # Example how to put a getty on a modem line\n"
+//usage: " #::respawn:/sbin/getty 57600 ttyS2\n"
+//usage: " \n"
+//usage: " # Stuff to do when restarting the init process\n"
+//usage: " ::restart:/sbin/init\n"
+//usage: " \n"
+//usage: " # Stuff to do before rebooting\n"
+//usage: " ::ctrlaltdel:/sbin/reboot\n"
+//usage: " ::shutdown:/bin/umount -a -r\n"
+//usage: " ::shutdown:/sbin/swapoff -a\n"