diff options
author | Jim Meyering <jim@meyering.net> | 2000-07-25 22:22:29 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2000-07-25 22:22:29 +0000 |
commit | d3938d3118d1f30cc613d92eb0e72c77693e6226 (patch) | |
tree | af1d816e293e30cf22e81af8a2df6d51d7d60dbc /src | |
parent | c0186d3cbb88f5b22c23e3e96e2432d6e8406de9 (diff) | |
download | coreutils-d3938d3118d1f30cc613d92eb0e72c77693e6226.tar.xz |
(change_file_group): Save errno from a possibly failed chown,
and use that later. Otherwise, errno itself could be clobbered before used.
Diffstat (limited to 'src')
-rw-r--r-- | src/chgrp.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/chgrp.c b/src/chgrp.c index be9c31695..d058580df 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); } } } |