aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-01-14 23:28:15 -0600
committerRob Landley <rob@landley.net>2012-01-14 23:28:15 -0600
commit8f8c504e585b6850abf628cabdb9ef231bef1a35 (patch)
treed48fdea1a9aff87165a7ed881ee9f540206147d5 /main.c
parentd11887170a084171d3c17201c76f87b2567a8d65 (diff)
downloadtoybox-8f8c504e585b6850abf628cabdb9ef231bef1a35.tar.gz
Expand comments.
Diffstat (limited to 'main.c')
-rw-r--r--main.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/main.c b/main.c
index 4b4b3765..3feaca0c 100644
--- a/main.c
+++ b/main.c
@@ -29,7 +29,7 @@ struct toy_list *toy_find(char *name)
{
int top, bottom, middle;
- // If the name starts with "toybox", accept that as a match. Otherwise
+ // If the name starts with "toybox" accept that as a match. Otherwise
// skip the first entry, which is out of order.
if (!strncmp(name,"toybox",6)) return toy_list;
@@ -52,7 +52,8 @@ struct toy_list *toy_find(char *name)
// Figure out whether or not anything is using the option parsing logic,
// because the compiler can't figure out whether or not to optimize it away
-// on its' own.
+// on its' own. NEED_OPTIONS becomes a constant allowing if() to optimize
+// stuff out via dead code elimination.
#undef NEWTOY
#undef OLDTOY
@@ -62,6 +63,8 @@ static const int NEED_OPTIONS =
#include "generated/newtoys.h"
0; // Ends the opts || opts || opts...
+// Setup toybox global state for this command.
+
void toy_init(struct toy_list *which, char *argv[])
{
// Drop permissions for non-suid commands.
@@ -90,7 +93,8 @@ void toy_init(struct toy_list *which, char *argv[])
if (which->flags & TOYFLAG_UMASK) toys.old_umask = umask(0);
}
-// Run a toy.
+// Like exec() but runs an internal toybox command instead of another file.
+// Only returns if it can't find the command, otherwise exit() when done.
void toy_exec(char *argv[])
{
struct toy_list *which;
@@ -102,6 +106,9 @@ void toy_exec(char *argv[])
exit(toys.exitval);
}
+// Multiplexer command, first argument is command to run, rest are args to that.
+// If first argument starts with - output list of command install paths.
+
void toybox_main(void)
{
static char *toy_paths[]={"usr/","bin/","sbin/",0};
@@ -140,13 +147,15 @@ int main(int argc, char *argv[])
{
char *name;
- // Figure out which applet to call.
+ // Trim path off of command name
name = rindex(argv[0], '/');
if (!name) name=argv[0];
else name++;
argv[0] = name;
}
+ // Call the multiplexer, adjusting this argv[] to be its' argv[1].
+ // (It will adjust it back before calling toy_exec().)
toys.argv = argv-1;
toybox_main();
return 0;