Skip to content

Commit

Permalink
logger: Fix crash bug when log rotate is enabled (groonga#1871)
Browse files Browse the repository at this point in the history
This bug occurred in the following conditions.

* When logging to a file
  *  `--log-path <path>`
  * `--query-log-path <path>`
* Log rotate is enabled
  * `--log-rotate-threshold-size <threshold>`
  * `--query-log-rotate-threshold-size <threshold>`
* Process ID log output is enabled
  * `--log-flags process_id`

When the log is rotated, `output->file` is closed and set to `NULL`.
The crash occurs because of `flock(fileno(output->file), LOCK_UN);` in
that state.
This unlocking was only executed when outputting process ID to the log,
so it occurred only when outputting process ID.
  • Loading branch information
abetomo authored Aug 19, 2024
1 parent c5da362 commit 778c539
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ grn_logger_output_end(grn_ctx *ctx,
output->file != stderr &&
(output->rotate_threshold_size > 0 &&
output->size >= output->rotate_threshold_size)) {
#ifndef _WIN32
if (output->need_flock) {
flock(fileno(output->file), LOCK_UN);
}
#endif
fclose(output->file);
output->file = NULL;
grn_logger_output_rotate(ctx, output);
Expand All @@ -321,7 +326,7 @@ grn_logger_output_end(grn_ctx *ctx,
}
}
#ifndef _WIN32
if (output->need_flock) {
if (output->need_flock && output->file) {
flock(fileno(output->file), LOCK_UN);
}
#endif
Expand Down

0 comments on commit 778c539

Please sign in to comment.