From dad76793a27297e14fd22e906c612045f045a17d Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Wed, 6 Nov 2013 19:33:31 +0000 Subject: [PATCH] - since the name is printed alread in the message as : don't repeat the name in the message - if we could not stat, don't try to provide unreadable info - if we could not stat, it is not an error, keep going. --- src/fsmagic.c | 12 +++++------- src/magic.c | 10 ++++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/fsmagic.c b/src/fsmagic.c index ae3fc33c..b540b9bf 100644 --- a/src/fsmagic.c +++ b/src/fsmagic.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: fsmagic.c,v 1.68 2013/05/28 21:24:31 christos Exp $") +FILE_RCSID("@(#)$File: fsmagic.c,v 1.69 2013/11/06 19:33:31 christos Exp $") #endif /* lint */ #include "magic.h" @@ -125,14 +125,12 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) if (ret) { if (ms->flags & MAGIC_ERROR) { - file_error(ms, errno, "cannot stat `%s'", fn); + file_error(ms, errno, "cannot stat"); return -1; } - if (file_printf(ms, "cannot open `%s' (%s)", - fn, strerror(errno)) == -1) + if (file_printf(ms, "cannot open (%s)", strerror(errno)) == -1) return -1; - ms->event_flags |= EVENT_HAD_ERR; - return -1; + return 0; } ret = 1; @@ -263,7 +261,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) if (handle_mime(ms, mime, "symlink") == -1) return -1; } else if (file_printf(ms, - "%sunreadable symlink `%s' (%s)", COMMA, fn, + "%sunreadable symlink (%s)", COMMA, strerror(errno)) == -1) return -1; break; diff --git a/src/magic.c b/src/magic.c index 93137cd5..741578d2 100644 --- a/src/magic.c +++ b/src/magic.c @@ -33,7 +33,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: magic.c,v 1.79 2013/09/03 08:54:47 christos Exp $") +FILE_RCSID("@(#)$File: magic.c,v 1.80 2013/11/06 19:33:31 christos Exp $") #endif /* lint */ #include "magic.h" @@ -373,8 +373,9 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) pos = lseek(fd, (off_t)0, SEEK_CUR); } else { int flags = O_RDONLY|O_BINARY; + int okstat = stat(inname, &sb) == 0; - if (stat(inname, &sb) == 0 && S_ISFIFO(sb.st_mode)) { + if (okstat && S_ISFIFO(sb.st_mode)) { #ifdef O_NONBLOCK flags |= O_NONBLOCK; #endif @@ -383,7 +384,8 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) errno = 0; if ((fd = open(inname, flags)) < 0) { - if (unreadable_info(ms, sb.st_mode, inname) == -1) + if (okstat && + unreadable_info(ms, sb.st_mode, inname) == -1) goto done; rv = 0; goto done; @@ -418,7 +420,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) } else { if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) { - file_error(ms, errno, "cannot read `%s'", inname); + file_error(ms, errno, "cannot read"); goto done; } } -- 2.40.0