Thank you for useful suggestions, PFA patch, for pg_ctl.c and pg_regress.c it relies on CreateRestrictedProcess() function now.
src/common/restricted_token.c
#define write_stderr(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
src//bin/pg_ctl/pg_ctl.c
static void
write_stderr(const char *fmt,...)
{
...
/*
* On Win32, we print to stderr if running on a console, or write to
* eventlog if running as a service
*/
if (!isatty(fileno(stderr))) /* Running as a service */
{
...
}
src/backend/port/win32/security.c
void
write_stderr(const char *fmt,...)
{
...
/*
* On Win32, we print to stderr if running on a console, or write to
* eventlog if running as a service
*/
if (pgwin32_is_service()) /* Running as a service */
{
...
}
security.c write_stderr() implementation seems correct, that relies on pgwin32_is_service() function but it seems little expensive operation to write error messages. pg_ctl.c write_stderr() implementation depend on isatty() to detect if it is running as service, I doubt that if it is right way to to do so. Any suggestion how to tackle this situation, along with this can we make common routine of write_stderr() function that others use it instead of defining their own ?.
Please do let me know if I missed something or more information is required. Thanks.