[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
chroot and rejecting unknown options
From: |
Paul Eggert |
Subject: |
chroot and rejecting unknown options |
Date: |
Sat, 18 Sep 2004 18:03:31 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
"chroot -u root /" attempts to chroot to a directory called "root".
It should report an error and exit instead. (-u is a freebsd option
that isn't supported by GNU chroot, yet.)
I installed this:
2004-09-18 Paul Eggert <address@hidden>
* src/chroot.c (main): Reject unknown options instead of
interpreting them as a directory to chroot to.
Index: chroot.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/chroot.c,v
retrieving revision 1.43
retrieving revision 1.45
diff -p -u -r1.43 -r1.45
--- chroot.c 21 Jun 2004 15:03:35 -0000 1.43
+++ chroot.c 19 Sep 2004 01:02:30 -0000 1.45
@@ -76,27 +76,22 @@ main (int argc, char **argv)
parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
usage, AUTHORS, (char const *) NULL);
- /* The above handles --help and --version.
- Since there is no other invocation of getopt, handle `--' here. */
- if (1 < argc && STREQ (argv[1], "--"))
- {
- --argc;
- ++argv;
- }
+ if (getopt_long (argc, argv, "+", NULL, NULL) != -1)
+ usage (EXIT_FAILURE);
- if (argc <= 1)
+ if (argc <= optind)
{
error (0, 0, _("missing operand"));
usage (EXIT_FAIL);
}
- if (chroot (argv[1]))
+ if (chroot (argv[optind]) != 0)
error (EXIT_FAIL, errno, _("cannot change root directory to %s"), argv[1]);
if (chdir ("/"))
error (EXIT_FAIL, errno, _("cannot chdir to root directory"));
- if (argc == 2)
+ if (argc == optind + 1)
{
/* No command. Run an interactive shell. */
char *shell = getenv ("SHELL");
@@ -104,11 +99,12 @@ main (int argc, char **argv)
shell = "/bin/sh";
argv[0] = shell;
argv[1] = "-i";
+ argv[2] = NULL;
}
else
{
/* The following arguments give the command. */
- argv += 2;
+ argv += optind + 1;
}
/* Execute the given command. */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- chroot and rejecting unknown options,
Paul Eggert <=