Dear Chao,
> One comment on v17.
> ```
> + if (internal_log_file_fp != NULL)
> + {
> + if (fclose(internal_log_file_fp) != 0)
> + report_createsub_fatal("could not
> close %s/%s.log: %m", logdir, INTERNAL_LOG_FILE_NAME);
> + internal_log_file_fp = NULL;
> + }
> ```
>
> As the error is about internal_log_file_fp, meaning it may no longer able to write to
> internal_log_file_fp anymore, we should avoid use report_createsub_fatal to log
> the error again. Maybe just a pg_fatal(), or just log to stderr.
I checked and found [1] in the exit() specification. It means all file descriptors
opened by the process would be closed automatically when the process exits.
So no need to try fclose() and report the failure here. Similarly, pg_upgrade
does not have fclose(log_opts.internal) in case of failures.
[1]:
First, all functions registered by the atexit function are called, in the reverse
order of their registration, except that a function is called after any previously
registered functions that had already been called at the time it was registered.
If, during the call to any such function, a call to the longjmp function is made
that would terminate the call to the registered function, the behavior is
undefined.
Next, all open streams with unwritten buffered data are flushed, all open streams
are closed, and all files created by the tmpfile function are removed.
Best regards,
Hayato Kuroda
FUJITSU LIMITED