bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: chgrp --preserve-root


From: Jim Meyering
Subject: Re: chgrp --preserve-root
Date: Sat, 27 May 2006 16:58:50 +0200

Michael Stone <address@hidden> wrote:
> Hmm. There's a help entry for --preserve-root in chgrp, but I can't find
> any code actually referencing that option. Was it removed?

Wow.  The code to add those options to chgrp was never written!
I did it for the others, but somehow neglected chgrp -- or maybe
I did, but didn't commit it?  The changes are almost identical
to those for chown.c.

Thanks for reporting that.

I've just remedied that on the trunk.
Soon to go onto the branch, too.

    * src/chgrp.c: Support new options: --preserve-root and --no-preserve-root.
    Somehow this program was skipped when those options were added to chown,
    chmod, and rm.  Reported by address@hidden in
    <http://bugs.debian.org/365656>.

Normally, I list the user name and email in the THANKS file.
If you (the person behind the address@hidden address)
would like to be listed there, let me know.

Index: chgrp.c
===================================================================
RCS file: /fetish/cu/src/chgrp.c,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -p -u -r1.121 -r1.122
--- chgrp.c     6 Feb 2006 08:00:23 -0000       1.121
+++ chgrp.c     27 May 2006 14:44:41 -0000      1.122
@@ -30,6 +30,7 @@
 #include "group-member.h"
 #include "lchown.h"
 #include "quote.h"
+#include "root-dev-ino.h"
 #include "xstrtol.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
@@ -53,6 +54,8 @@ static char *reference_file;
 enum
 {
   DEREFERENCE_OPTION = CHAR_MAX + 1,
+  NO_PRESERVE_ROOT,
+  PRESERVE_ROOT,
   REFERENCE_FILE_OPTION
 };
 
@@ -62,6 +65,8 @@ static struct option const long_options[
   {"changes", no_argument, NULL, 'c'},
   {"dereference", no_argument, NULL, DEREFERENCE_OPTION},
   {"no-dereference", no_argument, NULL, 'h'},
+  {"no-preserve-root", no_argument, NULL, NO_PRESERVE_ROOT},
+  {"preserve-root", no_argument, NULL, PRESERVE_ROOT},
   {"quiet", no_argument, NULL, 'f'},
   {"silent", no_argument, NULL, 'f'},
   {"reference", required_argument, NULL, REFERENCE_FILE_OPTION},
@@ -164,6 +169,7 @@ Examples:\n\
 int
 main (int argc, char **argv)
 {
+  bool preserve_root = false;
   gid_t gid;
 
   /* Bit flags that control how fts works.  */
@@ -213,6 +219,14 @@ main (int argc, char **argv)
          dereference = 1;
          break;
 
+       case NO_PRESERVE_ROOT:
+         preserve_root = false;
+         break;
+
+       case PRESERVE_ROOT:
+         preserve_root = true;
+         break;
+
        case REFERENCE_FILE_OPTION:
          reference_file = optarg;
          break;
@@ -288,6 +302,15 @@ main (int argc, char **argv)
       gid = parse_group (group_name);
     }
 
+  if (chopt.recurse & preserve_root)
+    {
+      static struct dev_ino dev_ino_buf;
+      chopt.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
+      if (chopt.root_dev_ino == NULL)
+       error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
+              quote ("/"));
+    }
+
   ok = chown_files (argv + optind, bit_flags,
                    (uid_t) -1, gid,
                    (uid_t) -1, (gid_t) -1, &chopt);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]