summaryrefslogtreecommitdiff
path: root/src/chgrp.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1997-08-31 22:07:53 +0000
committerJim Meyering <jim@meyering.net>1997-08-31 22:07:53 +0000
commitf5d34cdce9660471959be5e447a67e5d7b7b2dfe (patch)
treed687f5b2b5a44aef41184ecfdd46bbed2b352226 /src/chgrp.c
parent72bf7437cbe0090c4f2045850ce165b633c43d51 (diff)
downloadcoreutils-f5d34cdce9660471959be5e447a67e5d7b7b2dfe.tar.xz
(change_file_group): Call describe_change with a 3-state argument.
(describe_change): Report whether the operation was successful, a failure, or that the request was a no-op. Before, running `chown --verb bin /' as non-root reported group of / changed to bin chgrp: you are not a member of group `bin': Not owner
Diffstat (limited to 'src/chgrp.c')
-rw-r--r--src/chgrp.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/chgrp.c b/src/chgrp.c
index 3e4209983..74cbe5608 100644
--- a/src/chgrp.c
+++ b/src/chgrp.c
@@ -58,6 +58,13 @@ struct group *getgrnam ();
# define LCHOWN(FILE, OWNER, GROUP) 1
#endif
+enum Change_status
+{
+ CH_SUCCEEDED,
+ CH_FAILED,
+ CH_NO_CHANGE_REQUESTED
+};
+
char *group_member ();
char *savedir ();
char *xmalloc ();
@@ -112,16 +119,28 @@ static struct option const long_options[] =
{0, 0, 0, 0}
};
-/* Tell the user the group name to which ownership of FILE
- has been given; if CHANGED is zero, FILE was that group already. */
+/* Tell the user how/if the group of FILE has been changed.
+ CHANGED describes what (if anything) has happened. */
static void
-describe_change (const char *file, int changed)
+describe_change (const char *file, enum Change_status changed)
{
- if (changed)
- printf (_("group of %s changed to %s\n"), file, groupname);
- else
- printf (_("group of %s retained as %s\n"), file, groupname);
+ const char *fmt;
+ switch (changed)
+ {
+ case CH_SUCCEEDED:
+ fmt = _("group of %s changed to %s\n");
+ break;
+ case CH_FAILED:
+ fmt = _("failed to change group of %s to %s\n");
+ break;
+ case CH_NO_CHANGE_REQUESTED:
+ fmt = _("group of %s retained as %s\n");
+ break;
+ default:
+ abort ();
+ }
+ printf (fmt, file, groupname);
}
/* Set *G according to NAME. */
@@ -179,14 +198,14 @@ change_file_group (const char *file, int group)
{
int fail;
- if (verbose)
- describe_change (file, 1);
-
if (change_symlinks)
fail = LCHOWN (file, (uid_t) -1, group);
else
fail = chown (file, (uid_t) -1, group);
+ if (verbose || (changes_only && !fail))
+ describe_change (file, (fail ? CH_FAILED : CH_SUCCEEDED));
+
if (fail)
{
errors = 1;
@@ -213,7 +232,7 @@ change_file_group (const char *file, int group)
}
else if (verbose && changes_only == 0)
{
- describe_change (file, 0);
+ describe_change (file, CH_NO_CHANGE_REQUESTED);
}
if (recurse && S_ISDIR (file_stats.st_mode))