RE: [Proposal] Adding Log File Capability to pg_createsubscriber - Mailing list pgsql-hackers

From Hayato Kuroda (Fujitsu)
Subject RE: [Proposal] Adding Log File Capability to pg_createsubscriber
Date
Msg-id OS9PR01MB12149F1AD9C79A2644753A18AF548A@OS9PR01MB12149.jpnprd01.prod.outlook.com
Whole thread Raw
In response to Re: [Proposal] Adding Log File Capability to pg_createsubscriber  (Chao Li <li.evan.chao@gmail.com>)
List pgsql-hackers
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 


pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Use SIGTERM instead of SIGUSR1 for slotsync worker to exit during promotion?
Next
From: Rushabh Lathia
Date:
Subject: Re: ORDER BY ALL