Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/mtree Deal with the case when a device gets recreat...



details:   https://anonhg.NetBSD.org/src/rev/a30bb04026f4
branches:  trunk
changeset: 1020204:a30bb04026f4
user:      simonb <simonb%NetBSD.org@localhost>
date:      Sat Apr 03 13:37:18 2021 +0000

description:
Deal with the case when a device gets recreated (eg when mtree is called by
MAKEDEV) and the stat buffer contains information about the original device
before checking/setting the owner/group/mode of the new device file.

diffstat:

 usr.sbin/mtree/compare.c |  31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)

diffs (109 lines):

diff -r 9b12aaf2be90 -r a30bb04026f4 usr.sbin/mtree/compare.c
--- a/usr.sbin/mtree/compare.c  Sat Apr 03 12:57:21 2021 +0000
+++ b/usr.sbin/mtree/compare.c  Sat Apr 03 13:37:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compare.c,v 1.59 2021/03/18 20:02:18 cheusov Exp $     */
+/*     $NetBSD: compare.c,v 1.60 2021/04/03 13:37:18 simonb 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.59 2021/03/18 20:02:18 cheusov Exp $");
+__RCSID("$NetBSD: compare.c,v 1.60 2021/04/03 13:37:18 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -137,6 +137,7 @@
 {
        uint32_t len, val, flags;
        int fd, label;
+       bool was_unlinked;
        const char *cp, *tab;
 #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2)
        char *digestbuf;
@@ -144,6 +145,7 @@
 
        tab = NULL;
        label = 0;
+       was_unlinked = false;
        switch(s->type) {
        case F_BLOCK:
                if (!S_ISBLK(p->fts_statp->st_mode))
@@ -210,19 +212,22 @@
                              s->st_mode | nodetoino(s->type),
                              s->st_rdev) == -1) ||
                            (lchown(p->fts_accpath, p->fts_statp->st_uid,
-                             p->fts_statp->st_gid) == -1) )
+                             p->fts_statp->st_gid) == -1) ) {
                                printf(", not modified: %s%s\n",
                                    strerror(errno),
                                    flavor == F_FREEBSD9 ? "" : ")");
-                        else
+                       } else {
                                printf(", modified%s\n",
                                    flavor == F_FREEBSD9 ? "" : ")");
+                               was_unlinked = true;
+                       }
                } else
                        printf(")\n");
                tab = "\t";
        }
        /* Set the uid/gid first, then set the mode. */
-       if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) {
+       if (s->flags & (F_UID | F_UNAME) &&
+           (was_unlinked || s->st_uid != p->fts_statp->st_uid)) {
                LABEL;
                printf(flavor == F_FREEBSD9 ?
                    "%suser expected %lu found %lu" : "%suser (%lu, %lu",
@@ -233,13 +238,15 @@
                                    strerror(errno),
                                    flavor == F_FREEBSD9 ? "" : ")");
                        else
-                               printf(", modified%s\n",
+                               printf(", modified%s%s\n",
+                                   was_unlinked ? " by unlink" : "",
                                    flavor == F_FREEBSD9 ? "" : ")");
                } else
                        printf(")\n");
                tab = "\t";
        }
-       if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) {
+       if (s->flags & (F_GID | F_GNAME) &&
+           (was_unlinked || s->st_gid != p->fts_statp->st_gid)) {
                LABEL;
                printf(flavor == F_FREEBSD9 ?
                    "%sgid expected %lu found %lu" : "%sgid (%lu, %lu",
@@ -250,7 +257,8 @@
                                    strerror(errno),
                                    flavor == F_FREEBSD9 ? "" : ")");
                        else
-                               printf(", modified%s\n",
+                               printf(", modified%s%s\n",
+                                   was_unlinked ? " by unlink" : "",
                                    flavor == F_FREEBSD9 ? "" : ")");
                }
                else
@@ -258,8 +266,8 @@
                tab = "\t";
        }
        if (s->flags & F_MODE &&
-           s->st_mode != (p->fts_statp->st_mode & MBITS)) {
-               if (lflag) {
+           (was_unlinked || s->st_mode != (p->fts_statp->st_mode & MBITS))) {
+               if (lflag && !was_unlinked) {
                        mode_t tmode, mode;
 
                        tmode = s->st_mode;
@@ -287,7 +295,8 @@
                                    strerror(errno),
                                    flavor == F_FREEBSD9 ? "" : ")");
                        else
-                               printf(", modified%s\n",
+                               printf(", modified%s%s\n",
+                                   was_unlinked ? " by unlink" : "",
                                    flavor == F_FREEBSD9 ? "" : ")");
                }
                else



Home | Main Index | Thread Index | Old Index