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.
This commit is contained in:
parent
af1c0e7ba9
commit
353a61bfae
|
@ -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 @@ compare(NODE *s, FTSENT *p)
|
|||
{
|
||||
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 @@ compare(NODE *s, FTSENT *p)
|
|||
|
||||
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 @@ typeerr: LABEL;
|
|||
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 @@ typeerr: LABEL;
|
|||
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 @@ typeerr: LABEL;
|
|||
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 @@ typeerr: LABEL;
|
|||
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 @@ typeerr: LABEL;
|
|||
strerror(errno),
|
||||
flavor == F_FREEBSD9 ? "" : ")");
|
||||
else
|
||||
printf(", modified%s\n",
|
||||
printf(", modified%s%s\n",
|
||||
was_unlinked ? " by unlink" : "",
|
||||
flavor == F_FREEBSD9 ? "" : ")");
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue