aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-11-02 20:13:03 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-11-02 20:13:03 +0100
commitdb5fe62b6d9977304b864f961dae71232091b26c (patch)
treee69e9efc17a3b0feae78118eb14d653cfa47e259 /init
parent4d4d1a015f351816982e61a7f7dc861bfe06ca78 (diff)
downloadbusybox-w32-db5fe62b6d9977304b864f961dae71232091b26c.tar.gz
busybox-w32-db5fe62b6d9977304b864f961dae71232091b26c.tar.bz2
busybox-w32-db5fe62b6d9977304b864f961dae71232091b26c.zip
init: if PID!=1, show clearer error message. move usage text closer to main()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'init')
-rw-r--r--init/init.c271
1 files changed, 137 insertions, 134 deletions
diff --git a/init/init.c b/init/init.c
index a7bbd5e64..0a0d503b5 100644
--- a/init/init.c
+++ b/init/init.c
@@ -108,138 +108,6 @@
108//config: Note that on Linux, init attempts to detect serial terminal and 108//config: Note that on Linux, init attempts to detect serial terminal and
109//config: sets TERM to "vt102" if one is found. 109//config: sets TERM to "vt102" if one is found.
110 110
111//usage:#define init_trivial_usage
112//usage: ""
113//usage:#define init_full_usage "\n\n"
114//usage: "Init is the parent of all processes"
115//usage:
116//usage:#define init_notes_usage
117//usage: "This version of init is designed to be run only by the kernel.\n"
118//usage: "\n"
119//usage: "BusyBox init doesn't support multiple runlevels. The runlevels field of\n"
120//usage: "the /etc/inittab file is completely ignored by BusyBox init. If you want\n"
121//usage: "runlevels, use sysvinit.\n"
122//usage: "\n"
123//usage: "BusyBox init works just fine without an inittab. If no inittab is found,\n"
124//usage: "it has the following default behavior:\n"
125//usage: "\n"
126//usage: " ::sysinit:/etc/init.d/rcS\n"
127//usage: " ::askfirst:/bin/sh\n"
128//usage: " ::ctrlaltdel:/sbin/reboot\n"
129//usage: " ::shutdown:/sbin/swapoff -a\n"
130//usage: " ::shutdown:/bin/umount -a -r\n"
131//usage: " ::restart:/sbin/init\n"
132//usage: "\n"
133//usage: "if it detects that /dev/console is _not_ a serial console, it will also run:\n"
134//usage: "\n"
135//usage: " tty2::askfirst:/bin/sh\n"
136//usage: " tty3::askfirst:/bin/sh\n"
137//usage: " tty4::askfirst:/bin/sh\n"
138//usage: "\n"
139//usage: "If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n"
140//usage: "\n"
141//usage: " <id>:<runlevels>:<action>:<process>\n"
142//usage: "\n"
143//usage: " <id>:\n"
144//usage: "\n"
145//usage: " WARNING: This field has a non-traditional meaning for BusyBox init!\n"
146//usage: " The id field is used by BusyBox init to specify the controlling tty for\n"
147//usage: " the specified process to run on. The contents of this field are\n"
148//usage: " appended to \"/dev/\" and used as-is. There is no need for this field to\n"
149//usage: " be unique, although if it isn't you may have strange results. If this\n"
150//usage: " field is left blank, the controlling tty is set to the console. Also\n"
151//usage: " note that if BusyBox detects that a serial console is in use, then only\n"
152//usage: " entries whose controlling tty is either the serial console or /dev/null\n"
153//usage: " will be run. BusyBox init does nothing with utmp. We don't need no\n"
154//usage: " stinkin' utmp.\n"
155//usage: "\n"
156//usage: " <runlevels>:\n"
157//usage: "\n"
158//usage: " The runlevels field is completely ignored.\n"
159//usage: "\n"
160//usage: " <action>:\n"
161//usage: "\n"
162//usage: " Valid actions include: sysinit, respawn, askfirst, wait,\n"
163//usage: " once, restart, ctrlaltdel, and shutdown.\n"
164//usage: "\n"
165//usage: " The available actions can be classified into two groups: actions\n"
166//usage: " that are run only once, and actions that are re-run when the specified\n"
167//usage: " process exits.\n"
168//usage: "\n"
169//usage: " Run only-once actions:\n"
170//usage: "\n"
171//usage: " 'sysinit' is the first item run on boot. init waits until all\n"
172//usage: " sysinit actions are completed before continuing. Following the\n"
173//usage: " completion of all sysinit actions, all 'wait' actions are run.\n"
174//usage: " 'wait' actions, like 'sysinit' actions, cause init to wait until\n"
175//usage: " the specified task completes. 'once' actions are asynchronous,\n"
176//usage: " therefore, init does not wait for them to complete. 'restart' is\n"
177//usage: " the action taken to restart the init process. By default this should\n"
178//usage: " simply run /sbin/init, but can be a script which runs pivot_root or it\n"
179//usage: " can do all sorts of other interesting things. The 'ctrlaltdel' init\n"
180//usage: " actions are run when the system detects that someone on the system\n"
181//usage: " console has pressed the CTRL-ALT-DEL key combination. Typically one\n"
182//usage: " wants to run 'reboot' at this point to cause the system to reboot.\n"
183//usage: " Finally the 'shutdown' action specifies the actions to taken when\n"
184//usage: " init is told to reboot. Unmounting filesystems and disabling swap\n"
185//usage: " is a very good here.\n"
186//usage: "\n"
187//usage: " Run repeatedly actions:\n"
188//usage: "\n"
189//usage: " 'respawn' actions are run after the 'once' actions. When a process\n"
190//usage: " started with a 'respawn' action exits, init automatically restarts\n"
191//usage: " it. Unlike sysvinit, BusyBox init does not stop processes from\n"
192//usage: " respawning out of control. The 'askfirst' actions acts just like\n"
193//usage: " respawn, except that before running the specified process it\n"
194//usage: " displays the line \"Please press Enter to activate this console.\"\n"
195//usage: " and then waits for the user to press enter before starting the\n"
196//usage: " specified process.\n"
197//usage: "\n"
198//usage: " Unrecognized actions (like initdefault) will cause init to emit an\n"
199//usage: " error message, and then go along with its business. All actions are\n"
200//usage: " run in the order they appear in /etc/inittab.\n"
201//usage: "\n"
202//usage: " <process>:\n"
203//usage: "\n"
204//usage: " Specifies the process to be executed and its command line.\n"
205//usage: "\n"
206//usage: "Example /etc/inittab file:\n"
207//usage: "\n"
208//usage: " # This is run first except when booting in single-user mode\n"
209//usage: " #\n"
210//usage: " ::sysinit:/etc/init.d/rcS\n"
211//usage: " \n"
212//usage: " # /bin/sh invocations on selected ttys\n"
213//usage: " #\n"
214//usage: " # Start an \"askfirst\" shell on the console (whatever that may be)\n"
215//usage: " ::askfirst:-/bin/sh\n"
216//usage: " # Start an \"askfirst\" shell on /dev/tty2-4\n"
217//usage: " tty2::askfirst:-/bin/sh\n"
218//usage: " tty3::askfirst:-/bin/sh\n"
219//usage: " tty4::askfirst:-/bin/sh\n"
220//usage: " \n"
221//usage: " # /sbin/getty invocations for selected ttys\n"
222//usage: " #\n"
223//usage: " tty4::respawn:/sbin/getty 38400 tty4\n"
224//usage: " tty5::respawn:/sbin/getty 38400 tty5\n"
225//usage: " \n"
226//usage: " \n"
227//usage: " # Example of how to put a getty on a serial line (for a terminal)\n"
228//usage: " #\n"
229//usage: " #::respawn:/sbin/getty -L ttyS0 9600 vt100\n"
230//usage: " #::respawn:/sbin/getty -L ttyS1 9600 vt100\n"
231//usage: " #\n"
232//usage: " # Example how to put a getty on a modem line\n"
233//usage: " #::respawn:/sbin/getty 57600 ttyS2\n"
234//usage: " \n"
235//usage: " # Stuff to do when restarting the init process\n"
236//usage: " ::restart:/sbin/init\n"
237//usage: " \n"
238//usage: " # Stuff to do before rebooting\n"
239//usage: " ::ctrlaltdel:/sbin/reboot\n"
240//usage: " ::shutdown:/bin/umount -a -r\n"
241//usage: " ::shutdown:/sbin/swapoff -a\n"
242
243#include "libbb.h" 111#include "libbb.h"
244#include <syslog.h> 112#include <syslog.h>
245#include <paths.h> 113#include <paths.h>
@@ -1095,9 +963,9 @@ int init_main(int argc UNUSED_PARAM, char **argv)
1095 if (!DEBUG_INIT) { 963 if (!DEBUG_INIT) {
1096 /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ 964 /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
1097 if (getpid() != 1 965 if (getpid() != 1
1098 && (!ENABLE_FEATURE_INITRD || !strstr(applet_name, "linuxrc")) 966 && (!ENABLE_FEATURE_INITRD || applet_name[0] != 'l') /* not linuxrc? */
1099 ) { 967 ) {
1100 bb_show_usage(); 968 bb_error_msg_and_die("must be run as PID 1");
1101 } 969 }
1102#ifdef RB_DISABLE_CAD 970#ifdef RB_DISABLE_CAD
1103 /* Turn off rebooting via CTL-ALT-DEL - we get a 971 /* Turn off rebooting via CTL-ALT-DEL - we get a
@@ -1286,3 +1154,138 @@ int init_main(int argc UNUSED_PARAM, char **argv)
1286 } 1154 }
1287 } /* while (1) */ 1155 } /* while (1) */
1288} 1156}
1157
1158//usage:#define linuxrc_trivial_usage NOUSAGE_STR
1159//usage:#define linuxrc_full_usage ""
1160
1161//usage:#define init_trivial_usage
1162//usage: ""
1163//usage:#define init_full_usage "\n\n"
1164//usage: "Init is the parent of all processes"
1165//usage:
1166//usage:#define init_notes_usage
1167//usage: "This version of init is designed to be run only by the kernel.\n"
1168//usage: "\n"
1169//usage: "BusyBox init doesn't support multiple runlevels. The runlevels field of\n"
1170//usage: "the /etc/inittab file is completely ignored by BusyBox init. If you want\n"
1171//usage: "runlevels, use sysvinit.\n"
1172//usage: "\n"
1173//usage: "BusyBox init works just fine without an inittab. If no inittab is found,\n"
1174//usage: "it has the following default behavior:\n"
1175//usage: "\n"
1176//usage: " ::sysinit:/etc/init.d/rcS\n"
1177//usage: " ::askfirst:/bin/sh\n"
1178//usage: " ::ctrlaltdel:/sbin/reboot\n"
1179//usage: " ::shutdown:/sbin/swapoff -a\n"
1180//usage: " ::shutdown:/bin/umount -a -r\n"
1181//usage: " ::restart:/sbin/init\n"
1182//usage: "\n"
1183//usage: "if it detects that /dev/console is _not_ a serial console, it will also run:\n"
1184//usage: "\n"
1185//usage: " tty2::askfirst:/bin/sh\n"
1186//usage: " tty3::askfirst:/bin/sh\n"
1187//usage: " tty4::askfirst:/bin/sh\n"
1188//usage: "\n"
1189//usage: "If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n"
1190//usage: "\n"
1191//usage: " <id>:<runlevels>:<action>:<process>\n"
1192//usage: "\n"
1193//usage: " <id>:\n"
1194//usage: "\n"
1195//usage: " WARNING: This field has a non-traditional meaning for BusyBox init!\n"
1196//usage: " The id field is used by BusyBox init to specify the controlling tty for\n"
1197//usage: " the specified process to run on. The contents of this field are\n"
1198//usage: " appended to \"/dev/\" and used as-is. There is no need for this field to\n"
1199//usage: " be unique, although if it isn't you may have strange results. If this\n"
1200//usage: " field is left blank, the controlling tty is set to the console. Also\n"
1201//usage: " note that if BusyBox detects that a serial console is in use, then only\n"
1202//usage: " entries whose controlling tty is either the serial console or /dev/null\n"
1203//usage: " will be run. BusyBox init does nothing with utmp. We don't need no\n"
1204//usage: " stinkin' utmp.\n"
1205//usage: "\n"
1206//usage: " <runlevels>:\n"
1207//usage: "\n"
1208//usage: " The runlevels field is completely ignored.\n"
1209//usage: "\n"
1210//usage: " <action>:\n"
1211//usage: "\n"
1212//usage: " Valid actions include: sysinit, respawn, askfirst, wait,\n"
1213//usage: " once, restart, ctrlaltdel, and shutdown.\n"
1214//usage: "\n"
1215//usage: " The available actions can be classified into two groups: actions\n"
1216//usage: " that are run only once, and actions that are re-run when the specified\n"
1217//usage: " process exits.\n"
1218//usage: "\n"
1219//usage: " Run only-once actions:\n"
1220//usage: "\n"
1221//usage: " 'sysinit' is the first item run on boot. init waits until all\n"
1222//usage: " sysinit actions are completed before continuing. Following the\n"
1223//usage: " completion of all sysinit actions, all 'wait' actions are run.\n"
1224//usage: " 'wait' actions, like 'sysinit' actions, cause init to wait until\n"
1225//usage: " the specified task completes. 'once' actions are asynchronous,\n"
1226//usage: " therefore, init does not wait for them to complete. 'restart' is\n"
1227//usage: " the action taken to restart the init process. By default this should\n"
1228//usage: " simply run /sbin/init, but can be a script which runs pivot_root or it\n"
1229//usage: " can do all sorts of other interesting things. The 'ctrlaltdel' init\n"
1230//usage: " actions are run when the system detects that someone on the system\n"
1231//usage: " console has pressed the CTRL-ALT-DEL key combination. Typically one\n"
1232//usage: " wants to run 'reboot' at this point to cause the system to reboot.\n"
1233//usage: " Finally the 'shutdown' action specifies the actions to taken when\n"
1234//usage: " init is told to reboot. Unmounting filesystems and disabling swap\n"
1235//usage: " is a very good here.\n"
1236//usage: "\n"
1237//usage: " Run repeatedly actions:\n"
1238//usage: "\n"
1239//usage: " 'respawn' actions are run after the 'once' actions. When a process\n"
1240//usage: " started with a 'respawn' action exits, init automatically restarts\n"
1241//usage: " it. Unlike sysvinit, BusyBox init does not stop processes from\n"
1242//usage: " respawning out of control. The 'askfirst' actions acts just like\n"
1243//usage: " respawn, except that before running the specified process it\n"
1244//usage: " displays the line \"Please press Enter to activate this console.\"\n"
1245//usage: " and then waits for the user to press enter before starting the\n"
1246//usage: " specified process.\n"
1247//usage: "\n"
1248//usage: " Unrecognized actions (like initdefault) will cause init to emit an\n"
1249//usage: " error message, and then go along with its business. All actions are\n"
1250//usage: " run in the order they appear in /etc/inittab.\n"
1251//usage: "\n"
1252//usage: " <process>:\n"
1253//usage: "\n"
1254//usage: " Specifies the process to be executed and its command line.\n"
1255//usage: "\n"
1256//usage: "Example /etc/inittab file:\n"
1257//usage: "\n"
1258//usage: " # This is run first except when booting in single-user mode\n"
1259//usage: " #\n"
1260//usage: " ::sysinit:/etc/init.d/rcS\n"
1261//usage: " \n"
1262//usage: " # /bin/sh invocations on selected ttys\n"
1263//usage: " #\n"
1264//usage: " # Start an \"askfirst\" shell on the console (whatever that may be)\n"
1265//usage: " ::askfirst:-/bin/sh\n"
1266//usage: " # Start an \"askfirst\" shell on /dev/tty2-4\n"
1267//usage: " tty2::askfirst:-/bin/sh\n"
1268//usage: " tty3::askfirst:-/bin/sh\n"
1269//usage: " tty4::askfirst:-/bin/sh\n"
1270//usage: " \n"
1271//usage: " # /sbin/getty invocations for selected ttys\n"
1272//usage: " #\n"
1273//usage: " tty4::respawn:/sbin/getty 38400 tty4\n"
1274//usage: " tty5::respawn:/sbin/getty 38400 tty5\n"
1275//usage: " \n"
1276//usage: " \n"
1277//usage: " # Example of how to put a getty on a serial line (for a terminal)\n"
1278//usage: " #\n"
1279//usage: " #::respawn:/sbin/getty -L ttyS0 9600 vt100\n"
1280//usage: " #::respawn:/sbin/getty -L ttyS1 9600 vt100\n"
1281//usage: " #\n"
1282//usage: " # Example how to put a getty on a modem line\n"
1283//usage: " #::respawn:/sbin/getty 57600 ttyS2\n"
1284//usage: " \n"
1285//usage: " # Stuff to do when restarting the init process\n"
1286//usage: " ::restart:/sbin/init\n"
1287//usage: " \n"
1288//usage: " # Stuff to do before rebooting\n"
1289//usage: " ::ctrlaltdel:/sbin/reboot\n"
1290//usage: " ::shutdown:/bin/umount -a -r\n"
1291//usage: " ::shutdown:/sbin/swapoff -a\n"