summaryrefslogtreecommitdiffstats
path: root/usr.sbin/newsyslog/newsyslog.c
diff options
context:
space:
mode:
authormarkj <markj@FreeBSD.org>2013-05-12 01:58:04 +0000
committermarkj <markj@FreeBSD.org>2013-05-12 01:58:04 +0000
commitdbafd2120ecdd8ad26f05193bfb3f6604453df7d (patch)
tree65a36c690150bd8f6608f856fbc4c902d4686b50 /usr.sbin/newsyslog/newsyslog.c
parentcec511ab6555f8d191878ce5f90a56e67345ff26 (diff)
downloadFreeBSD-src-dbafd2120ecdd8ad26f05193bfb3f6604453df7d.zip
FreeBSD-src-dbafd2120ecdd8ad26f05193bfb3f6604453df7d.tar.gz
Some filesystems (NFS in particular) do not fill out the d_type field when
returning directory entries through readdir(3). In this case we need to obtain the file type ourselves; otherwise newsyslog -t will not be able to find archived log files and will fail to both delete old log files and to do interval-based rotations properly. Reported by: jilles Reviewed by: jilles MFC after: 2 weeks
Diffstat (limited to 'usr.sbin/newsyslog/newsyslog.c')
-rw-r--r--usr.sbin/newsyslog/newsyslog.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c
index 08598ac..1534026 100644
--- a/usr.sbin/newsyslog/newsyslog.c
+++ b/usr.sbin/newsyslog/newsyslog.c
@@ -1452,16 +1452,27 @@ oldlog_entry_compare(const void *a, const void *b)
* tm if this is the case; otherwise return false.
*/
static int
-validate_old_timelog(const struct dirent *dp, const char *logfname, struct tm *tm)
+validate_old_timelog(int fd, const struct dirent *dp, const char *logfname,
+ struct tm *tm)
{
+ struct stat sb;
size_t logfname_len;
char *s;
int c;
logfname_len = strlen(logfname);
- if (dp->d_type != DT_REG)
- return (0);
+ if (dp->d_type != DT_REG) {
+ /*
+ * Some filesystems (e.g. NFS) don't fill out the d_type field
+ * and leave it set to DT_UNKNOWN; in this case we must obtain
+ * the file type ourselves.
+ */
+ if (dp->d_type != DT_UNKNOWN ||
+ fstatat(fd, dp->d_name, &sb, AT_SYMLINK_NOFOLLOW) != 0 ||
+ !S_ISREG(sb.st_mode))
+ return (0);
+ }
/* Ignore everything but files with our logfile prefix. */
if (strncmp(dp->d_name, logfname, logfname_len) != 0)
return (0);
@@ -1547,7 +1558,7 @@ delete_oldest_timelog(const struct conf_entry *ent, const char *archive_dir)
err(1, "Cannot open log directory '%s'", dir);
dir_fd = dirfd(dirp);
while ((dp = readdir(dirp)) != NULL) {
- if (validate_old_timelog(dp, logfname, &tm) == 0)
+ if (validate_old_timelog(dir_fd, dp, logfname, &tm) == 0)
continue;
/*
@@ -2312,10 +2323,10 @@ mtime_old_timelog(const char *file)
dir_fd = dirfd(dirp);
/* Open the archive dir and find the most recent archive of logfname. */
while ((dp = readdir(dirp)) != NULL) {
- if (validate_old_timelog(dp, logfname, &tm) == 0)
+ if (validate_old_timelog(dir_fd, dp, logfname, &tm) == 0)
continue;
- if (fstatat(dir_fd, logfname, &sb, 0) == -1) {
+ if (fstatat(dir_fd, logfname, &sb, AT_SYMLINK_NOFOLLOW) == -1) {
warn("Cannot stat '%s'", file);
continue;
}
OpenPOWER on IntegriCloud