# HG changeset patch # User Rob Landley # Date 1387510692 21600 # Node ID ac4a0cde89c2b3932def6516558f75abf206aae7 # Parent 2213cedd15b4359e6d55395bea8ce1f3d0171a3c Don't permute toys.optargs, cleanup code (xexec()) can free it. diff -r 2213cedd15b4 -r ac4a0cde89c2 main.c --- a/main.c Thu Dec 19 15:14:33 2013 -0600 +++ b/main.c Thu Dec 19 21:38:12 2013 -0600 @@ -92,7 +92,7 @@ uid_t uid = getuid(), euid = geteuid(); if (!(which->flags & TOYFLAG_STAYROOT)) { - if (uid != euid) xsetuid(euid=uid); + if (uid != euid) xsetuid(euid=uid); // drop root } else if (CFG_TOYBOX_DEBUG && uid && which != toy_list) error_msg("Not installed suid root"); diff -r 2213cedd15b4 -r ac4a0cde89c2 toys/lsb/umount.c --- a/toys/lsb/umount.c Thu Dec 19 15:14:33 2013 -0600 +++ b/toys/lsb/umount.c Thu Dec 19 21:38:12 2013 -0600 @@ -91,7 +91,7 @@ return; } if (toys.optflags & FLAG_r) { - if (!mount("", *toys.optargs, "", MS_REMOUNT|MS_RDONLY, "")) { + if (!mount("", dir, "", MS_REMOUNT|MS_RDONLY, "")) { if (toys.optflags & FLAG_v) printf("%s remounted ro", dir); return; } @@ -102,6 +102,7 @@ void umount_main(void) { int flags=0; + char **optargs; if (!toys.optc && !(toys.optflags & FLAG_a)) error_exit("Need 1 arg or -a"); @@ -109,7 +110,7 @@ if (toys.optflags & FLAG_f) flags |= MNT_FORCE; if (toys.optflags & FLAG_l) flags |= MNT_DETACH; - for (; *toys.optargs; toys.optargs++) do_umount(*toys.optargs, flags); + for (optargs = toys.optargs; *optargs; optargs++) do_umount(*optargs, flags); if (toys.optflags & FLAG_a) { struct mtab_list *mlsave, *ml; diff -r 2213cedd15b4 -r ac4a0cde89c2 toys/other/hello.c --- a/toys/other/hello.c Thu Dec 19 15:14:33 2013 -0600 +++ b/toys/other/hello.c Thu Dec 19 21:38:12 2013 -0600 @@ -41,6 +41,8 @@ void hello_main(void) { + char **optargs; + printf("Hello world\n"); if (toys.optflags) printf("flags=%x\n", toys.optflags); @@ -52,7 +54,8 @@ TT.d_list = TT.d_list->next; } if (TT.e_count) printf("e was seen %ld times\n", TT.e_count); - while (*toys.optargs) printf("optarg=%s\n", *(toys.optargs++)); + for (optargs = toys.optargs; *optargs; optargs++) + printf("optarg=%s\n", *optargs); if (toys.optflags & FLAG_walrus) printf("Saw --walrus\n"); if (TT.blubber_string) printf("--blubber=%s\n", TT.blubber_string); } diff -r 2213cedd15b4 -r ac4a0cde89c2 toys/other/pmap.c --- a/toys/other/pmap.c Thu Dec 19 15:14:33 2013 -0600 +++ b/toys/other/pmap.c Thu Dec 19 21:38:12 2013 -0600 @@ -24,8 +24,10 @@ void pmap_main(void) { - while (*toys.optargs) { - pid_t pid = atolx(*toys.optargs++); + char **optargs; + + for (optargs = toys.optargs; *optargs; optargs++) { + pid_t pid = atolx(*optargs); FILE *fp; char *line, *oldline = 0, *name = 0, *k = (toys.optflags & FLAG_x) ? "" : "K"; diff -r 2213cedd15b4 -r ac4a0cde89c2 toys/other/pwdx.c --- a/toys/other/pwdx.c Thu Dec 19 15:14:33 2013 -0600 +++ b/toys/other/pwdx.c Thu Dec 19 21:38:12 2013 -0600 @@ -17,11 +17,13 @@ void pwdx_main(void) { - for (; *toys.optargs; toys.optargs++) { + char **optargs; + + for (optargs = toys.optargs; *optargs; optargs++) { char *path; int num_bytes; - path = xmsprintf("/proc/%s/cwd", *toys.optargs); + path = xmsprintf("/proc/%s/cwd", *optargs); num_bytes = readlink(path, toybuf, sizeof(toybuf)-1); free(path); @@ -32,6 +34,6 @@ path = toybuf; toybuf[num_bytes] = 0; } - xprintf("%s: %s\n", *toys.optargs, path); + xprintf("%s: %s\n", *optargs, path); } }