]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(main): Call chdir ("/") after chroot.
authorJim Meyering <jim@meyering.net>
Sun, 31 Jan 1999 17:50:53 +0000 (17:50 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 31 Jan 1999 17:50:53 +0000 (17:50 +0000)
Suggestion from James Youngman.

src/chroot.c

index 76cab5345d589907d3f9c499bb33be8f53c841cd..59514e92906e156ea8f67d428b69ca4329d5fa6b 100644 (file)
@@ -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);