main: fixup parameter parsing for user program
authorBrian Norris <banorris@uci.edu>
Fri, 2 Nov 2012 22:50:48 +0000 (15:50 -0700)
committerBrian Norris <banorris@uci.edu>
Fri, 2 Nov 2012 23:14:56 +0000 (16:14 -0700)
The user program expects 'optind' to be reset and for 'argv' and 'argc'
to include the program name as the first argument variable.

Note: our mmap()/mprotect()-based snapshotting does not snapshot this
'optind' global, so user-progs that use optarg() functionality might
fail.

main.cc

diff --git a/main.cc b/main.cc
index fc1b2779daa657ae6460293da49d29a5c95ec21d..635b8da70bc213e3db6524c964e78301b1b28ebf 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -72,8 +72,10 @@ static void parse_options(struct model_params *params, int *argc, char ***argv)
                        break;
                }
        }
-       (*argc) -= optind;
-       (*argv) += optind;
+       (*argv)[optind - 1] = (*argv)[0];
+       (*argc) -= (optind - 1);
+       (*argv) += (optind - 1);
+       optind = 1;
 
        if (error)
                print_usage(params);