mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
Fix purging old log files with absolute file path
Removing old timestamp or increment versions of log backup files did
not work when the file is an absolute path: only the entry name was
provided to the file remove function.
The dirname was also bogus, since the file separater was put back too
soon.
Fix these issues to make log file rotation work when the file is
configured to be an absolute path.
(cherry picked from commit 70629d73da)
This commit is contained in:
parent
021337f3e2
commit
33ad117166
1 changed files with 52 additions and 28 deletions
|
|
@ -1044,18 +1044,11 @@ greatest_version(isc_logfile_t *file, int versions, int *greatestp) {
|
|||
isc_dir_init(&dir);
|
||||
result = isc_dir_open(&dir, dirname);
|
||||
|
||||
/*
|
||||
* Replace the file separator if it was taken out.
|
||||
*/
|
||||
if (bname != file->name) {
|
||||
*(bname - 1) = sep;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return if the directory open failed.
|
||||
*/
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (isc_dir_read(&dir) == ISC_R_SUCCESS) {
|
||||
|
|
@ -1069,14 +1062,25 @@ greatest_version(isc_logfile_t *file, int versions, int *greatestp) {
|
|||
* Remove any backup files that exceed versions.
|
||||
*/
|
||||
if (*digit_end == '\0' && version >= versions) {
|
||||
result = isc_file_remove(dir.entry.name);
|
||||
char rmfile[PATH_MAX + 1];
|
||||
int n = snprintf(rmfile, sizeof(rmfile),
|
||||
"%s/%s", dirname,
|
||||
dir.entry.name);
|
||||
if (n >= (int)sizeof(rmfile) || n < 0) {
|
||||
result = ISC_R_NOSPACE;
|
||||
syslog(LOG_ERR,
|
||||
"unable to remove log files: %s",
|
||||
isc_result_totext(result));
|
||||
break;
|
||||
}
|
||||
result = isc_file_remove(rmfile);
|
||||
if (result != ISC_R_SUCCESS &&
|
||||
result != ISC_R_FILENOTFOUND)
|
||||
result != ISC_R_NOTFOUND)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"unable to remove "
|
||||
"log file '%s': %s",
|
||||
dir.entry.name,
|
||||
"unable to remove log file "
|
||||
"'%s': %s",
|
||||
rmfile,
|
||||
isc_result_totext(result));
|
||||
}
|
||||
} else if (*digit_end == '\0' && version > greatest) {
|
||||
|
|
@ -1087,8 +1091,16 @@ greatest_version(isc_logfile_t *file, int versions, int *greatestp) {
|
|||
isc_dir_close(&dir);
|
||||
|
||||
*greatestp = greatest;
|
||||
result = ISC_R_SUCCESS;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
out:
|
||||
/*
|
||||
* Replace the file separator if it was taken out.
|
||||
*/
|
||||
if (bname != file->name) {
|
||||
*(bname - 1) = sep;
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1176,18 +1188,11 @@ remove_old_tsversions(isc_logfile_t *file, int versions) {
|
|||
isc_dir_init(&dir);
|
||||
result = isc_dir_open(&dir, dirname);
|
||||
|
||||
/*
|
||||
* Replace the file separator if it was taken out.
|
||||
*/
|
||||
if (bname != file->name) {
|
||||
*(bname - 1) = sep;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return if the directory open failed.
|
||||
*/
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
goto out;
|
||||
}
|
||||
|
||||
last = last_to_keep(versions, &dir, bname, bnamelen);
|
||||
|
|
@ -1206,14 +1211,25 @@ remove_old_tsversions(isc_logfile_t *file, int versions) {
|
|||
* Remove any backup files that exceed versions.
|
||||
*/
|
||||
if (*digit_end == '\0' && version < last) {
|
||||
result = isc_file_remove(dir.entry.name);
|
||||
char rmfile[PATH_MAX + 1];
|
||||
int n = snprintf(rmfile, sizeof(rmfile),
|
||||
"%s/%s", dirname,
|
||||
dir.entry.name);
|
||||
if (n >= (int)sizeof(rmfile) || n < 0) {
|
||||
result = ISC_R_NOSPACE;
|
||||
syslog(LOG_ERR,
|
||||
"unable to remove log files: %s",
|
||||
isc_result_totext(result));
|
||||
break;
|
||||
}
|
||||
result = isc_file_remove(rmfile);
|
||||
if (result != ISC_R_SUCCESS &&
|
||||
result != ISC_R_FILENOTFOUND)
|
||||
result != ISC_R_NOTFOUND)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"unable to remove "
|
||||
"log file '%s': %s",
|
||||
dir.entry.name,
|
||||
"unable to remove log file "
|
||||
"'%s': %s",
|
||||
rmfile,
|
||||
isc_result_totext(result));
|
||||
}
|
||||
}
|
||||
|
|
@ -1221,8 +1237,16 @@ remove_old_tsversions(isc_logfile_t *file, int versions) {
|
|||
}
|
||||
|
||||
isc_dir_close(&dir);
|
||||
result = ISC_R_SUCCESS;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
out:
|
||||
/*
|
||||
* Replace the file separator if it was taken out.
|
||||
*/
|
||||
if (bname != file->name) {
|
||||
*(bname - 1) = sep;
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
|
|
|
|||
Loading…
Reference in a new issue