summaryrefslogtreecommitdiff
path: root/src/openvpn/error.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvpn/error.c')
-rw-r--r--src/openvpn/error.c30
1 files changed, 8 insertions, 22 deletions
diff --git a/src/openvpn/error.c b/src/openvpn/error.c
index d6247fe..10be3e0 100644
--- a/src/openvpn/error.c
+++ b/src/openvpn/error.c
@@ -5,7 +5,7 @@
* packet encryption, packet authentication, and
* packet compression.
*
- * Copyright (C) 2002-2018 OpenVPN Inc <sales@openvpn.net>
+ * Copyright (C) 2002-2021 OpenVPN Inc <sales@openvpn.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
@@ -498,22 +498,12 @@ close_syslog(void)
}
#ifdef _WIN32
+static int orig_stderr;
-static HANDLE orig_stderr;
-
-HANDLE
-get_orig_stderr(void)
+int get_orig_stderr()
{
- if (orig_stderr)
- {
- return orig_stderr;
- }
- else
- {
- return GetStdHandle(STD_ERROR_HANDLE);
- }
+ return orig_stderr ? orig_stderr : _fileno(stderr);
}
-
#endif
void
@@ -557,16 +547,12 @@ redirect_stdout_stderr(const char *file, bool append)
}
/* save original stderr for password prompts */
- orig_stderr = GetStdHandle(STD_ERROR_HANDLE);
-
-#if 0 /* seems not be necessary with stdout/stderr redirection below*/
- /* set up for redirection */
- if (!SetStdHandle(STD_OUTPUT_HANDLE, log_handle)
- || !SetStdHandle(STD_ERROR_HANDLE, log_handle))
+ orig_stderr = _dup(_fileno(stderr));
+ if (orig_stderr == -1)
{
- msg(M_ERR, "Error: cannot redirect stdout/stderr to --log file: %s", file);
+ msg(M_WARN | M_ERRNO, "Warning: cannot duplicate stderr, password prompts will appear in log file instead of console.");
+ orig_stderr = _fileno(stderr);
}
-#endif
/* direct stdout/stderr to point to log_handle */
log_fd = _open_osfhandle((intptr_t)log_handle, _O_TEXT);