summaryrefslogtreecommitdiff
path: root/src/chroot.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2014-05-18 16:48:28 +0100
committerPádraig Brady <P@draigBrady.com>2014-05-21 11:18:26 +0100
commitaa1a72706bb9581fc08c63efc3bc03b908407124 (patch)
tree224403cfba39b8ee5559642bb778bd0d91a77488 /src/chroot.c
parentce0c08b52d893f6cad7ae9b7b59968406c85eeb9 (diff)
downloadcoreutils-aa1a72706bb9581fc08c63efc3bc03b908407124.tar.xz
chroot: exit immediately upon failure
* src/chroot.c (main): Consistently exit with failure status immediately upon hitting a terminal issue, rather than diagnosing multiple issues lest users think previous failing actions are optional.
Diffstat (limited to 'src/chroot.c')
-rw-r--r--src/chroot.c30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/chroot.c b/src/chroot.c
index 6b1606055..0ded25dec 100644
--- a/src/chroot.c
+++ b/src/chroot.c
@@ -313,8 +313,6 @@ main (int argc, char **argv)
argv += optind + 1;
}
- bool fail = false;
-
/* Attempt to set all three: supplementary groups, group ID, user ID.
Diagnose any failures. If any have failed, exit before execvp. */
if (userspec)
@@ -350,7 +348,7 @@ main (int argc, char **argv)
if (parse_additional_groups (groups, &in_gids, &n_gids, !n_gids) != 0)
{
if (! n_gids)
- fail = true;
+ exit (EXIT_CANCELED);
/* else look-up outside the chroot worked, then go with those. */
}
else
@@ -363,10 +361,8 @@ main (int argc, char **argv)
if (ngroups <= 0)
{
if (! n_gids)
- {
- fail = true;
- error (0, errno, _("failed to get supplemental groups"));
- }
+ error (EXIT_CANCELED, errno,
+ _("failed to get supplemental groups"));
/* else look-up outside the chroot worked, then go with those. */
}
else
@@ -378,29 +374,17 @@ main (int argc, char **argv)
#endif
if ((uid_set (uid) || groups) && setgroups (n_gids, gids) != 0)
- {
- error (0, errno, _("failed to %s supplemental groups"),
- gids ? "set" : "clear");
- fail = true;
- }
+ error (EXIT_CANCELED, errno, _("failed to %s supplemental groups"),
+ gids ? "set" : "clear");
free (in_gids);
free (out_gids);
if (gid_set (gid) && setgid (gid))
- {
- error (0, errno, _("failed to set group-ID"));
- fail = true;
- }
+ error (EXIT_CANCELED, errno, _("failed to set group-ID"));
if (uid_set (uid) && setuid (uid))
- {
- error (0, errno, _("failed to set user-ID"));
- fail = true;
- }
-
- if (fail)
- exit (EXIT_CANCELED);
+ error (EXIT_CANCELED, errno, _("failed to set user-ID"));
/* Execute the given command. */
execvp (argv[0], argv);