changeset 1698:31475e814232 draft

Only discard optargs in toy_exec() after finding the command to run (otherwise the fallback exevp() segfaults).
author Rob Landley <rob@landley.net>
date Sun, 15 Feb 2015 15:27:43 -0600
parents fe210acdc97d
children dee053b7c775
files main.c
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Sat Feb 14 14:59:30 2015 -0600
+++ b/main.c	Sun Feb 15 15:27:43 2015 -0600
@@ -127,15 +127,15 @@
 {
   struct toy_list *which;
 
-  // don't blank old optargs if our new argc lives in the old optargs.
-  if (argv>=toys.optargs && argv<=toys.optargs+toys.optc) toys.optargs = 0;
-
   // Return if we can't find it, or need to re-exec to acquire root,
   // or if stack depth is getting silly.
   if (!(which = toy_find(argv[0]))) return;
   if (toys.recursion && (which->flags & TOYFLAG_ROOTONLY) && getuid()) return;
   if (toys.recursion++ > 5) return;
 
+  // don't blank old optargs if our new argc lives in the old optargs.
+  if (argv>=toys.optargs && argv<=toys.optargs+toys.optc) toys.optargs = 0;
+
   // Run command
   toy_init(which, argv);
   if (toys.which) toys.which->toy_main();