Audit chroot(1)

1) Fix usage()
2) Rename *p to *cmd
3) _exit trick with 126 + (savederrno == ENOENT)
4) return-style-fix
This commit is contained in:
FRIGN 2015-03-02 17:41:58 +01:00
parent 520d87e58e
commit eb137b9e42
2 changed files with 11 additions and 11 deletions

2
README
View File

@ -15,7 +15,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
=* chgrp yes none =* chgrp yes none
=* chmod yes none =* chmod yes none
=* chown yes none =* chown yes none
=* chroot non-posix none =*| chroot non-posix none
=* cksum yes none =* cksum yes none
=* cmp yes none =* cmp yes none
#* cols non-posix none #* cols non-posix none

View File

@ -8,13 +8,13 @@
static void static void
usage(void) usage(void)
{ {
eprintf("usage: chroot dir [cmd [arg ...]]\n"); eprintf("usage: %s dir [cmd [arg ...]]\n", argv0);
} }
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char *shell[] = { "/bin/sh", "-i", NULL }, *aux, *p; char *shell[] = { "/bin/sh", "-i", NULL }, *aux, *cmd;
int savederrno; int savederrno;
ARGBEGIN { ARGBEGIN {
@ -22,7 +22,7 @@ main(int argc, char *argv[])
usage(); usage();
} ARGEND; } ARGEND;
if (argc < 1) if (!argc)
usage(); usage();
if ((aux = getenv("SHELL"))) if ((aux = getenv("SHELL")))
@ -35,16 +35,16 @@ main(int argc, char *argv[])
eprintf("chdir:"); eprintf("chdir:");
if (argc == 1) { if (argc == 1) {
p = *shell; cmd = *shell;
execvp(*shell, shell); execvp(*shell, shell);
} else { } else {
p = argv[1]; cmd = argv[1];
execvp(argv[1], argv + 1); execvp(argv[1], argv + 1);
} }
savederrno = errno; savederrno = errno;
weprintf("execvp %s:", p); weprintf("execvp %s:", cmd);
_exit(savederrno == ENOENT ? 127 : 126); _exit(126 + (savederrno == ENOENT));
/* unreachable */
return 0; return 0; /* not reached */
} }