From d3938d3118d1f30cc613d92eb0e72c77693e6226 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 25 Jul 2000 22:22:29 +0000 Subject: [PATCH] (change_file_group): Save errno from a possibly failed chown, and use that later. Otherwise, errno itself could be clobbered before used. --- src/chgrp.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/chgrp.c b/src/chgrp.c index be9c316..d058580 100644 --- a/src/chgrp.c +++ b/src/chgrp.c @@ -213,6 +213,7 @@ change_file_group (int cmdline_arg, const char *file, gid_t group) { int fail; int symlink_changed = 1; + int saved_errno; if (S_ISLNK (file_stats.st_mode) && change_symlinks) { @@ -231,6 +232,9 @@ change_file_group (int cmdline_arg, const char *file, gid_t group) fail = chown (file, (uid_t) -1, group); } + /* Save errno, since in verbose mode, describe_change might change it. */ + saved_errno = errno; + if (verbosity == V_high || (verbosity == V_changes_only && !fail)) { enum Change_status ch_status = (! symlink_changed ? CH_NOT_APPLIED @@ -246,18 +250,18 @@ change_file_group (int cmdline_arg, const char *file, gid_t group) /* Give a more specific message. Some systems set errno to EPERM for both `inaccessible file' and `user not a member of the specified group' errors. */ - if (errno == EPERM && !group_member (group)) + if (saved_errno == EPERM && !group_member (group)) { - error (0, errno, _("you are not a member of group `%s'"), + error (0, saved_errno, _("you are not a member of group `%s'"), groupname); } - else if (errno == EINVAL && group > MAXUID) + else if (saved_errno == EINVAL && group > MAXUID) { error (0, 0, _("%s: invalid group number"), groupname); } else { - error (0, errno, "%s", file); + error (0, saved_errno, "%s", file); } } } -- 2.7.4