summaryrefslogtreecommitdiffstats
path: root/usr.sbin/mtree
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2004-01-11 19:38:48 +0000
committerphk <phk@FreeBSD.org>2004-01-11 19:38:48 +0000
commit32088626608317036dceb467a6f9b90fb02fd46c (patch)
tree73eccb588e3cb50b2fe4d6cab897730b75de9c95 /usr.sbin/mtree
parentad83565985bcd5de2b65d3cccbdeb9b10289e751 (diff)
downloadFreeBSD-src-32088626608317036dceb467a6f9b90fb02fd46c.zip
FreeBSD-src-32088626608317036dceb467a6f9b90fb02fd46c.tar.gz
Get rid of "lineno: 0" in error messages from create mode.
Add -w(arning) flag which makes failure to look up uid/gid a nonfatal warning instead of an error.
Diffstat (limited to 'usr.sbin/mtree')
-rw-r--r--usr.sbin/mtree/create.c56
-rw-r--r--usr.sbin/mtree/extern.h2
-rw-r--r--usr.sbin/mtree/mtree.82
-rw-r--r--usr.sbin/mtree/mtree.c7
4 files changed, 42 insertions, 25 deletions
diff --git a/usr.sbin/mtree/create.c b/usr.sbin/mtree/create.c
index 04e9a2b..fa902e4 100644
--- a/usr.sbin/mtree/create.c
+++ b/usr.sbin/mtree/create.c
@@ -98,7 +98,7 @@ cwalk(void)
argv[0] = dot;
argv[1] = NULL;
if ((t = fts_open(argv, ftsoptions, dsort)) == NULL)
- err(1, "line %d: fts_open", lineno);
+ err(1, "fts_open()");
while ((p = fts_read(t))) {
if (iflag)
indent = p->fts_level * 4;
@@ -171,22 +171,32 @@ statf(int indent, FTSENT *p)
output(indent, &offset, "type=%s", inotype(p->fts_statp->st_mode));
if (p->fts_statp->st_uid != uid) {
if (keys & F_UNAME) {
- if ((pw = getpwuid(p->fts_statp->st_uid)) == NULL)
+ pw = getpwuid(p->fts_statp->st_uid);
+ if (pw != NULL)
+ output(indent, &offset, "uname=%s", pw->pw_name);
+ else if (wflag)
+ warnx("Could not get uname for uid=%u",
+ p->fts_statp->st_uid);
+ else
errx(1,
- "line %d: could not get uname for uid=%u",
- lineno, p->fts_statp->st_uid);
- output(indent, &offset, "uname=%s", pw->pw_name);
+ "Could not get uname for uid=%u",
+ p->fts_statp->st_uid);
}
if (keys & F_UID)
output(indent, &offset, "uid=%u", p->fts_statp->st_uid);
}
if (p->fts_statp->st_gid != gid) {
if (keys & F_GNAME) {
- if ((gr = getgrgid(p->fts_statp->st_gid)) == NULL)
+ gr = getgrgid(p->fts_statp->st_gid);
+ if (gr != NULL)
+ output(indent, &offset, "gname=%s", gr->gr_name);
+ else if (wflag)
+ warnx("Could not get gname for gid=%u",
+ p->fts_statp->st_gid);
+ else
errx(1,
- "line %d: could not get gname for gid=%u",
- lineno, p->fts_statp->st_gid);
- output(indent, &offset, "gname=%s", gr->gr_name);
+ "Could not get gname for gid=%u",
+ p->fts_statp->st_gid);
}
if (keys & F_GID)
output(indent, &offset, "gid=%u", p->fts_statp->st_gid);
@@ -205,7 +215,7 @@ statf(int indent, FTSENT *p)
if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) {
if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 ||
crc(fd, &val, &len))
- err(1, "line %d: %s", lineno, p->fts_accpath);
+ err(1, "%s", p->fts_accpath);
(void)close(fd);
output(indent, &offset, "cksum=%lu", (unsigned long)val);
}
@@ -215,7 +225,7 @@ statf(int indent, FTSENT *p)
digest = MD5File(p->fts_accpath, buf);
if (!digest)
- err(1, "line %d: %s", lineno, p->fts_accpath);
+ err(1, "%s", p->fts_accpath);
output(indent, &offset, "md5digest=%s", digest);
}
#endif /* MD5 */
@@ -225,7 +235,7 @@ statf(int indent, FTSENT *p)
digest = SHA1_File(p->fts_accpath, buf);
if (!digest)
- err(1, "line %d: %s", lineno, p->fts_accpath);
+ err(1, "%s", p->fts_accpath);
output(indent, &offset, "sha1digest=%s", digest);
}
#endif /* SHA1 */
@@ -235,7 +245,7 @@ statf(int indent, FTSENT *p)
digest = RIPEMD160_File(p->fts_accpath, buf);
if (!digest)
- err(1, "line %d: %s", lineno, p->fts_accpath);
+ err(1, "%s", p->fts_accpath);
output(indent, &offset, "ripemd160digest=%s", digest);
}
#endif /* RMD160 */
@@ -277,7 +287,7 @@ statd(FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode, u_long *p
if ((p = fts_children(t, 0)) == NULL) {
if (errno)
- err(1, "line %d: %s", lineno, RP(parent));
+ err(1, "%s", RP(parent));
return (1);
}
@@ -336,22 +346,24 @@ statd(FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode, u_long *p
else
(void)printf("/set type=file");
if (keys & F_UNAME) {
- if ((pw = getpwuid(saveuid)) != NULL)
+ pw = getpwuid(saveuid);
+ if (pw != NULL)
(void)printf(" uname=%s", pw->pw_name);
+ else if (wflag)
+ warnx( "Could not get uname for uid=%u", saveuid);
else
- errx(1,
- "line %d: could not get uname for uid=%u",
- lineno, saveuid);
+ errx(1, "Could not get uname for uid=%u", saveuid);
}
if (keys & F_UID)
(void)printf(" uid=%lu", (u_long)saveuid);
if (keys & F_GNAME) {
- if ((gr = getgrgid(savegid)) != NULL)
+ gr = getgrgid(savegid);
+ if (gr != NULL)
(void)printf(" gname=%s", gr->gr_name);
+ else if (wflag)
+ warnx("Could not get gname for gid=%u", savegid);
else
- errx(1,
- "line %d: could not get gname for gid=%u",
- lineno, savegid);
+ errx(1, "Could not get gname for gid=%u", savegid);
}
if (keys & F_GID)
(void)printf(" gid=%lu", (u_long)savegid);
diff --git a/usr.sbin/mtree/extern.h b/usr.sbin/mtree/extern.h
index 5f92344..4b6fb3c 100644
--- a/usr.sbin/mtree/extern.h
+++ b/usr.sbin/mtree/extern.h
@@ -53,7 +53,7 @@ const char * ftype(u_int type);
extern int ftsoptions;
extern u_int keys;
extern int lineno;
-extern int dflag, eflag, iflag, nflag, qflag, rflag, sflag, uflag;
+extern int dflag, eflag, iflag, nflag, qflag, rflag, sflag, uflag, wflag;
#ifdef MAXPATHLEN
extern char fullpath[MAXPATHLEN];
#endif
diff --git a/usr.sbin/mtree/mtree.8 b/usr.sbin/mtree/mtree.8
index b2cf37d..ee4e38e 100644
--- a/usr.sbin/mtree/mtree.8
+++ b/usr.sbin/mtree/mtree.8
@@ -119,6 +119,8 @@ Same as
.Fl U
except a status of 2 is returned if the file hierarchy did not match
the specification.
+.It Fl w
+Make some errorconditions non-fatal warnings.
.It Fl x
Don't descend below mount points in the file hierarchy.
.It Fl f Ar file
diff --git a/usr.sbin/mtree/mtree.c b/usr.sbin/mtree/mtree.c
index 2fe395e..a815a0b 100644
--- a/usr.sbin/mtree/mtree.c
+++ b/usr.sbin/mtree/mtree.c
@@ -52,7 +52,7 @@ __FBSDID("$FreeBSD$");
#include "extern.h"
int ftsoptions = FTS_PHYSICAL;
-int cflag, dflag, eflag, iflag, nflag, qflag, rflag, sflag, uflag, Uflag;
+int cflag, dflag, eflag, iflag, nflag, qflag, rflag, sflag, uflag, Uflag, wflag;
u_int keys;
char fullpath[MAXPATHLEN];
@@ -72,7 +72,7 @@ main(int argc, char *argv[])
spec1 = stdin;
spec2 = NULL;
- while ((ch = getopt(argc, argv, "cdef:iK:k:LnPp:qrs:UuxX:")) != -1)
+ while ((ch = getopt(argc, argv, "cdef:iK:k:LnPp:qrs:UuwxX:")) != -1)
switch((char)ch) {
case 'c':
cflag = 1;
@@ -142,6 +142,9 @@ main(int argc, char *argv[])
case 'u':
uflag = 1;
break;
+ case 'w':
+ wflag = 1;
+ break;
case 'x':
ftsoptions |= FTS_XDEV;
break;
OpenPOWER on IntegriCloud