My os has no fork/exec - can I use busybox?

Denys Vlasenko vda.linux at googlemail.com
Sat Nov 7 00:04:02 UTC 2009


On Thursday 05 November 2009 23:19, busby1 at llnl.gov wrote:
> I'm writing user-level code on a high performance computer (IBM Blue
> Gene).  The OS is missing some system calls, including fork/exec.

Without fork, you only lose ash applet.

But without exec, stock busybox is nearly useless.

The biggest problem is not that exec is not available
(a fair number of applets don't need exec - like cp),
but the fact that in many cases bbox is happily
aborts on errors and/or doesn't bother to clean up
allocated memory, open files etc,
knowing that returning from main() will exit and
kernel will do it anyway.

If you simply call <applet>_main(), it may exit on error
or leak resources - this is not what you want.

The only applets which are safe to use in this case are
NOFORK applets:

basename
cat
dirname
echo
false
fsync
hostid
length
logname
mkdir
printf
pwd
rm
rmdir
seq
sleep
sync
test
touch
true
usleep
whoami
yes

There was no concerted effort to convert more applets.

That's why, for example, usleep is there and sleep is not -
nobody spent time yet to convert sleep to be suitable
for NOFORK mode.

Please read busybox/docs/nofork_noexec.txt, and look into
hush.c to see how NOFORK applets are detected and called
from C code. In particular, this fragment:

#if ENABLE_FEATURE_SH_STANDALONE
                i = find_applet_by_name(argv_expanded[0]);
                if (i >= 0 && APPLET_IS_NOFORK(i)) {
                        rcode = setup_redirects(command, squirrel);
                        if (rcode == 0) {
                                new_env = expand_assignments(argv, command->assignment_cnt);
                                old_vars = set_vars_and_save_old(new_env);
                                debug_printf_exec(": run_nofork_applet '%s' '%s'...\n",
                                        argv_expanded[0], argv_expanded[1]);
                                rcode = run_nofork_applet(i, argv_expanded);
                        }
                        goto clean_up_and_ret;
                }
#endif

--
vda


More information about the busybox mailing list