blob: b6a5d721ff4a582862b93bb3c0bc4604e87b9ef9 [file] [log] [blame]
Eric Andersen6c4a6b12004-10-08 10:50:08 +00001<!--#include file="header.html" -->
2
Eric Andersen6c4a6b12004-10-08 10:50:08 +00003<h3>Frequently Asked Questions</h3>
4
5This is a collection of some of the more frequently asked questions
6about BusyBox. Some of the questions even have answers. If you
7have additions to this FAQ document, we would love to add them,
8
Rob Landleyb73d2bf2006-05-11 15:00:32 +00009<h2>General questions</h2>
Eric Andersen6c4a6b12004-10-08 10:50:08 +000010<ol>
Rob Landleyac4c92d2006-05-11 17:21:13 +000011<li><a href="#getting_started">How can I get started using BusyBox?</a></li>
12<li><a href="#configure">How do I configure busybox?</a></li>
Bernhard Reutner-Fischer8936a192007-06-08 07:19:06 +000013<li><a href="#build">How do I build BusyBox with a cross-compiler?</a></li>
Rob Landleyac4c92d2006-05-11 17:21:13 +000014<li><a href="#build_system">How do I build a BusyBox-based system?</a></li>
15<li><a href="#kernel">Which Linux kernel versions are supported?</a></li>
16<li><a href="#arch">Which architectures does BusyBox run on?</a></li>
17<li><a href="#libc">Which C libraries are supported?</a></li>
18<li><a href="#commercial">Can I include BusyBox as part of the software on my device?</a></li>
19<li><a href="#external">Where can I find other small utilities since busybox does not include the features I want?</a></li></li>
20<li><a href="#demanding">I demand that you to add &lt;favorite feature&gt; right now! How come you don't answer all my questions on the mailing list instantly? I demand that you help me with all of my problems <em>Right Now</em>!</a></li>
21<li><a href="#helpme">I need help with BusyBox! What should I do?</a></li>
22<li><a href="#contracts">I need you to add &lt;favorite feature&gt;! Are the BusyBox developers willing to be paid in order to fix bugs or add in &lt;favorite feature&gt;? Are you willing to provide support contracts?</a></li>
Rob Landleyb73d2bf2006-05-11 15:00:32 +000023</ol>
Rob Landleyde7f9b72005-07-31 04:27:19 +000024
Rob Landleyb73d2bf2006-05-11 15:00:32 +000025<h2>Troubleshooting</h2>
26<ol>
27<li><a href="#bugs">I think I found a bug in BusyBox! What should I do?!</a></li>
Rob Landley95718b32006-08-16 22:13:56 +000028<li><a href="#backporting">I'm using an ancient version from the dawn of time and something's broken. Can you backport fixes for free?</a></li>
Rob Landleyb73d2bf2006-05-11 15:00:32 +000029<li><a href="#init">Busybox init isn't working!</a></li>
30<li><a href="#sed">I can't configure busybox on my system.</a></li>
31<li><a href="#job_control">Why do I keep getting "sh: can't access tty; job control turned off" errors? Why doesn't Control-C work within my shell?</a></li>
32</ol>
33
34<h2>Programming questions</h2>
35<ol>
36 <li><a href="#goals">What are the goals of busybox?</a></li>
37 <li><a href="#design">What is the design of busybox?</a></li>
38 <li><a href="#source">How is the source code organized?</a></li>
39 <ul>
40 <li><a href="#source_applets">The applet directories.</a></li>
41 <li><a href="#source_libbb">The busybox shared library (libbb)</a></li>
42 </ul>
43 <li><a href="#optimize">I want to make busybox even smaller, how do I go about it?</a></li>
44 <li><a href="#adding">Adding an applet to busybox</a></li>
45 <li><a href="#standards">What standards does busybox adhere to?</a></li>
46 <li><a href="#portability">Portability.</a></li>
47 <li><a href="#tips">Tips and tricks.</a></li>
48 <ul>
49 <li><a href="#tips_encrypted_passwords">Encrypted Passwords</a></li>
50 <li><a href="#tips_vfork">Fork and vfork</a></li>
51 <li><a href="#tips_short_read">Short reads and writes</a></li>
52 <li><a href="#tips_memory">Memory used by relocatable code, PIC, and static linking.</a></li>
53 <li><a href="#tips_kernel_headers">Including Linux kernel headers.</a></li>
54 </ul>
55 <li><a href="#who">Who are the BusyBox developers?</a></li>
56</ul>
Eric Andersen6c4a6b12004-10-08 10:50:08 +000057
58
59</ol>
60
Rob Landleyb73d2bf2006-05-11 15:00:32 +000061<h1>General questions</h1>
62
Rob Landley380ad122005-09-23 16:52:09 +000063<hr />
64<p>
65<h2><a name="getting_started">How can I get started using BusyBox?</a></h2>
66<p> If you just want to try out busybox without installing it, download the
Rob Landleyac4c92d2006-05-11 17:21:13 +000067 tarball, extract it, run "make defconfig", and then run "make".
Rob Landley380ad122005-09-23 16:52:09 +000068</p>
69<p>
Rob Landleyac4c92d2006-05-11 17:21:13 +000070 This will create a busybox binary with almost all features enabled. To try
Rob Landley380ad122005-09-23 16:52:09 +000071 out a busybox applet, type "./busybox [appletname] [options]", for
72 example "./busybox ls -l" or "./busybox cat LICENSE". Type "./busybox"
73 to see a command list, and "busybox appletname --help" to see a brief
74 usage message for a given applet.
75</p>
76<p>
77 BusyBox uses the name it was invoked under to determine which applet is
78 being invoked. (Try "mv busybox ls" and then "./ls -l".) Installing
79 busybox consists of creating symlinks (or hardlinks) to the busybox
Rob Landley3d283dd2005-11-03 22:11:00 +000080 binary for each applet in busybox, and making sure these links are in
81 the shell's command $PATH. The special applet name "busybox" (or with
82 any optional suffix, such as "busybox-static") uses the first argument
83 to determine which applet to run, as shown above.
Rob Landley380ad122005-09-23 16:52:09 +000084</p>
85<p>
Denis Vlasenkof7996f32007-01-11 17:20:00 +000086 BusyBox also has a feature called the
Bernhard Reutner-Fischer32f3ebf2006-12-10 13:40:16 +000087 <a name="standalone_shell">"standalone shell"</a>, where the busybox
Rob Landley380ad122005-09-23 16:52:09 +000088 shell runs any built-in applets before checking the command path. This
89 feature is also enabled by "make allyesconfig", and to try it out run
90 the command line "PATH= ./busybox ash". This will blank your command path
91 and run busybox as your command shell, so the only commands it can find
92 (without an explicit path such as /bin/ls) are the built-in busybox ones.
Bernhard Reutner-Fischerd591a362006-08-20 17:35:13 +000093 This is another good way to see what's built into busybox.
94 Note that the standalone shell requires CONFIG_BUSYBOX_EXEC_PATH
95 to be set appropriately, depending on whether or not /proc/self/exe is
96 available or not. If you do not have /proc, then point that config option
97 to the location of your busybox binary, usually /bin/busybox.
98 (So if you set it to /proc/self/exe, and happen to be able to chroot into
99 your rootfs, you must mount /proc beforehand.)
Rob Landley380ad122005-09-23 16:52:09 +0000100</p>
Bernhard Reutner-Fischer32f3ebf2006-12-10 13:40:16 +0000101<p>
102 A typical indication that you set CONFIG_BUSYBOX_EXEC_PATH to proc but
103 forgot to mount proc is:
104<pre>
105$ /bin/echo $PATH
106/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11
107$ echo $PATH
108/bin/sh: echo: not found
109</pre>
Rob Landleyac4c92d2006-05-11 17:21:13 +0000110<hr />
111<p>
112<h2><a name="configure">How do I configure busybox?</a></h2>
113<p> Busybox is configured similarly to the linux kernel. Create a default
114 configuration and then run "make menuconfig" to modify it. The end
115 result is a .config file that tells the busybox build process what features
116 to include. So instead of "./configure; make; make install" the equivalent
117 busybox build would be "make defconfig; make; make install".
118</p>
119
120<p> Busybox configured with all features enabled is a little under a megabyte
121 dynamically linked on x86. To create a smaller busybox, configure it with
122 fewer features. Individual busybox applets cost anywhere from a few
123 hundred bytes to tens of kilobytes. Disable unneeded applets to save,
124 space, using menuconfig.
125</p>
126
127<p>The most important busybox configurators are:</p>
128
129<ul>
130<li><p>make <b>defconfig</b> - Create the maximum "sane" configuration. This
131enables almost all features, minus things like debugging options and features
132that require changes to the rest of the system to work (such as selinux or
133devfs device names). Use this if you want to start from a full-featured
134busybox and remove features until it's small enough.</p></li>
135<li><p>make <b>allnoconfig</b> - Disable everything. This creates a tiny version
136of busybox that doesn't do anything. Start here if you know exactly what
137you want and would like to select only those features.</p></li>
138<li><p>make <b>menuconfig</b> - Interactively modify a .config file through a
139multi-level menu interface. Use this after one of the previous two.</p></li>
140</ul>
141
142<p>Some other configuration options are:</p>
143<ul>
144<li><p>make <b>oldconfig</b> - Update an old .config file for a newer version
145of busybox.</p></li>
146<li><p>make <b>allyesconfig</b> - Select absolutely everything. This creates
147a statically linked version of busybox full of debug code, with dependencies on
148selinux, using devfs names... This makes sure everything compiles. Whether
149or not the result would do anything useful is an open question.</p></li>
150<li><p>make <b>allbareconfig</b> - Select all applets but disable all sub-features
151within each applet. More build coverage testing.</p></li>
152<li><p>make <b>randconfig</b> - Create a random configuration for test purposes.</p></li>
153</ul>
154
155<p> Menuconfig modifies your .config file through an interactive menu where you can enable or disable
156 busybox features, and get help about each feature.
157
158
159
Rob Landley380ad122005-09-23 16:52:09 +0000160<p>
161 To build a smaller busybox binary, run "make menuconfig" and disable the
162 features you don't need. (Or run "make allnoconfig" and then use
163 menuconfig to add just the features you need. Don't forget to recompile
164 with "make" once you've finished configuring.)
165</p>
166<hr/>
167<p/>
Bernhard Reutner-Fischer8936a192007-06-08 07:19:06 +0000168<h2><a name="build">How do I build BusyBox with a cross-compiler?</a></h2>
169<p>
170 To build busybox with a cross-compiler, specify CROSS_COMPILE=&lt;prefix&gt;.
171</p>
172<p>
173 CROSS_COMPILE specifies the prefix used for all executables used
174 during compilation. Only gcc and related binutils executables
175 are prefixed with $(CROSS_COMPILE) in the makefiles.
176 CROSS_COMPILE can be set on the command line:
177<pre>
178 make CROSS_COMPILE=arm-linux-uclibcgnueabi-
179</pre>
180 Alternatively CROSS_COMPILE can be set in the environment.
181 Default value for CROSS_COMPILE is not to prefix executables.
182</p>
Rob Landley380ad122005-09-23 16:52:09 +0000183<h2><a name="build_system">How do I build a BusyBox-based system?</a></h2>
184<p>
185 BusyBox is a package that replaces a dozen standard packages, but it is
186 not by itself a complete bootable system. Building an entire Linux
187 distribution from source is a bit beyond the scope of this FAQ, but it
188 understandably keeps cropping up on the mailing list, so here are some
189 pointers.
190</p>
191<p>
192 Start by learning how to strip a working system down to the bare essentials
193 needed to run one or two commands, so you know what it is you actually
194 need. An excellent practical place to do
195 this is the <a href="http://www.tldp.org/HOWTO/Bootdisk-HOWTO/">Linux
196 BootDisk Howto</a>, or for a more theoretical approach try
197 <a href="http://www.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html">From
198 PowerUp to Bash Prompt</a>.
199</p>
200<p>
201 To learn how to build a working Linux system entirely from source code,
202 the place to go is the <a href="http://www.linuxfromscratch.org">Linux
203 From Scratch</a> project. They have an entire book of step-by-step
204 instructions you can
205 <a href="http://www.linuxfromscratch.org/lfs/view/stable/">read online</a>
206 or
207 <a href="http://www.linuxfromscratch.org/lfs/downloads/stable/">download</a>.
208 Be sure to check out the other sections of their main page, including
209 Beyond Linux From Scratch, Hardened Linux From Scratch, their Hints
210 directory, and their LiveCD project. (They also have mailing lists which
211 are better sources of answers to Linux-system building questions than
212 the busybox list.)
213</p>
214<p>
215 If you want an automated yet customizable system builder which produces
216 a BusyBox and uClibc based system, try
217 <a href="http://buildroot.uclibc.org">buildroot</a>, which is
Rob Landleya253e732006-02-14 08:29:48 +0000218 another project by the maintainer of the uClibc (Erik Andersen).
219 Download the tarball, extract it, unset CC, make.
Rob Landley380ad122005-09-23 16:52:09 +0000220 For more instructions, see the website.
221</p>
222
Rob Landleyd48633f2006-03-09 18:03:21 +0000223<hr />
224<p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000225<h2><a name="kernel">Which Linux kernel versions are supported?</a></h2>
226<p>
Rob Landley380ad122005-09-23 16:52:09 +0000227 Full functionality requires Linux 2.4.x or better. (Earlier versions may
228 still work, but are no longer regularly tested.) A large fraction of the
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000229 code should run on just about anything. While the current code is fairly
230 Linux specific, it should be fairly easy to port the majority of the code
231 to support, say, FreeBSD or Solaris, or Mac OS X, or even Windows (if you
232 are into that sort of thing).
Rob Landley380ad122005-09-23 16:52:09 +0000233</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000234<hr />
235<p>
236<h2><a name="arch">Which architectures does BusyBox run on?</a></h2>
237<p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000238 BusyBox in general will build on any architecture supported by gcc.
Rob Landley380ad122005-09-23 16:52:09 +0000239 Kernel module loading for 2.4 Linux kernels is currently
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000240 limited to ARM, CRIS, H8/300, x86, ia64, x86_64, m68k, MIPS, PowerPC,
241 S390, SH3/4/5, Sparc, v850e, and x86_64 for 2.4.x kernels.
Rob Landley380ad122005-09-23 16:52:09 +0000242</p>
243<p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000244 With 2.6.x kernels, module loading support should work on all architectures.
Rob Landley380ad122005-09-23 16:52:09 +0000245</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000246<hr />
247<p>
248<h2><a name="libc">Which C libraries are supported?</a></h2>
249<p>
Rob Landley380ad122005-09-23 16:52:09 +0000250 On Linux, BusyBox releases are tested against uClibc (0.9.27 or later) and
251 glibc (2.2 or later). Both should provide full functionality with busybox,
252 and if you find a bug we want to hear about it.
253</p>
Mike Frysingerd505e3e2005-10-29 08:03:54 +0000254<p>
Rob Landley380ad122005-09-23 16:52:09 +0000255 Linux-libc5 is no longer maintained (and has no known advantages over
256 uClibc), dietlibc is known to have numerous unfixed bugs, and klibc is
257 missing too many features to build BusyBox. If you require a small C
258 library for Linux, the busybox developers recommend uClibc.
259</p>
260<p>
261 Some BusyBox applets have been built and run under a combination
262 of newlib and libgloss (see
263 <a href="http://www.busybox.net/lists/busybox/2005-March/013759.html">this thread</a>).
264 This is still experimental, but may be supported in a future release.
265</p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000266
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000267<hr />
268<p>
Mike Frysinger86097b32005-09-15 01:37:36 +0000269<h2><a name="commercial">Can I include BusyBox as part of the software on my device?</a></h2>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000270<p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000271
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000272<p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000273 Yes. As long as you <a href="http://busybox.net/license.html">fully comply
274 with the generous terms of the GPL BusyBox license</a> you can ship BusyBox
275 as part of the software on your device.
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000276</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000277
278<hr />
279<p>
Denis Vlasenkof7996f32007-01-11 17:20:00 +0000280<h2><a name="external">where can i find other small utilities since busybox
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000281 does not include the features i want?</a></h2>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000282<p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000283 we maintain such a <a href="tinyutils.html">list</a> on this site!
284</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000285
286<hr />
287<p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000288<h2><a name="demanding">I demand that you to add &lt;favorite feature&gt; right now! How come you don't answer all my questions on the mailing list instantly? I demand that you help me with all of my problems <em>Right Now</em>!</a></h2>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000289<p>
290
291 You have not paid us a single cent and yet you still have the product of
292 many years of our work. We are not your slaves! We work on BusyBox
293 because we find it useful and interesting. If you go off flaming us, we
294 will ignore you.
295
296
297<hr />
298<p>
299<h2><a name="helpme">I need help with BusyBox! What should I do?</a></h2>
300<p>
301
302 If you find that you need help with BusyBox, you can ask for help on the
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000303 BusyBox mailing list at busybox@busybox.net.</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000304
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000305<p> In addition to the mailing list, Erik Andersen (andersee), Manuel Nova
306 (mjn3), Rob Landley (landley), Mike Frysinger (SpanKY), Bernhard Fischer
307 (blindvt), and other long-time BusyBox developers are known to hang out
308 on the uClibc IRC channel: #uclibc on irc.freenode.net. There is a
309 <a href="http://ibot.Rikers.org/%23uclibc/">web archive of
310 daily logs of the #uclibc IRC channel</a> going back to 2002.
311</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000312
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000313<p>
Rob Landleya253e732006-02-14 08:29:48 +0000314 <b>Please do not send private email to Rob, Erik, Manuel, or the other
315 BusyBox contributors asking for private help unless you are planning on
316 paying for consulting services.</b>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000317</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000318
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000319<p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000320 When we answer questions on the BusyBox mailing list, it helps everyone
321 since people with similar problems in the future will be able to get help
322 by searching the mailing list archives. Private help is reserved as a paid
323 service. If you need to use private communication, or if you are serious
324 about getting timely assistance with BusyBox, you should seriously consider
325 paying for consulting services.
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000326</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000327
328<hr />
329<p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000330<h2><a name="contracts">I need you to add &lt;favorite feature&gt;! Are the BusyBox developers willing to be paid in order to fix bugs or add in &lt;favorite feature&gt;? Are you willing to provide support contracts?</a></h2>
331</p>
332
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000333<p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000334 Yes we are. The easy way to sponsor a new feature is to post an offer on
335 the mailing list to see who's interested. You can also email the project's
336 maintainer and ask them to recommend someone.
337</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000338
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000339<p> If you prefer to deal with an organization rather than an individual, Rob
340 Landley (the current BusyBox maintainer) works for
341 <a http://www.timesys.com>TimeSys</a>, and Eric Andersen (the previous
342 busybox maintainer and current uClibc maintainer) owns
343 <a href="http://codepoet-consulting.com/">CodePoet Consulting</a>. Both
344 companies offer support contracts and handle new development, and there
345 are plenty of other companies that do the same.
346</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000347
348
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000349
350
351<h1>Troubleshooting</h1>
352
353<hr />
354<p></p>
355<h2><a name="bugs">I think I found a bug in BusyBox! What should I do?</a></h2>
356<p></p>
357
358<p>
359 If you simply need help with using or configuring BusyBox, please submit a
360 detailed description of your problem to the BusyBox mailing list at <a
361 href="mailto:busybox@busybox.net"> busybox@busybox.net</a>.
362 Please do not send email to individual developers asking
363 for private help unless you are planning on paying for consulting services.
364 When we answer questions on the BusyBox mailing list, it helps everyone,
365 while private answers help only you...
366</p>
367
368<p>
Rob Landley95718b32006-08-16 22:13:56 +0000369 Bug reports and new feature patches sometimes get lost when posted to the
370 mailing list, because the developers of BusyBox are busy people and have
371 only so much they can keep in their brains at a time. You can post a
372 polite reminder after 2-3 days without offending anybody. If that doesn't
373 result in a solution, please use the
374 <a href="http://bugs.busybox.net/">BusyBox Bug
375 and Patch Tracking System</a> to submit a detailed explanation and we'll
376 get to it as soon as we can.
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000377</p>
378
Rob Landley95718b32006-08-16 22:13:56 +0000379<p>
380 Note that bugs entered into the bug system without being mentioned on the
381 mailing list first may languish there for months before anyone even notices
382 them. We generally go through the bug system when preparing for new
383 development releases, to see what fell through the cracks while we were
384 off writing new features. (It's a fast/unreliable vs slow/reliable thing.
385 Saves retransits, but the latency sucks.)
386</p>
387
388<hr />
389<p></p>
390<h2><a name="backporting">I'm using an ancient version from the dawn of time and something's broken. Can you backport fixes for free?</h2>
391
392<p>Variants of this one get asked a lot.</p>
393
394<p>The purpose of the BusyBox mailing list is to develop and improve BusyBox,
395and we're happy to respond to our users' needs. But if you're coming to the
396list for free tech support we're going to ask you to upgrade to a current
397version before we try to diagnose your problem.</p>
398
399<p>If you're building BusyBox 0.50 with uClibc 0.9.19 and gcc 0.9.26 there's a
400fairly large chance that whatever problem you're seeing has already been fixed.
401To get that fix, all you have to do is upgrade to a newer version. If you
402don't at least _try_ that, you're wasting our time.</p>
403
404<p>The volunteers are happy to fix any bugs you point out in the current
405versions because doing so helps everybody and makes the project better. We
406want to make the current version work for you. But diagnosing, debugging, and
407backporting fixes to old versions isn't something we do for free, because it
408doesn't help anybody but you. The cost of volunteer tech support is using a
409reasonably current version of the project.</p>
410
411<p>If you don't want to upgrade, you have the complete source code and thus
412the ability to fix it yourself, or hire a consultant to do it for you. If you
413got your version from a vendor who still supports the older version, they can
414help you. But there are limits as to what the volunteers will feel obliged to
415do for you.</p>
416
417<p>As a rule of thumb, volunteers will generally answer polite questions about
418a given version for about three years after its release before it's so old
419we don't remember the answer off the top of our head. And if you want us to
420put any _effort_ into tracking it down, we want you to put in a little effort
421of your own by confirming it's still a problem with the current version. It's
422also hard for us to fix a problem of yours if we can't reproduce it because
423we don't have any systems running an environment that old.</p>
424
425<p>A consultant will happily set up a special environment just to reproduce
426your problem, and you can always ask on the list if any of the developers
427have consulting rates.</p>
428
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000429<hr />
430<p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000431<h2><a name="init">Busybox init isn't working!</a></h2>
Mike Frysinger77dbe732005-04-17 04:32:22 +0000432<p>
Rob Landleyc5e4ab72006-06-29 04:59:11 +0000433 Init is the first program that runs, so it might be that no programs are
434 working on your new system because of a problem with your cross-compiler,
435 kernel, console settings, shared libraries, root filesystem... To rule all
436 that out, first build a statically linked version of the following "hello
437 world" program with your cross compiler toolchain:
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000438</p>
439<pre>
440#include &lt;stdio.h&gt;
Mike Frysinger77dbe732005-04-17 04:32:22 +0000441
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000442int main(int argc, char *argv)
443{
444 printf("Hello world!\n");
445 sleep(999999999);
446}
447</pre>
448
449<p>
450 Now try to boot your device with an "init=" argument pointing to your
451 hello world program. Did you see the hello world message? Until you
452 do, don't bother messing with busybox init.
453</p>
454
455<p>
456 Once you've got it working statically linked, try getting it to work
457 dynamically linked. Then read the FAQ entry <a href="#build_system">How
Rob Landleyc5e4ab72006-06-29 04:59:11 +0000458 do I build a BusyBox-based system?</a>, and the
459 <a href="/downloads/BusyBox.html#item_init">documentation for BusyBox
460 init</a>.
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000461</p>
Mike Frysinger77dbe732005-04-17 04:32:22 +0000462
463<hr />
464<p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000465<h2><a name="sed">I can't configure busybox on my system.</a></h2>
466<p>
467 Configuring Busybox depends on a recent version of sed. Older
468 distributions (Red Hat 7.2, Debian 3.0) may not come with a
469 usable version. Luckily BusyBox can use its own sed to configure itself,
470 although this leads to a bit of a chicken and egg problem.
471 You can work around this by hand-configuring busybox to build with just
472 sed, then putting that sed in your path to configure the rest of busybox
473 with, like so:
474</p>
475
476<pre>
477 tar xvjf sources/busybox-x.x.x.tar.bz2
478 cd busybox-x.x.x
479 make allnoconfig
480 make include/bb_config.h
481 echo "CONFIG_SED=y" >> .config
482 echo "#undef ENABLE_SED" >> include/bb_config.h
483 echo "#define ENABLE_SED 1" >> include/bb_config.h
484 make
485 mv busybox sed
486 export PATH=`pwd`:"$PATH"
487</pre>
488
489<p>Then you can run "make defconfig" or "make menuconfig" normally.</p>
490
491<hr />
492<p>
493<h2><a name="job_control">Why do I keep getting "sh: can't access tty; job control turned off" errors? Why doesn't Control-C work within my shell?</a></h2>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000494<p>
495
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000496 Job control will be turned off since your shell can not obtain a controlling
497 terminal. This typically happens when you run your shell on /dev/console.
498 The kernel will not provide a controlling terminal on the /dev/console
499 device. Your should run your shell on a normal tty such as tty1 or ttyS0
500 and everything will work perfectly. If you <em>REALLY</em> want your shell
501 to run on /dev/console, then you can hack your kernel (if you are into that
502 sortof thing) by changing drivers/char/tty_io.c to change the lines where
503 it sets "noctty = 1;" to instead set it to "0". I recommend you instead
504 run your shell on a real console...
505</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000506
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000507<h1>Development</h1>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000508
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000509<h2><b><a name="goals">What are the goals of busybox?</a></b></h2>
510
511<p>Busybox aims to be the smallest and simplest correct implementation of the
512standard Linux command line tools. First and foremost, this means the
513smallest executable size we can manage. We also want to have the simplest
514and cleanest implementation we can manage, be <a href="#standards">standards
515compliant</a>, minimize run-time memory usage (heap and stack), run fast, and
516take over the world.</p>
517
518<h2><b><a name="design">What is the design of busybox?</a></b></h2>
519
520<p>Busybox is like a swiss army knife: one thing with many functions.
521The busybox executable can act like many different programs depending on
522the name used to invoke it. Normal practice is to create a bunch of symlinks
523pointing to the busybox binary, each of which triggers a different busybox
524function. (See <a href="FAQ.html#getting_started">getting started</a> in the
525FAQ for more information on usage, and <a href="BusyBox.html">the
526busybox documentation</a> for a list of symlink names and what they do.)
527
528<p>The "one binary to rule them all" approach is primarily for size reasons: a
529single multi-purpose executable is smaller then many small files could be.
530This way busybox only has one set of ELF headers, it can easily share code
531between different apps even when statically linked, it has better packing
532efficiency by avoding gaps between files or compression dictionary resets,
533and so on.</p>
534
535<p>Work is underway on new options such as "make standalone" to build separate
536binaries for each applet, and a "libbb.so" to make the busybox common code
537available as a shared library. Neither is ready yet at the time of this
538writing.</p>
539
540<a name="source"></a>
541
542<h2><a name="source_applets"><b>The applet directories</b></a></h2>
543
544<p>The directory "applets" contains the busybox startup code (applets.c and
545busybox.c), and several subdirectories containing the code for the individual
546applets.</p>
547
548<p>Busybox execution starts with the main() function in applets/busybox.c,
Denis Vlasenko8f8f2682006-10-03 21:00:43 +0000549which sets the global variable applet_name to argv[0] and calls
Denis Vlasenkoe4f2d062007-04-11 17:03:19 +0000550run_applet_and_exit() in applets/applets.c. That uses the applets[] array
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000551(defined in include/busybox.h and filled out in include/applets.h) to
552transfer control to the appropriate APPLET_main() function (such as
553cat_main() or sed_main()). The individual applet takes it from there.</p>
554
555<p>This is why calling busybox under a different name triggers different
556functionality: main() looks up argv[0] in applets[] to get a function pointer
557to APPLET_main().</p>
558
559<p>Busybox applets may also be invoked through the multiplexor applet
560"busybox" (see busybox_main() in applets/busybox.c), and through the
561standalone shell (grep for STANDALONE_SHELL in applets/shell/*.c).
562See <a href="FAQ.html#getting_started">getting started</a> in the
563FAQ for more information on these alternate usage mechanisms, which are
564just different ways to reach the relevant APPLET_main() function.</p>
565
566<p>The applet subdirectories (archival, console-tools, coreutils,
567debianutils, e2fsprogs, editors, findutils, init, loginutils, miscutils,
568modutils, networking, procps, shell, sysklogd, and util-linux) correspond
569to the configuration sub-menus in menuconfig. Each subdirectory contains the
570code to implement the applets in that sub-menu, as well as a Config.in
571file defining that configuration sub-menu (with dependencies and help text
572for each applet), and the makefile segment (Makefile.in) for that
573subdirectory.</p>
574
575<p>The run-time --help is stored in usage_messages[], which is initialized at
576the start of applets/applets.c and gets its help text from usage.h. During the
577build this help text is also used to generate the BusyBox documentation (in
578html, txt, and man page formats) in the docs directory. See
579<a href="#adding">adding an applet to busybox</a> for more
580information.</p>
581
582<h2><a name="source_libbb"><b>libbb</b></a></h2>
583
584<p>Most non-setup code shared between busybox applets lives in the libbb
585directory. It's a mess that evolved over the years without much auditing
586or cleanup. For anybody looking for a great project to break into busybox
587development with, documenting libbb would be both incredibly useful and good
588experience.</p>
589
590<p>Common themes in libbb include allocation functions that test
591for failure and abort the program with an error message so the caller doesn't
592have to test the return value (xmalloc(), xstrdup(), etc), wrapped versions
593of open(), close(), read(), and write() that test for their own failures
594and/or retry automatically, linked list management functions (llist.c),
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000595command line argument parsing (getopt32.c), and a whole lot more.</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000596
597<hr />
Rob Landleyc7a3e1b2005-07-31 04:25:00 +0000598<p>
599<h2><a name="optimize">I want to make busybox even smaller, how do I go about it?</a></h2>
600<p>
601 To conserve bytes it's good to know where they're being used, and the
602 size of the final executable isn't always a reliable indicator of
603 the size of the components (since various structures are rounded up,
604 so a small change may not even be visible by itself, but many small
605 savings add up).
606</p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000607
608<p> The busybox Makefile builds two versions of busybox, one of which
609 (busybox_unstripped) has extra information that various analysis tools
610 can use. (This has nothing to do with CONFIG_DEBUG, leave that off
611 when trying to optimize for size.)
612</p>
613
614<p> The <b>"make bloatcheck"</b> option uses Matt Mackall's bloat-o-meter
615 script to compare two versions of busybox (busybox_unstripped vs
616 busybox_old), and report which symbols changed size and by how much.
Rob Landleyd244bc12006-05-27 21:30:34 +0000617 To use it, first build a base version with <b>"make baseline"</b>.
618 (This creates busybox_old, which should have the original sizes for
619 comparison purposes.) Then build the new version with your changes
620 and run "make bloatcheck" to see the size differences from the old
621 version.
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000622</p>
Rob Landleyc7a3e1b2005-07-31 04:25:00 +0000623<p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000624 The first line of output has totals: how many symbols were added or
625 removed, how many symbols grew or shrank, the number of bytes added
626 and number of bytes removed by these changes, and finally the total
627 number of bytes difference between the two files. The remaining
628 lines show each individual symbol, the old and new sizes, and the
629 increase or decrease in size (which results are sorted by).
630</p>
631<p>
632 The <b>"make sizes"</b> option produces raw symbol size information for
633 busybox_unstripped. This is the output from the "nm --size-sort"
634 command (see "man nm" for more information), and is the information
635 bloat-o-meter parses to produce the comparison report above. For
636 defconfig, this is a good way to find the largest symbols in the tree
637 (which is a good place to start when trying to shrink the code). To
638 take a closer look at individual applets, configure busybox with just
639 one applet (run "make allnoconfig" and then switch on a single applet
640 with menuconfig), and then use "make sizes" to see the size of that
641 applet's components.
642</p>
643<p>
644 The "showasm" command (in the scripts directory) produces an assembly
645 dump of a function, providing a closer look at what changed. Try
646 "scripts/showasm busybox_unstripped" to list available symbols, and
647 "scripts/showasm busybox_unstripped symbolname" to see the assembly
648 for a sepecific symbol.
Rob Landleyc7a3e1b2005-07-31 04:25:00 +0000649</p>
650<hr />
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000651
Rob Landleyc7a3e1b2005-07-31 04:25:00 +0000652
653
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000654<h2><a name="adding"><b>Adding an applet to busybox</b></a></h2>
655
656<p>To add a new applet to busybox, first pick a name for the applet and
657a corresponding CONFIG_NAME. Then do this:</p>
658
659<ul>
660<li>Figure out where in the busybox source tree your applet best fits,
661and put your source code there. Be sure to use APPLET_main() instead
662of main(), where APPLET is the name of your applet.</li>
663
664<li>Add your applet to the relevant Config.in file (which file you add
665it to determines where it shows up in "make menuconfig"). This uses
666the same general format as the linux kernel's configuration system.</li>
667
668<li>Add your applet to the relevant Makefile.in file (in the same
669directory as the Config.in you chose), using the existing entries as a
670template and the same CONFIG symbol as you used for Config.in. (Don't
671forget "needlibm" or "needcrypt" if your applet needs libm or
672libcrypt.)</li>
673
674<li>Add your applet to "include/applets.h", using one of the existing
675entries as a template. (Note: this is in alphabetical order. Applets
676are found via binary search, and if you add an applet out of order it
677won't work.)</li>
678
679<li>Add your applet's runtime help text to "include/usage.h". You need
680at least appname_trivial_usage (the minimal help text, always included
681in the busybox binary when this applet is enabled) and appname_full_usage
682(extra help text included in the busybox binary with
683CONFIG_FEATURE_VERBOSE_USAGE is enabled), or it won't compile.
684The other two help entry types (appname_example_usage and
685appname_notes_usage) are optional. They don't take up space in the binary,
686but instead show up in the generated documentation (BusyBox.html,
687BusyBox.txt, and the man page BusyBox.1).</li>
688
689<li>Run menuconfig, switch your applet on, compile, test, and fix the
690bugs. Be sure to try both "allyesconfig" and "allnoconfig" (and
691"allbareconfig" if relevant).</li>
692
693</ul>
694
695<h2><a name="standards">What standards does busybox adhere to?</a></h2>
696
697<p>The standard we're paying attention to is the "Shell and Utilities"
698portion of the <a href="http://www.opengroup.org/onlinepubs/009695399/">Open
699Group Base Standards</a> (also known as the Single Unix Specification version
7003 or SUSv3). Note that paying attention isn't necessarily the same thing as
701following it.</p>
702
703<p>SUSv3 doesn't even mention things like init, mount, tar, or losetup, nor
704commonly used options like echo's '-e' and '-n', or sed's '-i'. Busybox is
705driven by what real users actually need, not the fact the standard believes
706we should implement ed or sccs. For size reasons, we're unlikely to include
707much internationalization support beyond UTF-8, and on top of all that, our
708configuration menu lets developers chop out features to produce smaller but
709very non-standard utilities.</p>
710
711<p>Also, Busybox is aimed primarily at Linux. Unix standards are interesting
712because Linux tries to adhere to them, but portability to dozens of platforms
713is only interesting in terms of offering a restricted feature set that works
714everywhere, not growing dozens of platform-specific extensions. Busybox
715should be portable to all hardware platforms Linux supports, and any other
716similar operating systems that are easy to do and won't require much
717maintenance.</p>
718
719<p>In practice, standards compliance tends to be a clean-up step once an
720applet is otherwise finished. When polishing and testing a busybox applet,
721we ensure we have at least the option of full standards compliance, or else
722document where we (intentionally) fall short.</p>
723
724<h2><a name="portability">Portability.</a></h2>
725
726<p>Busybox is a Linux project, but that doesn't mean we don't have to worry
727about portability. First of all, there are different hardware platforms,
728different C library implementations, different versions of the kernel and
729build toolchain... The file "include/platform.h" exists to centralize and
730encapsulate various platform-specific things in one place, so most busybox
731code doesn't have to care where it's running.</p>
732
733<p>To start with, Linux runs on dozens of hardware platforms. We try to test
734each release on x86, x86-64, arm, power pc, and mips. (Since qemu can handle
735all of these, this isn't that hard.) This means we have to care about a number
736of portability issues like endianness, word size, and alignment, all of which
737belong in platform.h. That header handles conditional #includes and gives
738us macros we can use in the rest of our code. At some point in the future
739we might grow a platform.c, possibly even a platform subdirectory. As long
740as the applets themselves don't have to care.</p>
741
742<p>On a related note, we made the "default signedness of char varies" problem
743go away by feeding the compiler -funsigned-char. This gives us consistent
744behavior on all platforms, and defaults to 8-bit clean text processing (which
745gets us halfway to UTF-8 support). NOMMU support is less easily separated
746(see the tips section later in this document), but we're working on it.</p>
747
748<p>Another type of portability is build environments: we unapologetically use
749a number of gcc and glibc extensions (as does the Linux kernel), but these have
750been picked up by packages like uClibc, TCC, and Intel's C Compiler. As for
751gcc, we take advantage of newer compiler optimizations to get the smallest
752possible size, but we also regression test against an older build environment
753using the Red Hat 9 image at "http://busybox.net/downloads/qemu". This has a
7542.4 kernel, gcc 3.2, make 3.79.1, and glibc 2.3, and is the oldest
755build/deployment environment we still put any effort into maintaining. (If
756anyone takes an interest in older kernels you're welcome to submit patches,
757but the effort would probably be better spent
758<a href="http://www.selenic.com/linux-tiny/">trimming
759down the 2.6 kernel</a>.) Older gcc versions than that are uninteresting since
760we now use c99 features, although
761<a href="http://fabrice.bellard.free.fr/tcc/">tcc</a> might be worth a
762look.</p>
763
764<p>We also test busybox against the current release of uClibc. Older versions
765of uClibc aren't very interesting (they were buggy, and uClibc wasn't really
766usable as a general-purpose C library before version 0.9.26 anyway).</p>
767
768<p>Other unix implementations are mostly uninteresting, since Linux binaries
769have become the new standard for portable Unix programs. Specifically,
770the ubiquity of Linux was cited as the main reason the Intel Binary
771Compatability Standard 2 died, by the standards group organized to name a
772successor to ibcs2: <a href="http://www.telly.org/86open/">the 86open
773project</a>. That project disbanded in 1999 with the endorsement of an
774existing standard: Linux ELF binaries. Since then, the major players at the
775time (such as <a
776href=http://www-03.ibm.com/servers/aix/products/aixos/linux/index.html>AIX</a>, <a
777href=http://www.sun.com/software/solaris/ds/linux_interop.jsp#3>Solaris</a>, and
778<a href=http://www.onlamp.com/pub/a/bsd/2000/03/17/linuxapps.html>FreeBSD</a>)
779have all either grown Linux support or folded.</p>
780
781<p>The major exceptions are newcomer MacOS X, some embedded environments
782(such as newlib+libgloss) which provide a posix environment but not a full
783Linux environment, and environments like Cygwin that provide only partial Linux
784emulation. Also, some embedded Linux systems run a Linux kernel but amputate
785things like the /proc directory to save space.</p>
786
787<p>Supporting these systems is largely a question of providing a clean subset
788of BusyBox's functionality -- whichever applets can easily be made to
789work in that environment. Annotating the configuration system to
790indicate which applets require which prerequisites (such as procfs) is
791also welcome. Other efforts to support these systems (swapping #include
792files to build in different environments, adding adapter code to platform.h,
793adding more extensive special-case supporting infrastructure such as mount's
794legacy mtab support) are handled on a case-by-case basis. Support that can be
795cleanly hidden in platform.h is reasonably attractive, and failing that
796support that can be cleanly separated into a separate conditionally compiled
797file is at least worth a look. Special-case code in the body of an applet is
798something we're trying to avoid.</p>
799
800<h2><a name="tips" />Programming tips and tricks.</a></h2>
801
802<p>Various things busybox uses that aren't particularly well documented
803elsewhere.</p>
804
805<h2><a name="tips_encrypted_passwords">Encrypted Passwords</a></h2>
806
807<p>Password fields in /etc/passwd and /etc/shadow are in a special format.
808If the first character isn't '$', then it's an old DES style password. If
809the first character is '$' then the password is actually three fields
810separated by '$' characters:</p>
811<pre>
812 <b>$type$salt$encrypted_password</b>
813</pre>
814
815<p>The "type" indicates which encryption algorithm to use: 1 for MD5 and 2 for SHA1.</p>
816
817<p>The "salt" is a bunch of ramdom characters (generally 8) the encryption
818algorithm uses to perturb the password in a known and reproducible way (such
819as by appending the random data to the unencrypted password, or combining
820them with exclusive or). Salt is randomly generated when setting a password,
821and then the same salt value is re-used when checking the password. (Salt is
822thus stored unencrypted.)</p>
823
824<p>The advantage of using salt is that the same cleartext password encrypted
825with a different salt value produces a different encrypted value.
826If each encrypted password uses a different salt value, an attacker is forced
827to do the cryptographic math all over again for each password they want to
828check. Without salt, they could simply produce a big dictionary of commonly
829used passwords ahead of time, and look up each password in a stolen password
830file to see if it's a known value. (Even if there are billions of possible
831passwords in the dictionary, checking each one is just a binary search against
832a file only a few gigabytes long.) With salt they can't even tell if two
833different users share the same password without guessing what that password
834is and decrypting it. They also can't precompute the attack dictionary for
835a specific password until they know what the salt value is.</p>
836
837<p>The third field is the encrypted password (plus the salt). For md5 this
838is 22 bytes.</p>
839
840<p>The busybox function to handle all this is pw_encrypt(clear, salt) in
841"libbb/pw_encrypt.c". The first argument is the clear text password to be
842encrypted, and the second is a string in "$type$salt$password" format, from
843which the "type" and "salt" fields will be extracted to produce an encrypted
844value. (Only the first two fields are needed, the third $ is equivalent to
845the end of the string.) The return value is an encrypted password in
846/etc/passwd format, with all three $ separated fields. It's stored in
847a static buffer, 128 bytes long.</p>
848
849<p>So when checking an existing password, if pw_encrypt(text,
850old_encrypted_password) returns a string that compares identical to
851old_encrypted_password, you've got the right password. When setting a new
852password, generate a random 8 character salt string, put it in the right
853format with sprintf(buffer, "$%c$%s", type, salt), and feed buffer as the
854second argument to pw_encrypt(text,buffer).</p>
855
856<h2><a name="tips_vfork">Fork and vfork</a></h2>
857
858<p>On systems that haven't got a Memory Management Unit, fork() is unreasonably
859expensive to implement (and sometimes even impossible), so a less capable
860function called vfork() is used instead. (Using vfork() on a system with an
861MMU is like pounding a nail with a wrench. Not the best tool for the job, but
862it works.)</p>
863
864<p>Busybox hides the difference between fork() and vfork() in
865libbb/bb_fork_exec.c. If you ever want to fork and exec, use bb_fork_exec()
866(which returns a pid and takes the same arguments as execve(), although in
867this case envp can be NULL) and don't worry about it. This description is
868here in case you want to know why that does what it does.</p>
869
870<p>Implementing fork() depends on having a Memory Management Unit. With an
871MMU then you can simply set up a second set of page tables and share the
872physical memory via copy-on-write. So a fork() followed quickly by exec()
873only copies a few pages of the parent's memory, just the ones it changes
874before freeing them.</p>
875
876<p>With a very primitive MMU (using a base pointer plus length instead of page
877tables, which can provide virtual addresses and protect processes from each
878other, but no copy on write) you can still implement fork. But it's
879unreasonably expensive, because you have to copy all the parent process'
880memory into the new process (which could easily be several megabytes per fork).
881And you have to do this even though that memory gets freed again as soon as the
882exec happens. (This is not just slow and a waste of space but causes memory
883usage spikes that can easily cause the system to run out of memory.)</p>
884
885<p>Without even a primitive MMU, you have no virtual addresses. Every process
886can reach out and touch any other process' memory, because all pointers are to
887physical addresses with no protection. Even if you copy a process' memory to
888new physical addresses, all of its pointers point to the old objects in the
889old process. (Searching through the new copy's memory for pointers and
890redirect them to the new locations is not an easy problem.)</p>
891
892<p>So with a primitive or missing MMU, fork() is just not a good idea.</p>
893
894<p>In theory, vfork() is just a fork() that writeably shares the heap and stack
895rather than copying it (so what one process writes the other one sees). In
896practice, vfork() has to suspend the parent process until the child does exec,
897at which point the parent wakes up and resumes by returning from the call to
898vfork(). All modern kernel/libc combinations implement vfork() to put the
899parent to sleep until the child does its exec. There's just no other way to
900make it work: the parent has to know the child has done its exec() or exit()
901before it's safe to return from the function it's in, so it has to block
902until that happens. In fact without suspending the parent there's no way to
903even store separate copies of the return value (the pid) from the vfork() call
904itself: both assignments write into the same memory location.</p>
905
906<p>One way to understand (and in fact implement) vfork() is this: imagine
907the parent does a setjmp and then continues on (pretending to be the child)
908until the exec() comes around, then the _exec_ does the actual fork, and the
909parent does a longjmp back to the original vfork call and continues on from
910there. (It thus becomes obvious why the child can't return, or modify
911local variables it doesn't want the parent to see changed when it resumes.)
912
913<p>Note a common mistake: the need for vfork doesn't mean you can't have two
914processes running at the same time. It means you can't have two processes
915sharing the same memory without stomping all over each other. As soon as
916the child calls exec(), the parent resumes.</p>
917
918<p>If the child's attempt to call exec() fails, the child should call _exit()
919rather than a normal exit(). This avoids any atexit() code that might confuse
920the parent. (The parent should never call _exit(), only a vforked child that
921failed to exec.)</p>
922
923<p>(Now in theory, a nommu system could just copy the _stack_ when it forks
924(which presumably is much shorter than the heap), and leave the heap shared.
925Even with no MMU at all
926In practice, you've just wound up in a multi-threaded situation and you can't
927do a malloc() or free() on your heap without freeing the other process' memory
928(and if you don't have the proper locking for being threaded, corrupting the
929heap if both of you try to do it at the same time and wind up stomping on
930each other while traversing the free memory lists). The thing about vfork is
931that it's a big red flag warning "there be dragons here" rather than
932something subtle and thus even more dangerous.)</p>
933
934<h2><a name="tips_sort_read">Short reads and writes</a></h2>
935
936<p>Busybox has special functions, bb_full_read() and bb_full_write(), to
937check that all the data we asked for got read or written. Is this a real
938world consideration? Try the following:</p>
939
940<pre>while true; do echo hello; sleep 1; done | tee out.txt</pre>
941
942<p>If tee is implemented with bb_full_read(), tee doesn't display output
943in real time but blocks until its entire input buffer (generally a couple
944kilobytes) is read, then displays it all at once. In that case, we _want_
945the short read, for user interface reasons. (Note that read() should never
946return 0 unless it has hit the end of input, and an attempt to write 0
947bytes should be ignored by the OS.)</p>
948
949<p>As for short writes, play around with two processes piping data to each
950other on the command line (cat bigfile | gzip &gt; out.gz) and suspend and
951resume a few times (ctrl-z to suspend, "fg" to resume). The writer can
952experience short writes, which are especially dangerous because if you don't
953notice them you'll discard data. They can also happen when a system is under
954load and a fast process is piping to a slower one. (Such as an xterm waiting
955on x11 when the scheduler decides X is being a CPU hog with all that
956text console scrolling...)</p>
957
958<p>So will data always be read from the far end of a pipe at the
959same chunk sizes it was written in? Nope. Don't rely on that. For one
Denis Vlasenkof7996f32007-01-11 17:20:00 +0000960counterexample, see <a href="http://www.faqs.org/rfcs/rfc896.html">rfc 896
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000961for Nagle's algorithm</a>, which waits a fraction of a second or so before
962sending out small amounts of data through a TCP/IP connection in case more
963data comes in that can be merged into the same packet. (In case you were
964wondering why action games that use TCP/IP set TCP_NODELAY to lower the latency
965on their their sockets, now you know.)</p>
966
967<h2><a name="tips_memory">Memory used by relocatable code, PIC, and static linking.</a></h2>
968
969<p>The downside of standard dynamic linking is that it results in self-modifying
970code. Although each executable's pages are mmaped() into a process' address
971space from the executable file and are thus naturally shared between processes
972out of the page cache, the library loader (ld-linux.so.2 or ld-uClibc.so.0)
973writes to these pages to supply addresses for relocatable symbols. This
974dirties the pages, triggering copy-on-write allocation of new memory for each
975processes' dirtied pages.</p>
976
977<p>One solution to this is Position Independent Code (PIC), a way of linking
978a file so all the relocations are grouped together. This dirties fewer
979pages (often just a single page) for each process' relocations. The down
980side is this results in larger executables, which take up more space on disk
981(and a correspondingly larger space in memory). But when many copies of the
982same program are running, PIC dynamic linking trades a larger disk footprint
983for a smaller memory footprint, by sharing more pages.</p>
984
985<p>A third solution is static linking. A statically linked program has no
986relocations, and thus the entire executable is shared between all running
987instances. This tends to have a significantly larger disk footprint, but
988on a system with only one or two executables, shared libraries aren't much
989of a win anyway.</p>
990
991<p>You can tell the glibc linker to display debugging information about its
992relocations with the environment variable "LD_DEBUG". Try
993"LD_DEBUG=help /bin/true" for a list of commands. Learning to interpret
994"LD_DEBUG=statistics cat /proc/self/statm" could be interesting.</p>
995
996<p>For more on this topic, here's Rich Felker:</p>
997<blockquote>
998<p>Dynamic linking (without fixed load addresses) fundamentally requires
999at least one dirty page per dso that uses symbols. Making calls (but
1000never taking the address explicitly) to functions within the same dso
1001does not require a dirty page by itself, but will with ELF unless you
1002use -Bsymbolic or hidden symbols when linking.</p>
1003
1004<p>ELF uses significant additional stack space for the kernel to pass all
1005the ELF data structures to the newly created process image. These are
1006located above the argument list and environment. This normally adds 1
1007dirty page to the process size.</p>
1008
1009<p>The ELF dynamic linker has its own data segment, adding one or more
1010dirty pages. I believe it also performs relocations on itself.</p>
1011
1012<p>The ELF dynamic linker makes significant dynamic allocations to manage
1013the global symbol table and the loaded dso's. This data is never
1014freed. It will be needed again if libdl is used, so unconditionally
1015freeing it is not possible, but normal programs do not use libdl. Of
1016course with glibc all programs use libdl (due to nsswitch) so the
1017issue was never addressed.</p>
1018
1019<p>ELF also has the issue that segments are not page-aligned on disk.
1020This saves up to 4k on disk, but at the expense of using an additional
1021dirty page in most cases, due to a large portion of the first data
1022page being filled with a duplicate copy of the last text page.</p>
1023
1024<p>The above is just a partial list of the tiny memory penalties of ELF
1025dynamic linking, which eventually add up to quite a bit. The smallest
1026I've been able to get a process down to is 8 dirty pages, and the
1027above factors seem to mostly account for it (but some were difficult
1028to measure).</p>
1029</blockquote>
1030
1031<h2><a name="tips_kernel_headers"></a>Including kernel headers</h2>
1032
1033<p>The "linux" or "asm" directories of /usr/include contain Linux kernel
1034headers, so that the C library can talk directly to the Linux kernel. In
1035a perfect world, applications shouldn't include these headers directly, but
1036we don't live in a perfect world.</p>
1037
1038<p>For example, Busybox's losetup code wants linux/loop.c because nothing else
1039#defines the structures to call the kernel's loopback device setup ioctls.
1040Attempts to cut and paste the information into a local busybox header file
1041proved incredibly painful, because portions of the loop_info structure vary by
1042architecture, namely the type __kernel_dev_t has different sizes on alpha,
1043arm, x86, and so on. Meaning we either #include <linux/posix_types.h> or
1044we hardwire #ifdefs to check what platform we're building on and define this
1045type appropriately for every single hardware architecture supported by
1046Linux, which is simply unworkable.</p>
1047
1048<p>This is aside from the fact that the relevant type defined in
1049posix_types.h was renamed to __kernel_old_dev_t during the 2.5 series, so
1050to cut and paste the structure into our header we have to #include
1051<linux/version.h> to figure out which name to use. (What we actually do is
1052check if we're building on 2.6, and if so just use the new 64 bit structure
1053instead to avoid the rename entirely.) But we still need the version
1054check, since 2.4 didn't have the 64 bit structure.</p>
1055
1056<p>The BusyBox developers spent <u>two years</u> trying to figure
1057out a clean way to do all this. There isn't one. The losetup in the
1058util-linux package from kernel.org isn't doing it cleanly either, they just
1059hide the ugliness by nesting #include files. Their mount/loop.h
1060#includes "my_dev_t.h", which #includes <linux/posix_types.h> and
1061<linux/version.h> just like we do. There simply is no alternative.</p>
1062
1063<p>Just because directly #including kernel headers is sometimes
1064unavoidable doesn't me we should include them when there's a better
1065way to do it. However, block copying information out of the kernel headers
1066is not a better way.</p>
1067
1068<h2><a name="who">Who are the BusyBox developers?</a></h2>
1069
1070<p>The following login accounts currently exist on busybox.net. (I.E. these
1071people can commit <a href="http://busybox.net/downloads/patches">patches</a>
1072into subversion for the BusyBox, uClibc, and buildroot projects.)</p>
1073
1074<pre>
1075aldot :Bernhard Fischer
Denis Vlasenkoabfc4cf2006-11-18 16:30:04 +00001076andersen :Erik Andersen - uClibc and BuildRoot maintainer.
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001077bug1 :Glenn McGrath
1078davidm :David McCullough
Denis Vlasenkoabfc4cf2006-11-18 16:30:04 +00001079gkajmowi :Garrett Kajmowicz - uClibc++ maintainer
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001080jbglaw :Jan-Benedict Glaw
1081jocke :Joakim Tjernlund
Denis Vlasenkoabfc4cf2006-11-18 16:30:04 +00001082landley :Rob Landley - BusyBox maintainer
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001083lethal :Paul Mundt
1084mjn3 :Manuel Novoa III
1085osuadmin :osuadmin
1086pgf :Paul Fox
1087pkj :Peter Kjellerstedt
1088prpplague :David Anders
1089psm :Peter S. Mazinger
1090russ :Russ Dill
1091sandman :Robert Griebl
1092sjhill :Steven J. Hill
1093solar :Ned Ludd
1094timr :Tim Riker
1095tobiasa :Tobias Anderberg
1096vapier :Mike Frysinger
1097</pre>
1098
1099<p>The following accounts used to exist on busybox.net, but don't anymore so
Denis Vlasenkoabfc4cf2006-11-18 16:30:04 +00001100I can't ask /etc/passwd for their names. Rob Wentworth <robwen@gmail.com>
1101asked Google and recovered the names:</p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001102
1103<pre>
Denis Vlasenkoabfc4cf2006-11-18 16:30:04 +00001104aaronl :Aaron Lehmann
1105beppu :John Beppu
1106dwhedon :David Whedon
1107erik :Erik Andersen
Denis Vlasenkof7996f32007-01-11 17:20:00 +00001108gfeldman :Gennady Feldman
Denis Vlasenkoabfc4cf2006-11-18 16:30:04 +00001109jimg :Jim Gleason
1110kraai :Matt Kraai
1111markw :Mark Whitley
1112miles :Miles Bader
1113proski :Pavel Roskin
1114rjune :Richard June
1115tausq :Randolph Chung
1116vodz :Vladimir N. Oleynik
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001117</pre>
1118
1119
Eric Andersen6c4a6b12004-10-08 10:50:08 +00001120<br>
1121<br>
1122<br>
1123
1124<!--#include file="footer.html" -->