summaryrefslogtreecommitdiff
path: root/src/chroot.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-01-04 20:25:46 +0000
committerJim Meyering <jim@meyering.net>2004-01-04 20:25:46 +0000
commitfd1e65f0a1e25aff9e0d0c152419fffa51163320 (patch)
tree74aa31d43a486b53de22ae07045b8570ade82f23 /src/chroot.c
parent1276aa43f3e3457f44c3195aac8c2917a3da2773 (diff)
downloadcoreutils-fd1e65f0a1e25aff9e0d0c152419fffa51163320.tar.xz
Include "quote.h".
(CHROOT_FOUND_BUT_CANNOT_INVOKE, CHROOT_FAILURE): Define. (main): Exit with status of 127, not 1, for too-few-args, chroot failure, or chdir failure. Give a better diagnostic upon execvp failure.
Diffstat (limited to 'src/chroot.c')
-rw-r--r--src/chroot.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/chroot.c b/src/chroot.c
index 8095f2ec1..9a2c913ee 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, 1999-2003 Free Software Foundation, Inc.
+ Copyright (C) 95, 96, 1997, 1999-2004 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
@@ -22,14 +22,25 @@
#include <sys/types.h>
#include "system.h"
-#include "long-options.h"
#include "error.h"
+#include "long-options.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "chroot"
#define AUTHORS "Roland McGrath"
+/* Exit statuses. */
+enum
+ {
+ /* found the specified command but failed to invoke it. */
+ CHROOT_FOUND_BUT_CANNOT_INVOKE = 126,
+
+ /* `chroot' itself failed, or did not find the specified command. */
+ CHROOT_FAILURE = 127
+ };
+
/* The name this program was run with, for error messages. */
char *program_name;
@@ -76,15 +87,15 @@ main (int argc, char **argv)
if (argc <= 1)
{
error (0, 0, _("too few arguments"));
- usage (EXIT_FAILURE);
+ usage (CHROOT_FAILURE);
}
if (chroot (argv[1]))
- error (EXIT_FAILURE, errno,
+ error (CHROOT_FAILURE, errno,
_("cannot change root directory to %s"), argv[1]);
if (chdir ("/"))
- error (EXIT_FAILURE, errno, _("cannot chdir to root directory"));
+ error (CHROOT_FAILURE, errno, _("cannot chdir to root directory"));
if (argc == 2)
{
@@ -105,8 +116,10 @@ main (int argc, char **argv)
execvp (argv[0], argv);
{
- int exit_status = (errno == ENOENT ? 127 : 126);
- error (0, errno, "%s", argv[0]);
+ int exit_status = (errno == ENOENT
+ ? CHROOT_FAILURE
+ : CHROOT_FOUND_BUT_CANNOT_INVOKE);
+ error (0, errno, _("cannot run command %s"), quote (argv[0]));
exit (exit_status);
}
}