summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-07-25 22:23:05 +0000
committerJim Meyering <jim@meyering.net>2000-07-25 22:23:05 +0000
commitd86f9d40a52e37e060427dfbcf35b85185ecc066 (patch)
tree7495d683eb4fcd181a041cf74991e7eca3a6e7fb
parentebd74667bc327d4bcbbe7385bd3668919d93f0cb (diff)
downloadcoreutils-d86f9d40a52e37e060427dfbcf35b85185ecc066.tar.xz
(change_file_owner): Save errno from a possibly failed chown,
and use that later. Otherwise, errno itself could be clobbered before used.
-rw-r--r--src/chown.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/chown.c b/src/chown.c
index 5998fdf4c..0b07bc47f 100644
--- a/src/chown.c
+++ b/src/chown.c
@@ -199,6 +199,7 @@ change_file_owner (int cmdline_arg, const char *file, uid_t user, gid_t group,
{
int fail;
int symlink_changed = 1;
+ int saved_errno;
if (S_ISLNK (file_stats.st_mode) && change_symlinks)
{
@@ -216,6 +217,7 @@ change_file_owner (int cmdline_arg, const char *file, uid_t user, gid_t group,
{
fail = chown (file, newuser, newgroup);
}
+ saved_errno = errno;
if (verbosity == V_high || (verbosity == V_changes_only && !fail))
{
@@ -229,7 +231,7 @@ change_file_owner (int cmdline_arg, const char *file, uid_t user, gid_t group,
if (fail)
{
if (force_silent == 0)
- error (0, errno, "%s", file);
+ error (0, saved_errno, "%s", file);
errors = 1;
}
}