sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 79a913f4e6c4bb79bb3843a1417cf95db03e708c
parent a79472bb1aea9e83d04b372f1f3a0b14ae12c596
Author: sin <sin@2f30.org>
Date:   Thu, 13 Feb 2014 12:57:16 +0000

We can't use eprintf etc. without using the arg.h macros.

Diffstat:
Mchroot.c | 23++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/chroot.c b/chroot.c @@ -8,27 +8,32 @@ static void usage(void); int main(int argc, char **argv) { - char *shell[] = {"/bin/sh", "-i", NULL}, *aux; + char *shell[] = { "/bin/sh", "-i", NULL }, *aux; - if((aux = getenv("SHELL"))) - shell[0] = aux; + ARGBEGIN { + default: + usage(); + } ARGEND; - if(argc < 2) + if(argc < 1) usage(); - if(chroot(argv[1]) == -1) - eprintf("chroot: '%s':", argv[1]); + if((aux = getenv("SHELL"))) + shell[0] = aux; + + if(chroot(argv[0]) == -1) + eprintf("chroot: '%s':", argv[0]); if(chdir("/") == -1) eprintf("chroot:"); - if(argc == 2) { + if(argc == 1) { execvp(*shell, shell); } else { - execvp(argv[2], argv+2); + execvp(argv[1], argv+1); } - eprintf("chroot: '%s':", argv[2]); + eprintf("chroot: '%s':", argv[1]); return EXIT_FAILURE; }