log: add log_location parameter to allow log redirection to file#11858
log: add log_location parameter to allow log redirection to file#11858philippfriese wants to merge 1 commit intoofiwg:mainfrom
Conversation
| goto error_log_location; | ||
| } | ||
|
|
||
| log_location = fopen(path_buffer, "w"); |
Check failure
Code scanning / CodeQL
Time-of-check time-of-use filesystem race condition High
| log_location = fopen(path_buffer, "w"); | ||
| if (log_location == NULL) | ||
| goto error_log_location; | ||
| if (chmod(path_buffer, mode) == -1) |
Check failure
Code scanning / CodeQL
Time-of-check time-of-use filesystem race condition High
|
The line indentation is off -- using spaces instead of tabs. A library should never print without explicitly being enabled to do so. For all the library knows, stderr could have been closed and redirected to an application file. Use only logging functions to print errors, not direct calls to fprintf. |
2da5ff9 to
c1d1924
Compare
|
Thank you for the feedback @shefty. I have pushed an updated commit which moves the fprintf calls to the OFI logging macros. As for the line indentation: I adjusted some indentations but overall could not find places where my changes use spaces instead of tabs. Is this an issue on my end or did I miss spots where I did in fact use spaces for indentation? |
src/log.c
Outdated
| char path_buffer[PATH_MAX]; | ||
| int len; | ||
|
|
||
| if (strncmp(locationstr, "stderr", 6) == 0 || *locationstr == '\0') { |
There was a problem hiding this comment.
Better to use strcmp instead. Reason: (1) for exact match; (2) the second string is constant with known length so the comparison will stop after 6 characters any way. Same for L126.
There was a problem hiding this comment.
Thanks! Changed in the updated commit.
| strncpy(path_buffer, locationstr, PATH_MAX-1); | ||
| if (stat(dirname(path_buffer), &st) == -1) | ||
| goto error_log_location; | ||
| strncpy(path_buffer, locationstr, PATH_MAX-1); |
There was a problem hiding this comment.
This is in fact intentional: dirname may modify the input string, so the second strncpy fetches a fresh version. I have added a comment in the updated commit to document this intent.
Signed-off-by: Philipp Friese <philipp.friese@cit.tum.de>
c1d1924 to
5565f71
Compare
This PR adds the parameter
log_location/ the environment variabelFI_LOG_LOCATIONto the standard logging provider in to allow control of the output location of the libfabric log. Possible options are: stderr (default), stdout, as well as a path to a file or to a directory. If a directory is provided, a log file with formatofi_<pid>.logis used. Log files are created with the file mode specified vialog_location_mode/FI_LOG_LOCATION_MODE, defaulting to0600, and must not exist prior to launching libfabric[1].The use-case of this parameter concerns multi-process application cases, such as MPI applications. By default, libfabric writes to stderr, which is usually unbuffered. Even when stderr of an MPI application is redirected to per-process files, for example using Open MPIs
--output-filenameoption, then the libfabric log still contains interleaved lines, resulting in one MPI process' log containing a log line from another MPI process.When modifying stderr to be line-buffered, then libfabric log entries are no longer interleaved, but may be out-of-order, which may render certain provider outputs impossible to interpret correctly. An example is the output of the
ofi_hook_profileprovider, which relies on strict line ordering for its output sematic.While libfabric allows the logging provider to be extended and overwritten programmatically, this approach is not feasible for applications using another communication library on-top of libfabric, such as MPI applications.
The parameter introduced in this PR addresses this.
[1] This is to prevent libfabric from overwriting/modifying files via an accidentally or intentionally mis-crafted log location path.
Usage Example