Project

General

Profile

Actions

Bug #11639

closed

Entries from rotated log files may be displayed out of order when log display includes contents from multiple files

Added by Jim Pingle over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Logging
Target version:
Start date:
03/09/2021
Due date:
% Done:

100%

Estimated time:
Plus Target Version:
Release Notes:
Default
Affected Version:
2.5.0
Affected Architecture:

Description

The code in rsort_log_filename() is making faulty assumptions about the log filenames. It is not only testing the wrong part of the filename, but it isn't properly accounting for both compressed and uncompressed log filenames.

In some cases it's OK since glob() may happen to return the filenames in order by chance, but when there are a large number of related log files the incorrect order is more apparent.

To reproduce, touch /var/log/filter.log.0 through /var/log/filter.log.18 and then check the contents of the array returned by sort_related_log_files('/var/log/filter.log', false, false).
Remove those files and touch /var/log/filter.log.0.bz2 through /var/log/filter.log.18.bz2 and repeat the test.

In each case it returns a result in an unexpected order, for example:

array(20) {
  [0]=>
  string(21) "/var/log/filter.log.5" 
  [1]=>
  string(21) "/var/log/filter.log.3" 
  [2]=>
  string(21) "/var/log/filter.log.4" 
  [3]=>
  string(22) "/var/log/filter.log.18" 
  [4]=>
  string(21) "/var/log/filter.log.2" 
  [5]=>
  string(21) "/var/log/filter.log.8" 
  [6]=>
  string(21) "/var/log/filter.log.0" 
  [7]=>
  string(22) "/var/log/filter.log.14" 
  [8]=>
  string(22) "/var/log/filter.log.15" 
  [9]=>
  string(22) "/var/log/filter.log.12" 
  [10]=>
  string(22) "/var/log/filter.log.13" 
  [11]=>
  string(22) "/var/log/filter.log.11" 
  [12]=>
  string(22) "/var/log/filter.log.10" 
  [13]=>
  string(21) "/var/log/filter.log.1" 
  [14]=>
  string(21) "/var/log/filter.log.6" 
  [15]=>
  string(22) "/var/log/filter.log.16" 
  [16]=>
  string(21) "/var/log/filter.log.7" 
  [17]=>
  string(22) "/var/log/filter.log.17" 
  [18]=>
  string(21) "/var/log/filter.log.9" 
  [19]=>
  string(19) "/var/log/filter.log" 
}

To me, I have a fix.

Actions #1

Updated by Jim Pingle over 3 years ago

  • Status changed from New to Feedback
  • % Done changed from 0 to 100
Actions #2

Updated by Jim Pingle over 3 years ago

  • Status changed from Feedback to Waiting on Merge

With the commit applied the order is correct for both uncompressed and compressed log files:

array(20) {
  [0]=>
  string(22) "/var/log/filter.log.18" 
  [1]=>
  string(22) "/var/log/filter.log.17" 
  [2]=>
  string(22) "/var/log/filter.log.16" 
  [3]=>
  string(22) "/var/log/filter.log.15" 
  [4]=>
  string(22) "/var/log/filter.log.14" 
  [5]=>
  string(22) "/var/log/filter.log.13" 
  [6]=>
  string(22) "/var/log/filter.log.12" 
  [7]=>
  string(22) "/var/log/filter.log.11" 
  [8]=>
  string(22) "/var/log/filter.log.10" 
  [9]=>
  string(21) "/var/log/filter.log.9" 
  [10]=>
  string(21) "/var/log/filter.log.8" 
  [11]=>
  string(21) "/var/log/filter.log.7" 
  [12]=>
  string(21) "/var/log/filter.log.6" 
  [13]=>
  string(21) "/var/log/filter.log.5" 
  [14]=>
  string(21) "/var/log/filter.log.4" 
  [15]=>
  string(21) "/var/log/filter.log.3" 
  [16]=>
  string(21) "/var/log/filter.log.2" 
  [17]=>
  string(21) "/var/log/filter.log.1" 
  [18]=>
  string(21) "/var/log/filter.log.0" 
  [19]=>
  string(19) "/var/log/filter.log" 
}
array(21) {
  [0]=>
  string(26) "/var/log/filter.log.19.bz2" 
  [1]=>
  string(26) "/var/log/filter.log.18.bz2" 
  [2]=>
  string(26) "/var/log/filter.log.17.bz2" 
  [3]=>
  string(26) "/var/log/filter.log.16.bz2" 
  [4]=>
  string(26) "/var/log/filter.log.15.bz2" 
  [5]=>
  string(26) "/var/log/filter.log.14.bz2" 
  [6]=>
  string(26) "/var/log/filter.log.13.bz2" 
  [7]=>
  string(26) "/var/log/filter.log.12.bz2" 
  [8]=>
  string(26) "/var/log/filter.log.11.bz2" 
  [9]=>
  string(26) "/var/log/filter.log.10.bz2" 
  [10]=>
  string(25) "/var/log/filter.log.9.bz2" 
  [11]=>
  string(25) "/var/log/filter.log.8.bz2" 
  [12]=>
  string(25) "/var/log/filter.log.7.bz2" 
  [13]=>
  string(25) "/var/log/filter.log.6.bz2" 
  [14]=>
  string(25) "/var/log/filter.log.5.bz2" 
  [15]=>
  string(25) "/var/log/filter.log.4.bz2" 
  [16]=>
  string(25) "/var/log/filter.log.3.bz2" 
  [17]=>
  string(25) "/var/log/filter.log.2.bz2" 
  [18]=>
  string(25) "/var/log/filter.log.1.bz2" 
  [19]=>
  string(25) "/var/log/filter.log.0.bz2" 
  [20]=>
  string(19) "/var/log/filter.log" 
}
Actions #3

Updated by Renato Botelho over 3 years ago

  • Status changed from Waiting on Merge to Feedback

Cherry-picked to RELENG_2_5_1

Actions #4

Updated by Jim Pingle over 3 years ago

  • Subject changed from rsort_log_filename() in syslog.inc is not sorting properly to Entries from rotated log files may be displayed out of order when log display includes contents from multiple files

Updating subject for release notes.

Actions #5

Updated by Jim Pingle over 3 years ago

  • Status changed from Feedback to Closed

Fixed.

Actions

Also available in: Atom PDF