# HG changeset patch # User Rob Landley # Date 1423347464 21600 # Node ID cbb1aca81ecac77a8e8f0818f8df0dcdb33c7273 # Parent 435f91d71898eef11c80e4c230983592bb0d468a Make toy_exec() check if argc is in optargs and deal with it there so we don't need a separate xexec_optargs(). diff -r 435f91d71898 -r cbb1aca81eca main.c --- a/main.c Sat Feb 07 15:32:22 2015 -0600 +++ b/main.c Sat Feb 07 16:17:44 2015 -0600 @@ -127,6 +127,9 @@ { 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; diff -r 435f91d71898 -r cbb1aca81eca toys/other/chroot.c --- a/toys/other/chroot.c Sat Feb 07 15:32:22 2015 -0600 +++ b/toys/other/chroot.c Sat Feb 07 16:17:44 2015 -0600 @@ -20,6 +20,6 @@ char *binsh[] = {"/bin/sh", "-i", 0}; if (chdir(*toys.optargs) || chroot(".")) perror_exit("%s", *toys.optargs); - if (toys.optargs[1]) xexec_optargs(1); + if (toys.optargs[1]) xexec(toys.optargs+1); else xexec(binsh); } diff -r 435f91d71898 -r cbb1aca81eca toys/other/netcat.c --- a/toys/other/netcat.c Sat Feb 07 15:32:22 2015 -0600 +++ b/toys/other/netcat.c Sat Feb 07 16:17:44 2015 -0600 @@ -185,7 +185,7 @@ set_alarm(0); if (CFG_NETCAT_LISTEN && (toys.optflags&(FLAG_L|FLAG_l) && toys.optc)) - xexec_optargs(0); + xexec(toys.optargs); // Poll loop copying stdin->socket and socket->stdout. for (;;) { diff -r 435f91d71898 -r cbb1aca81eca toys/other/nsenter.c --- a/toys/other/nsenter.c Sat Feb 07 15:32:22 2015 -0600 +++ b/toys/other/nsenter.c Sat Feb 07 16:17:44 2015 -0600 @@ -112,5 +112,5 @@ } } - xexec_optargs(0); + xexec(toys.optargs); } diff -r 435f91d71898 -r cbb1aca81eca toys/other/setsid.c --- a/toys/other/setsid.c Sat Feb 07 15:32:22 2015 -0600 +++ b/toys/other/setsid.c Sat Feb 07 16:17:44 2015 -0600 @@ -24,5 +24,5 @@ setpgid(0,0); tcsetpgrp(0, getpid()); } - xexec_optargs(0); + xexec(toys.optargs); } diff -r 435f91d71898 -r cbb1aca81eca toys/other/taskset.c --- a/toys/other/taskset.c Sat Feb 07 15:32:22 2015 -0600 +++ b/toys/other/taskset.c Sat Feb 07 16:17:44 2015 -0600 @@ -90,7 +90,7 @@ if (!(toys.optflags & FLAG_p)) { if (toys.optc < 2) error_exit("Needs 2 args"); do_taskset(getpid(), 1); - xexec_optargs(1); + xexec(toys.optargs+1); } else { char *c; pid_t pid = strtol(toys.optargs[toys.optc-1], &c, 10); diff -r 435f91d71898 -r cbb1aca81eca toys/other/timeout.c --- a/toys/other/timeout.c Sat Feb 07 15:32:22 2015 -0600 +++ b/toys/other/timeout.c Sat Feb 07 16:17:44 2015 -0600 @@ -60,7 +60,7 @@ if (TT.s_signal && -1 == (TT.nextsig = sig_to_num(TT.s_signal))) error_exit("bad -s: '%s'", TT.s_signal); - if (!(TT.pid = xfork())) xexec_optargs(1); + if (!(TT.pid = xfork())) xexec(toys.optargs+1); else { int status; diff -r 435f91d71898 -r cbb1aca81eca toys/pending/bootchartd.c --- a/toys/pending/bootchartd.c Sat Feb 07 15:32:22 2015 -0600 +++ b/toys/pending/bootchartd.c Sat Feb 07 16:17:44 2015 -0600 @@ -309,7 +309,7 @@ if (bchartd_opt == 1 && toys.optargs[1]) { pid_t prog_pid; - if (!(prog_pid = xfork())) xexec_optargs(1); + if (!(prog_pid = xfork())) xexec(toys.optargs+1); waitpid(prog_pid, NULL, 0); kill(lgr_pid, SIGUSR1); } diff -r 435f91d71898 -r cbb1aca81eca toys/pending/tcpsvd.c --- a/toys/pending/tcpsvd.c Sat Feb 07 15:32:22 2015 -0600 +++ b/toys/pending/tcpsvd.c Sat Feb 07 16:17:44 2015 -0600 @@ -392,7 +392,7 @@ close(1); dup2(newfd, 0); dup2(newfd, 1); - xexec_optargs(2); //skip IP PORT + xexec(toys.optargs+2); //skip IP PORT } else { insert(&pids, pid, addr); xclose(newfd); //close and reopen for next client. diff -r 435f91d71898 -r cbb1aca81eca toys/posix/nice.c --- a/toys/posix/nice.c Sat Feb 07 15:32:22 2015 -0600 +++ b/toys/posix/nice.c Sat Feb 07 16:17:44 2015 -0600 @@ -34,5 +34,5 @@ errno = 0; if (nice(TT.priority)==-1 && errno) perror_exit("Can't set priority"); - xexec_optargs(0); + xexec(toys.optargs); } diff -r 435f91d71898 -r cbb1aca81eca toys/posix/nohup.c --- a/toys/posix/nohup.c Sat Feb 07 15:32:22 2015 -0600 +++ b/toys/posix/nohup.c Sat Feb 07 16:17:44 2015 -0600 @@ -38,5 +38,5 @@ close(0); open("/dev/null", O_RDONLY); } - xexec_optargs(0); + xexec(toys.optargs); } diff -r 435f91d71898 -r cbb1aca81eca toys/posix/time.c --- a/toys/posix/time.c Sat Feb 07 15:32:22 2015 -0600 +++ b/toys/posix/time.c Sat Feb 07 16:17:44 2015 -0600 @@ -27,7 +27,7 @@ struct timeval tv, tv2; gettimeofday(&tv, NULL); - if (!(pid = xfork())) xexec_optargs(0); + if (!(pid = xfork())) xexec(toys.optargs); else { int stat; struct rusage ru;