Skip to content

Ensure that created log files' names start with the specified name - #6236

Merged
dsouzai merged 2 commits into
eclipse-omr:masterfrom
jdmpapin:suffix-only-logs
Nov 10, 2021
Merged

dsouzai merged 2 commits into
eclipse-omr:masterfrom
jdmpapin:suffix-only-logs

Conversation

@jdmpapin

Copy link
Copy Markdown
Contributor

Prior to this change, if suffixLogs (i.e. TR_EnablePIDExtension) was enabled (which by default it is), log files for compilation threads other than compilation thread 0 would be opened using a name consisting of only the extra suffix, e.g. ".193310.88163.20211109.150243.193310".

The cause was as follows:

  1. When openLogFile() got a valid idSuffix, it would concatenate _logFileName with it into a stack buffer (filename).

  2. Then when suffixLogs was also enabled, it would use the same stack buffer (filename) as the destination for the concatenation of the name so far (e.g. foo.log.1) with the PID and time. This was a call to sprintf() in which the destination buffer was also passed as an argument corresponding to a %s format specifier. This could (depending on platform?) behave as though the string argument was just an empty string.

Note that the compilation thread ID was also lost, so any threads other than compilation thread 0 could pass the same filename to trfopen() if they started to trace within the same second, resulting in too few log files created. Since trfopen() is implemented via fopen(), we can expect that such a log opened multiple times will be truncated on each open (after the first).

This problem is fixed by replacing the single buffer (filename) on the stack with a pair of buffers (buf0, buf1). At any given time, one is considered the next destination (destBuf). After formatting into destBuf, the buffers are swapped to ensure that it is safe to format into destBuf again. With this pair of buffers in place, it is no longer necessary to declare another buffer (tmp) for getFormattedName().


There is one additional commit to remove uses of sprintf() in OMROptions.cpp

Prior to this change, if suffixLogs (i.e. TR_EnablePIDExtension) was
enabled (which by default it is), log files for compilation threads
other than compilation thread 0 would be opened using a name consisting
of only the extra suffix, e.g. ".193310.88163.20211109.150243.193310".

The cause was as follows:

1. When openLogFile() got a valid idSuffix, it would concatenate
   _logFileName with it into a stack buffer (filename).

2. Then when suffixLogs was also enabled, it would use the same stack
   buffer (filename) as the destination for the concatenation of the
   name so far (e.g. foo.log.1) with the PID and time. This was a call
   to sprintf() in which the destination buffer was also passed as an
   argument corresponding to a %s format specifier. This could
   (depending on platform?) behave as though the string argument was
   just an empty string.

Note that the compilation thread ID was also lost, so any threads other
than compilation thread 0 could pass the same filename to trfopen() if
they started to trace within the same second, resulting in too few log
files created. Since trfopen() is implemented via fopen(), we can expect
that such a log opened multiple times will be truncated on each open
(after the first).

This problem is fixed by replacing the single buffer (filename) on the
stack with a pair of buffers (buf0, buf1). At any given time, one is
considered the next destination (destBuf). After formatting into
destBuf, the buffers are swapped to ensure that it is safe to format
into destBuf again. With this pair of buffers in place, it is no longer
necessary to declare another buffer (tmp) for getFormattedName().
sprintf() is unsafe and should not be used.
@jdmpapin

Copy link
Copy Markdown
Contributor Author

@dsouzai, could I get your review?

@jdmpapin
jdmpapin requested a review from dsouzai November 10, 2021 14:28
@dsouzai

dsouzai commented Nov 10, 2021

Copy link
Copy Markdown
Contributor

Jenkins build all

@dsouzai
dsouzai merged commit af0be75 into eclipse-omr:master Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants