From 5a44bb763cbcb85792ea59b07175a56342b63c59 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Fri, 2 Nov 2012 15:50:48 -0700 Subject: [PATCH] main: fixup parameter parsing for user program 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.cc b/main.cc index fc1b2779..635b8da7 100644 --- 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); -- 2.34.1