Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that created log files' names start with the specified name
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().
- Loading branch information