Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/mtree - Check HAVE_LCHFLAGS for lchflags(2) support...



details:   https://anonhg.NetBSD.org/src/rev/bfdd7732b63f
branches:  trunk
changeset: 537811:bfdd7732b63f
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sun Oct 06 01:36:09 2002 +0000

description:
- Check HAVE_LCHFLAGS for lchflags(2) support, rather than assuming
  that HAVE_STRUCT_STAT_ST_FLAGS implies this.
- Set HAVE_LCHFLAGS for native builds
- Clean up {CLEAR,SET,CHANGE}FLAGS macros, and only provide if
  HAVE_STRUCT_STAT_ST_FLAGS is set.

(Fixes compilation as a tool on MacOS X, noted by Allen Briggs.)

diffstat:

 usr.sbin/mtree/compare.c |  65 +++++++++++++++++++++++++----------------------
 usr.sbin/mtree/extern.h  |   3 +-
 usr.sbin/mtree/verify.c  |  10 +++++--
 3 files changed, 43 insertions(+), 35 deletions(-)

diffs (181 lines):

diff -r 4c5e077374d0 -r bfdd7732b63f usr.sbin/mtree/compare.c
--- a/usr.sbin/mtree/compare.c  Sun Oct 06 01:28:55 2002 +0000
+++ b/usr.sbin/mtree/compare.c  Sun Oct 06 01:36:09 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compare.c,v 1.40 2002/02/08 18:15:12 tv Exp $  */
+/*     $NetBSD: compare.c,v 1.41 2002/10/06 01:36:09 lukem Exp $       */
 
 /*-
  * Copyright (c) 1989, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)compare.c  8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: compare.c,v 1.40 2002/02/08 18:15:12 tv Exp $");
+__RCSID("$NetBSD: compare.c,v 1.41 2002/10/06 01:36:09 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -77,14 +77,26 @@
 } while (0)
 #define        LABEL if (!label++) MARK
 
-#define CHANGEFLAGS(path, oflags)                                      \
-       if (flags != (oflags)) {                                        \
+#if HAVE_STRUCT_STAT_ST_FLAGS
+
+#if HAVE_LCHFLAGS
+#define CHANGE_LCHFLAGS        if (lchflags(p->fts_accpath, flags))
+#else
+#define CHANGE_LCHFLAGS        if (S_ISLNK(p->fts_statp->st_mode)) {           \
+                               label++;                                \
+                               printf(                                 \
+                                   ", not modified: no lchflags call)\n"); \
+                       } else if (chflags(p->fts_accpath, flags))
+#endif
+
+#define CHANGEFLAGS                                                    \
+       if (flags != p->fts_statp->st_flags) {                          \
                if (!label) {                                           \
                        MARK;                                           \
                        printf("%sflags (\"%s\"", tab,                  \
                            flags_to_string(p->fts_statp->st_flags, "none")); \
                }                                                       \
-               if (lchflags(path, flags)) {                            \
+               CHANGE_LCHFLAGS {                                       \
                        label++;                                        \
                        printf(", not modified: %s)\n",                 \
                            strerror(errno));                           \
@@ -94,26 +106,25 @@
        }
 
 /* SETFLAGS:
- * given pflags, additionally set those flags specified in sflags and
- * selected by mask (the other flags are left unchanged). oflags is
- * passed as reference to check if lchflags is necessary.
+ * given pflags, additionally set those flags specified in s->st_flags and
+ * selected by mask (the other flags are left unchanged).
  */
-#define SETFLAGS(path, sflags, pflags, oflags, mask)                   \
+#define SETFLAGS(pflags, mask)                                         \
 do {                                                                   \
-       flags = ((sflags) & (mask)) | (pflags);                         \
-       CHANGEFLAGS(path, oflags);                                      \
+       flags = (s->st_flags & (mask)) | (pflags);                      \
+       CHANGEFLAGS;                                                    \
 } while (0)
 
 /* CLEARFLAGS:
- * given pflags, reset the flags specified in sflags and selected by mask
- * (the other flags are left unchanged). oflags is
- * passed as reference to check if lchflags is necessary.
+ * given pflags, reset the flags specified in s->st_flags and selected by mask
+ * (the other flags are left unchanged).
  */
-#define CLEARFLAGS(path, sflags, pflags, oflags, mask)                 \
+#define CLEARFLAGS(pflags, mask)                                       \
 do {                                                                   \
-       flags = (~((sflags) & (mask)) & CH_MASK) & (pflags);            \
-       CHANGEFLAGS(path, oflags);                                      \
+       flags = (~(s->st_flags & (mask)) & CH_MASK) & (pflags);         \
+       CHANGEFLAGS;                                                    \
 } while (0)
+#endif /* HAVE_STRUCT_STAT_ST_FLAGS */
 
 int
 compare(NODE *s, FTSENT *p)
@@ -166,16 +177,12 @@
 #if HAVE_STRUCT_STAT_ST_FLAGS
        if (iflag && !uflag) {
                if (s->flags & F_FLAGS)
-                   SETFLAGS(p->fts_accpath, s->st_flags,
-                       p->fts_statp->st_flags, p->fts_statp->st_flags,
-                       SP_FLGS);
+                   SETFLAGS(p->fts_statp->st_flags, SP_FLGS);
                return (label);
         }
        if (mflag && !uflag) {
                if (s->flags & F_FLAGS)
-                   CLEARFLAGS(p->fts_accpath, s->st_flags,
-                       p->fts_statp->st_flags, p->fts_statp->st_flags,
-                       SP_FLGS);
+                   CLEARFLAGS(p->fts_statp->st_flags, SP_FLGS);
                return (label);
         }
 #endif
@@ -347,20 +354,16 @@
                }
                if (uflag) {
                        if (iflag)
-                               SETFLAGS(p->fts_accpath, s->st_flags,
-                                   0, p->fts_statp->st_flags, CH_MASK);
+                               SETFLAGS(0, CH_MASK);
                        else if (mflag)
-                               CLEARFLAGS(p->fts_accpath, s->st_flags,
-                                   0, p->fts_statp->st_flags, SP_FLGS);
+                               CLEARFLAGS(0, SP_FLGS);
                        else
-                               SETFLAGS(p->fts_accpath, s->st_flags,
-                                   0, p->fts_statp->st_flags,
-                                   (~SP_FLGS & CH_MASK));
+                               SETFLAGS(0, (~SP_FLGS & CH_MASK));
                } else
                        printf(")\n");
                tab = "\t";
        }
-#endif
+#endif /* HAVE_STRUCT_STAT_ST_FLAGS */
 
        /*
         * from this point, no more permission checking or whacking
diff -r 4c5e077374d0 -r bfdd7732b63f usr.sbin/mtree/extern.h
--- a/usr.sbin/mtree/extern.h   Sun Oct 06 01:28:55 2002 +0000
+++ b/usr.sbin/mtree/extern.h   Sun Oct 06 01:36:09 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.23 2002/02/08 18:15:12 tv Exp $   */
+/*     $NetBSD: extern.h,v 1.24 2002/10/06 01:36:09 lukem Exp $        */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -40,6 +40,7 @@
 #if HAVE_CONFIG_H
 #include "config.h" 
 #else 
+#define HAVE_LCHFLAGS 1
 #define HAVE_LCHMOD 1
 #define HAVE_STRUCT_STAT_ST_FLAGS 1
 #endif
diff -r 4c5e077374d0 -r bfdd7732b63f usr.sbin/mtree/verify.c
--- a/usr.sbin/mtree/verify.c   Sun Oct 06 01:28:55 2002 +0000
+++ b/usr.sbin/mtree/verify.c   Sun Oct 06 01:36:09 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: verify.c,v 1.30 2002/02/08 18:15:12 tv Exp $   */
+/*     $NetBSD: verify.c,v 1.31 2002/10/06 01:36:09 lukem Exp $        */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)verify.c   8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: verify.c,v 1.30 2002/02/08 18:15:12 tv Exp $");
+__RCSID("$NetBSD: verify.c,v 1.31 2002/10/06 01:36:09 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -284,10 +284,14 @@
                                flags = p->st_flags;
                        else
                                flags = p->st_flags & ~SP_FLGS;
+#if HAVE_LCHFLAGS
                        if (lchflags(path, flags))
+#else
+                       if ((p->type != F_LINK) && chflags(path, flags))
+#endif
                                printf("%s: file flags not set: %s\n",
                                    path, strerror(errno));
                }
-#endif
+#endif /* HAVE_STRUCT_STAT_ST_FLAGS */
        }
 }



Home | Main Index | Thread Index | Old Index