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.c48
1 files changed, 16 insertions, 32 deletions
diff --git a/src/openvpn/error.c b/src/openvpn/error.c
index bc14e8c..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
@@ -31,6 +31,7 @@
#include "error.h"
#include "buffer.h"
+#include "init.h"
#include "misc.h"
#include "win32.h"
#include "socket.h"
@@ -342,9 +343,9 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
struct timeval tv;
gettimeofday(&tv, NULL);
- fprintf(fp, "%"PRIi64".%06lu %x %s%s%s%s",
+ fprintf(fp, "%" PRIi64 ".%06ld %x %s%s%s%s",
(int64_t)tv.tv_sec,
- (unsigned long)tv.tv_usec,
+ (long)tv.tv_usec,
flags,
prefix,
prefix_sep,
@@ -497,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
@@ -556,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);
@@ -687,7 +674,10 @@ x_check_status(int status,
}
#elif defined(_WIN32)
/* get possible driver error from TAP-Windows driver */
- extended_msg = tap_win_getinfo(tt, &gc);
+ if (tuntap_defined(tt))
+ {
+ extended_msg = tap_win_getinfo(tt, &gc);
+ }
#endif
if (!ignore_sys_error(my_errno))
{
@@ -734,18 +724,12 @@ openvpn_exit(const int status)
{
if (!forked)
{
- void tun_abort();
-
-#ifdef ENABLE_PLUGIN
- void plugin_abort(void);
-
-#endif
-
tun_abort();
#ifdef _WIN32
uninit_win32();
#endif
+ remove_pid_file();
close_syslog();