main.c revision 29e75d51d447c5c0aae9834f5988b79a945c7acc
113bab2f09e9189c2b1e83ae37a1134108f9479clandley/* Toybox infrastructure.
213bab2f09e9189c2b1e83ae37a1134108f9479clandley *
313bab2f09e9189c2b1e83ae37a1134108f9479clandley * Copyright 2006 Rob Landley <rob@landley.net>
413bab2f09e9189c2b1e83ae37a1134108f9479clandley */
513bab2f09e9189c2b1e83ae37a1134108f9479clandley
6c56215062c961402515daeef8330ed75cd94af29landley#include "toys.h"
7c56215062c961402515daeef8330ed75cd94af29landley
890afbad4c1f115d5363fe99eb797d2458cd298a0Rob Landley#ifndef TOYBOX_VERSION
98387fcb03edc718f031bc5b6af056c2ef408f3d5Paul Barker#define TOYBOX_VERSION "0.7.1"
1090afbad4c1f115d5363fe99eb797d2458cd298a0Rob Landley#endif
11ad602aa127e44eade76fbb05fd27ee8f5825282aRob Landley
12f2311a42a0751e7c039981857fcf60b40f36b475Rob Landley// Populate toy_list[].
13c56215062c961402515daeef8330ed75cd94af29landley
14a6d696b74adb08d83b21f8299b5443f31a5f43ecRob Landley#undef NEWTOY
15a6d696b74adb08d83b21f8299b5443f31a5f43ecRob Landley#undef OLDTOY
16ec0b482e9fd27cb994b30e0f1b8a4d39a85735ccRob Landley#define NEWTOY(name, opts, flags) {#name, name##_main, OPTSTR_##name, flags},
17f3e56f4e4ff773de95fa2c9daf979734d826fc33Rob Landley#define OLDTOY(name, oldname, flags) \
18f3e56f4e4ff773de95fa2c9daf979734d826fc33Rob Landley  {#name, oldname##_main, OPTSTR_##oldname, flags},
19a6d696b74adb08d83b21f8299b5443f31a5f43ecRob Landley
20c56215062c961402515daeef8330ed75cd94af29landleystruct toy_list toy_list[] = {
2155928b1e0a08d84a5cbc50020f0a8c1024f5b6ceRob Landley#include "generated/newtoys.h"
22c56215062c961402515daeef8330ed75cd94af29landley};
23c56215062c961402515daeef8330ed75cd94af29landley
24933919cd8094e870b3e7a554605fd49b20ddb1e0Rob Landley// global context for this command.
25c56215062c961402515daeef8330ed75cd94af29landley
26c56215062c961402515daeef8330ed75cd94af29landleystruct toy_context toys;
27b1aaba1fc8176ac0b7c202a664d2554aa0967116Rob Landleyunion global_union this;
288fdcfdb4479dff7a993a25a63253f0e749fd99feRob Landleychar toybuf[4096], libbuf[4096];
29c56215062c961402515daeef8330ed75cd94af29landley
304f344e356d2c36c4b1df46917eaef25f82ca79a9landleystruct toy_list *toy_find(char *name)
3113bab2f09e9189c2b1e83ae37a1134108f9479clandley{
327aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  int top, bottom, middle;
3313bab2f09e9189c2b1e83ae37a1134108f9479clandley
34dc1af185e73410c5cad997c600678c212262a13cRob Landley  if (!CFG_TOYBOX) return 0;
35dc1af185e73410c5cad997c600678c212262a13cRob Landley
367aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  // If the name starts with "toybox" accept that as a match.  Otherwise
377aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  // skip the first entry, which is out of order.
3813bab2f09e9189c2b1e83ae37a1134108f9479clandley
397aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  if (!strncmp(name,"toybox",6)) return toy_list;
407aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  bottom = 1;
4113bab2f09e9189c2b1e83ae37a1134108f9479clandley
42933919cd8094e870b3e7a554605fd49b20ddb1e0Rob Landley  // Binary search to find this command.
4313bab2f09e9189c2b1e83ae37a1134108f9479clandley
447aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  top = ARRAY_LEN(toy_list)-1;
457aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  for (;;) {
467aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley    int result;
472c226859cfc911c4a1eea009897050a16714aeecRob Landley
487aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley    middle = (top+bottom)/2;
497aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley    if (middle<bottom || middle>top) return NULL;
507aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley    result = strcmp(name,toy_list[middle].name);
517aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley    if (!result) return toy_list+middle;
527aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley    if (result<0) top=--middle;
537aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley    else bottom = ++middle;
547aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  }
5513bab2f09e9189c2b1e83ae37a1134108f9479clandley}
5613bab2f09e9189c2b1e83ae37a1134108f9479clandley
57fc2224b26c73198d00eba714caf47bd2e3a5e63bRob Landley// Figure out whether or not anything is using the option parsing logic,
58fc2224b26c73198d00eba714caf47bd2e3a5e63bRob Landley// because the compiler can't figure out whether or not to optimize it away
598f8c504e585b6850abf628cabdb9ef231bef1a35Rob Landley// on its' own.  NEED_OPTIONS becomes a constant allowing if() to optimize
608f8c504e585b6850abf628cabdb9ef231bef1a35Rob Landley// stuff out via dead code elimination.
61fc2224b26c73198d00eba714caf47bd2e3a5e63bRob Landley
62fc2224b26c73198d00eba714caf47bd2e3a5e63bRob Landley#undef NEWTOY
63fc2224b26c73198d00eba714caf47bd2e3a5e63bRob Landley#undef OLDTOY
64fc2224b26c73198d00eba714caf47bd2e3a5e63bRob Landley#define NEWTOY(name, opts, flags) opts ||
65f3e56f4e4ff773de95fa2c9daf979734d826fc33Rob Landley#define OLDTOY(name, oldname, flags) OPTSTR_##oldname ||
664307a7b07cec4ad8cbab47a29ba941f8cb041812Rob Landleystatic const int NEED_OPTIONS =
6755928b1e0a08d84a5cbc50020f0a8c1024f5b6ceRob Landley#include "generated/newtoys.h"
68fc2224b26c73198d00eba714caf47bd2e3a5e63bRob Landley0;  // Ends the opts || opts || opts...
69fc2224b26c73198d00eba714caf47bd2e3a5e63bRob Landley
7029e75d51d447c5c0aae9834f5988b79a945c7accRob Landleystatic void unknown(char *name)
7129e75d51d447c5c0aae9834f5988b79a945c7accRob Landley{
7229e75d51d447c5c0aae9834f5988b79a945c7accRob Landley  toys.exitval = 127;
7329e75d51d447c5c0aae9834f5988b79a945c7accRob Landley  error_exit("Unknown command %s", name);
7429e75d51d447c5c0aae9834f5988b79a945c7accRob Landley}
7529e75d51d447c5c0aae9834f5988b79a945c7accRob Landley
763b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley// Setup toybox global state for this command.
77bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landleystatic void toy_singleinit(struct toy_list *which, char *argv[])
78bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley{
79bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley  toys.which = which;
80bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley  toys.argv = argv;
81bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley
829b14cb6b12e6f1b07a1ad401e5cb6e091df4ac2fRob Landley  if (CFG_TOYBOX_I18N) setlocale(LC_ALL, "C"+!!(which->flags & TOYFLAG_LOCALE));
83fc49761a9c992a120a27cca016d6a3ed31b1f3d3Rob Landley
8429e75d51d447c5c0aae9834f5988b79a945c7accRob Landley  // Parse --help and --version for (almost) all commands
8529e75d51d447c5c0aae9834f5988b79a945c7accRob Landley  if (CFG_TOYBOX_HELP_DASHDASH && !(which->flags & TOYFLAG_NOHELP) && argv[1]) {
8629e75d51d447c5c0aae9834f5988b79a945c7accRob Landley    if (!strcmp(argv[1], "--help")) {
8729e75d51d447c5c0aae9834f5988b79a945c7accRob Landley      if (CFG_TOYBOX && toys.which == toy_list && toys.argv[2])
8829e75d51d447c5c0aae9834f5988b79a945c7accRob Landley        if (!(toys.which = toy_find(toys.argv[2]))) unknown(toys.argv[2]);
8929e75d51d447c5c0aae9834f5988b79a945c7accRob Landley      show_help(stdout);
9029e75d51d447c5c0aae9834f5988b79a945c7accRob Landley      xexit();
9129e75d51d447c5c0aae9834f5988b79a945c7accRob Landley    }
9229e75d51d447c5c0aae9834f5988b79a945c7accRob Landley
9329e75d51d447c5c0aae9834f5988b79a945c7accRob Landley    if (!strcmp(argv[1], "--version")) {
9429e75d51d447c5c0aae9834f5988b79a945c7accRob Landley      xputs("toybox "TOYBOX_VERSION);
9529e75d51d447c5c0aae9834f5988b79a945c7accRob Landley      xexit();
9629e75d51d447c5c0aae9834f5988b79a945c7accRob Landley    }
97bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley  }
98bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley
99bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley  if (NEED_OPTIONS && which->options) get_optflags();
100bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley  else {
101bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley    toys.optargs = argv+1;
1023b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley    for (toys.optc = 0; toys.optargs[toys.optc]; toys.optc++);
103bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley  }
104bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley  toys.old_umask = umask(0);
105bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley  if (!(which->flags & TOYFLAG_UMASK)) umask(toys.old_umask);
1061bc522424f6bb21842366ccd11953136436b684bRob Landley  toys.signalfd--;
10790b200cac621ee925476297a2b70ddf3101cbb45Rob Landley  toys.toycount = ARRAY_LEN(toy_list);
108bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley}
109bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley
1103b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley// Full init needed by multiplexer or reentrant calls, calls singleinit at end
111cd9dfc3b7b73715840b63180e2e4bfdb6e7ca9a4landleyvoid toy_init(struct toy_list *which, char *argv[])
112cd9dfc3b7b73715840b63180e2e4bfdb6e7ca9a4landley{
113ca311f1a41a579a57076adfeb2cc08b20dbca21aRob Landley  void *oldwhich = toys.which;
114ca311f1a41a579a57076adfeb2cc08b20dbca21aRob Landley
1157aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  // Drop permissions for non-suid commands.
116e0377fb294821a68112d4da09f836ac42e3d5956Rob Landley
1177aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  if (CFG_TOYBOX_SUID) {
118ca311f1a41a579a57076adfeb2cc08b20dbca21aRob Landley    if (!toys.which) toys.which = toy_list;
119ca311f1a41a579a57076adfeb2cc08b20dbca21aRob Landley
1207aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley    uid_t uid = getuid(), euid = geteuid();
121e0377fb294821a68112d4da09f836ac42e3d5956Rob Landley
1227aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley    if (!(which->flags & TOYFLAG_STAYROOT)) {
1235c87c1426b5c99dd1f2a3ac7493996c342efef4eRob Landley      if (uid != euid) {
12462b53ed9e64e40d2534f1239c4b314d84e79f15fPatrick Ohly        if (setuid(uid)) perror_exit("setuid %d->%d", euid, uid); // drop root
125ca311f1a41a579a57076adfeb2cc08b20dbca21aRob Landley        euid = uid;
126ca311f1a41a579a57076adfeb2cc08b20dbca21aRob Landley        toys.wasroot++;
1275c87c1426b5c99dd1f2a3ac7493996c342efef4eRob Landley      }
128bf1e70f3554c2f591e15df7abca03138861e5c6cRob Landley    } else if (CFG_TOYBOX_DEBUG && uid && which != toy_list)
129bf1e70f3554c2f591e15df7abca03138861e5c6cRob Landley      error_msg("Not installed suid root");
130e0377fb294821a68112d4da09f836ac42e3d5956Rob Landley
131e5354ca12a232b3f97726214254a868771cb70d1Rob Landley    if ((which->flags & TOYFLAG_NEEDROOT) && euid) help_exit("Not root");
1327aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  }
133e0377fb294821a68112d4da09f836ac42e3d5956Rob Landley
134caf39c26827f355c4e107f55c5c51f67c484bfd7Rob Landley  // Free old toys contents (to be reentrant), but leave rebound if any
1353b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  // don't blank old optargs if our new argc lives in the old optargs.
1363b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  if (argv<toys.optargs || argv>toys.optargs+toys.optc) free(toys.optargs);
137caf39c26827f355c4e107f55c5c51f67c484bfd7Rob Landley  memset(&toys, 0, offsetof(struct toy_context, rebound));
138ca311f1a41a579a57076adfeb2cc08b20dbca21aRob Landley  if (oldwhich) memset(&this, 0, sizeof(this));
139cd9dfc3b7b73715840b63180e2e4bfdb6e7ca9a4landley
1403b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  // Continue to portion of init needed by standalone commands
141bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley  toy_singleinit(which, argv);
142cd9dfc3b7b73715840b63180e2e4bfdb6e7ca9a4landley}
143cd9dfc3b7b73715840b63180e2e4bfdb6e7ca9a4landley
1448f8c504e585b6850abf628cabdb9ef231bef1a35Rob Landley// Like exec() but runs an internal toybox command instead of another file.
145c6705af4231b8071830721f98021d0e79223da12Rob Landley// Only returns if it can't run command internally, otherwise exit() when done.
1464f344e356d2c36c4b1df46917eaef25f82ca79a9landleyvoid toy_exec(char *argv[])
14713bab2f09e9189c2b1e83ae37a1134108f9479clandley{
1487aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  struct toy_list *which;
149b841cd2f8c1b378c1e8d73f5915662b8e79aac80Rob Landley
1503b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  // Return if we can't find it (which includes no multiplexer case),
1513b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  if (!(which = toy_find(*argv))) return;
152c6705af4231b8071830721f98021d0e79223da12Rob Landley
1533b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  // Return if stack depth getting noticeable (proxy for leaked heap, etc).
154869da8ce3752ce6f5aa63d302eebe60a2b5c8da8Rob Landley
155869da8ce3752ce6f5aa63d302eebe60a2b5c8da8Rob Landley  // Compiler writers have decided subtracting char * is undefined behavior,
156869da8ce3752ce6f5aa63d302eebe60a2b5c8da8Rob Landley  // so convert to integers. (LP64 says sizeof(long)==sizeof(pointer).)
1574e756d7f9fd1b32b545ce8c43120dc733653b52fRob Landley  if (!CFG_TOYBOX_NORECURSE)
1584e756d7f9fd1b32b545ce8c43120dc733653b52fRob Landley    if (toys.stacktop && labs((long)toys.stacktop-(long)&which)>6000) return;
1593b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley
1603b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  // Return if we need to re-exec to acquire root via suid bit.
161ca311f1a41a579a57076adfeb2cc08b20dbca21aRob Landley  if (toys.which && (which->flags&TOYFLAG_ROOTONLY) && toys.wasroot) return;
1627c5ed1cedaa881fff52da019da96f9bf6735dc5dRob Landley
163c6705af4231b8071830721f98021d0e79223da12Rob Landley  // Run command
1647aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  toy_init(which, argv);
1655f80533836c60a167f69b71624fad5c494057ee2Rob Landley  if (toys.which) toys.which->toy_main();
166953722e3826c779f261a4c8a3649e36b1333a86fRob Landley  xexit();
1674f344e356d2c36c4b1df46917eaef25f82ca79a9landley}
16813bab2f09e9189c2b1e83ae37a1134108f9479clandley
1698f8c504e585b6850abf628cabdb9ef231bef1a35Rob Landley// Multiplexer command, first argument is command to run, rest are args to that.
1708f8c504e585b6850abf628cabdb9ef231bef1a35Rob Landley// If first argument starts with - output list of command install paths.
171efda21ca931766eed6cfc49d1b2122c53827d9fcRob Landleyvoid toybox_main(void)
1724f344e356d2c36c4b1df46917eaef25f82ca79a9landley{
1737aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  static char *toy_paths[]={"usr/","bin/","sbin/",0};
1747aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  int i, len = 0;
1757aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley
1763b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  // fast path: try to exec immediately.
1773b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  // (Leave toys.which null to disable suid return logic.)
1783b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  if (toys.argv[1]) toy_exec(toys.argv+1);
1793b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley
1803b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  // For early error reporting
1816c62448f72ed9fc2b6a59ee09735283c07060cdbRob Landley  toys.which = toy_list;
1823b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley
18329e75d51d447c5c0aae9834f5988b79a945c7accRob Landley  if (toys.argv[1] && toys.argv[1][0] != '-') unknown(toys.argv[1]);
1847aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley
185933919cd8094e870b3e7a554605fd49b20ddb1e0Rob Landley  // Output list of command.
186e7acb4749dc655fee22d08f2723ea783f0d75fb6Rob Landley  for (i=1; i<ARRAY_LEN(toy_list); i++) {
1877aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley    int fl = toy_list[i].flags;
1887aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley    if (fl & TOYMASK_LOCATION) {
1897aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley      if (toys.argv[1]) {
1907aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley        int j;
1917aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley        for (j=0; toy_paths[j]; j++)
1927aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley          if (fl & (1<<j)) len += printf("%s", toy_paths[j]);
1937aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley      }
194d3f335d2cf64eb6c556ee5ba6e4a9315766e3c6eRob Landley      len += printf("%s",toy_list[i].name);
195d3f335d2cf64eb6c556ee5ba6e4a9315766e3c6eRob Landley      if (++len > 65) len = 0;
196d3f335d2cf64eb6c556ee5ba6e4a9315766e3c6eRob Landley      xputc(len ? ' ' : '\n');
1977aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley    }
1987aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  }
1997aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley  xputc('\n');
2004f344e356d2c36c4b1df46917eaef25f82ca79a9landley}
2014f344e356d2c36c4b1df46917eaef25f82ca79a9landley
2024f344e356d2c36c4b1df46917eaef25f82ca79a9landleyint main(int argc, char *argv[])
2034f344e356d2c36c4b1df46917eaef25f82ca79a9landley{
2043b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  if (!*argv) return 127;
205e7c09548b9c6188857260064c8ceba03d850c4b7Rob Landley
2063b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  // Snapshot stack location so we can detect recursion depth later.
2073b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  // This is its own block so probe doesn't permanently consume stack.
2083b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  else {
2093b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley    int stack;
2103b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley
2113b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley    toys.stacktop = &stack;
2123b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  }
213cb49c305e3c78179b19d6f174ae73309544292b8Rob Landley  *argv = getbasename(*argv);
2143b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley
2153b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  // If nommu can't fork, special reentry path.
2163b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  // Use !stacktop to signal "vfork happened", both before and after xexec()
2173b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  if (!CFG_TOYBOX_FORK) {
2183b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley    if (0x80 & **argv) {
2193b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley      **argv &= 0x7f;
2203b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley      toys.stacktop = 0;
2213b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley    }
2223b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  }
223bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley
2243b51a07e478d64a84e40b3a7c026b2f8566b194bRob Landley  if (CFG_TOYBOX) {
225bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley    // Call the multiplexer, adjusting this argv[] to be its' argv[1].
226bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley    // (It will adjust it back before calling toy_exec().)
227bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley    toys.argv = argv-1;
228bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley    toybox_main();
229bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley  } else {
230bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley    // a single toybox command built standalone with no multiplexer
231bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley    toy_singleinit(toy_list, argv);
232bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley    toy_list->toy_main();
233bb504f382dc6c596e6b2b9ce04931e7fbdd15bbeRob Landley  }
2347aa651a6a4496d848f86de9b1e6b3a003256a01fRob Landley
235aad492fd87d689c443e87561c23abc2e12b785a9Rob Landley  xexit();
23613bab2f09e9189c2b1e83ae37a1134108f9479clandley}
237