Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/newsyslog/newsyslog.c
Show All 12 Lines | |||||
return (t); | return (t); | ||||
} else if (s[0] == '/') { | } else if (s[0] == '/') { | ||||
warnx("Invalid log filename '%s'", s); | warnx("Invalid log filename '%s'", s); | ||||
return (t); | return (t); | ||||
} else if ((logfname = strdup(s)) == NULL) | } else if ((logfname = strdup(s)) == NULL) | ||||
err(1, "strdup()"); | err(1, "strdup()"); | ||||
if ((dirp = opendir(dir)) == NULL) { | if ((dirp = opendir(dir)) == NULL) { | ||||
free(logfname); | |||||
warn("Cannot open log directory '%s'", dir); | warn("Cannot open log directory '%s'", dir); | ||||
return (t); | return (t); | ||||
} | } | ||||
dir_fd = dirfd(dirp); | dir_fd = dirfd(dirp); | ||||
/* Open the archive dir and find the most recent archive of logfname. */ | /* Open the archive dir and find the most recent archive of logfname. */ | ||||
while ((dp = readdir(dirp)) != NULL) { | while ((dp = readdir(dirp)) != NULL) { | ||||
if (validate_old_timelog(dir_fd, dp, logfname, &tm) == 0) | if (validate_old_timelog(dir_fd, dp, logfname, &tm) == 0) | ||||
continue; | continue; | ||||
if (fstatat(dir_fd, dp->d_name, &sb, AT_SYMLINK_NOFOLLOW) == -1) { | if (fstatat(dir_fd, dp->d_name, &sb, AT_SYMLINK_NOFOLLOW) == -1) { | ||||
warn("Cannot stat '%s'", file); | warn("Cannot stat '%s'", file); | ||||
continue; | continue; | ||||
} | } | ||||
if (t < sb.st_mtime) | if (t < sb.st_mtime) | ||||
t = sb.st_mtime; | t = sb.st_mtime; | ||||
} | } | ||||
free(logfname); | |||||
closedir(dirp); | closedir(dirp); | ||||
return (t); | return (t); | ||||
} | } | ||||
/* Return the age in hours of the most recent archive of the logfile. */ | /* Return the age in hours of the most recent archive of the logfile. */ | ||||
static int | static int | ||||
age_old_log(const char *file) | age_old_log(const char *file) | ||||
Show All 12 Lines |