summaryrefslogtreecommitdiff
path: root/src/chroot.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-01-31 17:50:53 +0000
committerJim Meyering <jim@meyering.net>1999-01-31 17:50:53 +0000
commit2f07328f17a278e8997ac5f61b1426ac18403e8a (patch)
tree5a16c0b886017766148e44e91a52c076e833e3ca /src/chroot.c
parent09619556e678d3c490ec973086f809ffff14e0f3 (diff)
downloadcoreutils-2f07328f17a278e8997ac5f61b1426ac18403e8a.tar.xz
(main): Call chdir ("/") after chroot.
Suggestion from James Youngman.
Diffstat (limited to 'src/chroot.c')
-rw-r--r--src/chroot.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/chroot.c b/src/chroot.c
index 76cab5345..59514e929 100644
--- a/src/chroot.c
+++ b/src/chroot.c
@@ -1,5 +1,5 @@
/* chroot -- run command or shell with special root directory
- Copyright (C) 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 95, 96, 1997, 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -72,6 +72,9 @@ main (int argc, char **argv)
if (chroot (argv[1]))
error (1, errno, _("cannot change root directory to %s"), argv[1]);
+ if (chdir ("/"))
+ error (1, errno, _("cannot chdir to root directory"));
+
if (argc == 2)
{
/* No command. Run an interactive shell. */
@@ -82,8 +85,10 @@ main (int argc, char **argv)
argv[1] = "-i";
}
else
- /* The following arguments give the command. */
- argv += 2;
+ {
+ /* The following arguments give the command. */
+ argv += 2;
+ }
/* Execute the given command. */
execvp (argv[0], argv);