26 #elif defined(_MSC_VER) 49 #define LOG_OPENVPN LOG_DAEMON 87 static char *pgmname_syslog;
109 const int ceiling = 15;
111 if (level >= 0 && level <= ceiling)
175 #ifdef OPENVPN_DEBUG_COMMAND_LINE 210 #define SWAP { tmp = m1; m1 = m2; m2 = tmp; } 218 va_start(arglist, format);
227 #if SYSLOG_CAPABILITY 235 const char *prefix_sep;
239 #ifndef HAVE_VARARG_MACROS 252 #ifndef HAVE_VARARG_MACROS 281 #if SYSLOG_CAPABILITY 308 prefix_sep = prefix =
"";
329 #if SYSLOG_CAPABILITY 330 syslog(level,
"%s%s%s",
344 gettimeofday(&tv, NULL);
346 fprintf(fp,
"%" PRIi64
".%06ld %x %s%s%s%s",
358 fprintf(fp,
"%s%s%s%s",
362 (flags&
M_NOLF) ?
"" :
"\n");
366 fprintf(fp,
"%s %s%s%s%s",
371 (flags&
M_NOLF) ?
"" :
"\n");
380 msg(
M_INFO,
"Exiting due to fatal error");
410 msg(
M_INFO | M_NOMUTE,
"NOTE: --mute triggered...");
423 "%d variation(s) on previous %d message(s) suppressed by --mute",
439 msg(
M_FATAL,
"Assertion failed at %s:%d (%s)", filename, line, condition);
443 msg(
M_FATAL,
"Assertion failed at %s:%d", filename, line);
462 #if SYSLOG_CAPABILITY 468 openlog(pgmname_syslog, LOG_PID, LOG_OPENVPN);
479 msg(
M_WARN,
"Warning on use of --daemon/--inetd: this operating system lacks daemon logging features, therefore when I become a daemon, I won't be able to log status or error messages");
486 #if SYSLOG_CAPABILITY 491 free(pgmname_syslog);
492 pgmname_syslog = NULL;
510 return GetStdHandle(STD_ERROR_HANDLE);
526 SECURITY_ATTRIBUTES saAttr;
527 saAttr.nLength =
sizeof(SECURITY_ATTRIBUTES);
528 saAttr.bInheritHandle = TRUE;
529 saAttr.lpSecurityDescriptor = NULL;
535 append ? OPEN_ALWAYS : CREATE_ALWAYS,
536 FILE_ATTRIBUTE_NORMAL,
541 if (log_handle == INVALID_HANDLE_VALUE)
550 if (SetFilePointer(log_handle, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
552 msg(
M_ERR,
"Error: cannot seek to end of --log file: %s", file);
561 if (!SetStdHandle(STD_OUTPUT_HANDLE, log_handle)
562 || !SetStdHandle(STD_ERROR_HANDLE, log_handle))
564 msg(
M_ERR,
"Error: cannot redirect stdout/stderr to --log file: %s", file);
569 log_fd = _open_osfhandle((intptr_t)log_handle, _O_TEXT);
572 msg(
M_ERR,
"Error: --log redirect failed due to _open_osfhandle failure");
577 msgfp = _fdopen(log_fd,
"wt");
580 msg(
M_ERR,
"Error: --log redirect failed due to _fdopen");
584 if (_dup2(log_fd, 1) == -1 || _dup2(log_fd, 2) == -1)
586 msg(
M_WARN,
"Error: --log redirect of stdout/stderr failed");
591 #elif defined(HAVE_DUP2) 595 O_CREAT | O_WRONLY | (append ? O_APPEND : O_TRUNC),
600 msg(
M_WARN|
M_ERRNO,
"Warning: Error redirecting stdout/stderr to --log file: %s", file);
604 if (dup2(out, 1) == -1)
606 msg(
M_ERR,
"--log file redirection error on stdout");
608 if (dup2(out, 2) == -1)
610 msg(
M_ERR,
"--log file redirection error on stderr");
622 msg(
M_WARN,
"WARNING: The --log option is not supported on this OS because it lacks the dup2 function");
659 const char *description,
664 const char *extended_msg = NULL;
674 #if EXTENDED_SOCKET_ERROR_CAPABILITY 679 extended_msg = format_extended_socket_error(sock->
sd, &mtu, &gc);
680 if (mtu > 0 && sock->
mtu != mtu)
686 #elif defined(_WIN32) 699 extended_msg, strerror(my_errno), my_errno);
705 strerror(my_errno), my_errno);
754 port_share_abort(port_share);
758 #ifdef ENABLE_MEMSTATS 762 #ifdef ABORT_ON_ERROR 834 case ERROR_GEN_FAILURE:
835 return "General failure (ERROR_GEN_FAILURE)";
837 case ERROR_IO_PENDING:
838 return "I/O Operation in progress (ERROR_IO_PENDING)";
840 case WSA_IO_INCOMPLETE:
841 return "I/O Operation in progress (WSA_IO_INCOMPLETE)";
844 return "Interrupted system call (WSAEINTR)";
847 return "Bad file number (WSAEBADF)";
850 return "Permission denied (WSAEACCES)";
853 return "Bad address (WSAEFAULT)";
856 return "Invalid argument (WSAEINVAL)";
859 return "Too many open files (WSAEMFILE)";
862 return "Operation would block (WSAEWOULDBLOCK)";
865 return "Operation now in progress (WSAEINPROGRESS)";
868 return "Operation already in progress (WSAEALREADY)";
870 case WSAEDESTADDRREQ:
871 return "Destination address required (WSAEDESTADDRREQ)";
874 return "Message too long (WSAEMSGSIZE)";
877 return "Protocol wrong type for socket (WSAEPROTOTYPE)";
880 return "Bad protocol option (WSAENOPROTOOPT)";
882 case WSAEPROTONOSUPPORT:
883 return "Protocol not supported (WSAEPROTONOSUPPORT)";
885 case WSAESOCKTNOSUPPORT:
886 return "Socket type not supported (WSAESOCKTNOSUPPORT)";
889 return "Operation not supported on socket (WSAEOPNOTSUPP)";
891 case WSAEPFNOSUPPORT:
892 return "Protocol family not supported (WSAEPFNOSUPPORT)";
894 case WSAEAFNOSUPPORT:
895 return "Address family not supported by protocol family (WSAEAFNOSUPPORT)";
898 return "Address already in use (WSAEADDRINUSE)";
901 return "Network is down (WSAENETDOWN)";
904 return "Network is unreachable (WSAENETUNREACH)";
907 return "Net dropped connection or reset (WSAENETRESET)";
909 case WSAECONNABORTED:
910 return "Software caused connection abort (WSAECONNABORTED)";
913 return "Connection reset by peer (WSAECONNRESET)";
916 return "No buffer space available (WSAENOBUFS)";
919 return "Socket is already connected (WSAEISCONN)";
922 return "Socket is not connected (WSAENOTCONN)";
925 return "Connection timed out (WSAETIMEDOUT)";
927 case WSAECONNREFUSED:
928 return "Connection refused (WSAECONNREFUSED)";
931 return "Too many levels of symbolic links (WSAELOOP)";
933 case WSAENAMETOOLONG:
934 return "File name too long (WSAENAMETOOLONG)";
937 return "Host is down (WSAEHOSTDOWN)";
939 case WSAEHOSTUNREACH:
940 return "No Route to Host (WSAEHOSTUNREACH)";
943 return "Directory not empty (WSAENOTEMPTY)";
946 return "Too many processes (WSAEPROCLIM)";
949 return "Too many users (WSAEUSERS)";
952 return "Disc Quota Exceeded (WSAEDQUOT)";
955 return "Stale NFS file handle (WSAESTALE)";
958 return "Network SubSystem is unavailable (WSASYSNOTREADY)";
960 case WSAVERNOTSUPPORTED:
961 return "WINSOCK DLL Version out of range (WSAVERNOTSUPPORTED)";
963 case WSANOTINITIALISED:
964 return "Successful WSASTARTUP not yet performed (WSANOTINITIALISED)";
967 return "Too many levels of remote in path (WSAEREMOTE)";
969 case WSAHOST_NOT_FOUND:
970 return "Host not found (WSAHOST_NOT_FOUND)";
981 const int status = FormatMessage(
982 FORMAT_MESSAGE_IGNORE_INSERTS
983 | FORMAT_MESSAGE_FROM_SYSTEM
984 | FORMAT_MESSAGE_ARGUMENT_ARRAY,
998 for (cp = message; *cp !=
'\0'; ++cp)
1000 if (*cp ==
'\n' || *cp ==
'\r')
WCHAR * wide_string(const char *utf8, struct gc_arena *gc)
void open_syslog(const char *pgmname, bool stdio_to_null)
void x_check_status(int status, const char *description, struct link_socket *sock, struct tuntap *tt)
static HANDLE orig_stderr
void set_std_files_to_null(bool stdin_only)
HANDLE get_orig_stderr(void)
void assert_failed(const char *filename, int line, const char *condition)
static void virtual_output_print(const struct virtual_output *vo, const unsigned int flags, const char *str)
char * string_alloc(const char *str, struct gc_arena *gc)
static bool machine_readable_output
void set_machine_readable_output(bool parsable)
static void gc_free(struct gc_arena *a)
void openvpn_exit(const int status)
const char * msg_flags_string(const unsigned int flags, struct gc_arena *gc)
unsigned int x_cs_verbose_level
static bool suppress_timestamps
static const char * msg_get_prefix(void)
bool buf_printf(struct buffer *buf, const char *format,...)
void remove_pid_file(void)
struct link_socket_info info
bool dont_mute(unsigned int flags)
Check muting filter.
void x_msg_va(const unsigned int flags, const char *format, va_list arglist)
static bool check_debug_level(unsigned int level)
const char * tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
static bool tuntap_defined(const struct tuntap *tt)
#define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE
int get_debug_level(void)
static FILE * default_out
bool openvpn_snprintf(char *str, size_t size, const char *format,...)
static void perf_output_results(void)
static struct gc_arena gc_new(void)
static const struct virtual_output * msg_get_virtual_output(void)
void errors_to_stderr(void)
const char * x_msg_prefix
static void gc_init(struct gc_arena *a)
void set_suppress_timestamps(bool suppressed)
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
const char * time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc)
void reset_check_status(void)
static SERVICE_STATUS status
void redirect_stdout_stderr(const char *file, bool append)
FILE * msg_fp(const unsigned int flags)
const char * strerror_win32(DWORD errnum, struct gc_arena *gc)
#define DEBUG_LEVEL_USEC_TIME
#define OPENVPN_DEBUG_FILE
const struct virtual_output * x_msg_virtual_output
static FILE * default_err
void set_check_status(unsigned int info_level, unsigned int verbose_level)
static bool msg_test(unsigned int flags)
Return true if flags represent an enabled, not muted log level.
unsigned int x_debug_level
bool set_debug_level(const int level, const unsigned int flags)
Wrapper structure for dynamically allocated memory.
void x_msg(const unsigned int flags, const char *format,...)
int get_mute_cutoff(void)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
static int constrain_int(int x, int min, int max)
static bool ignore_sys_error(const int err)
Garbage collection arena used to keep track of dynamically allocated memory.
#define OPENVPN_EXIT_STATUS_ERROR
unsigned int x_cs_err_delay_ms
const char * proto2ascii(int proto, sa_family_t af, bool display_form)
unsigned int x_cs_info_level
#define OPENVPN_EXIT_STATUS_GOOD
bool set_mute_cutoff(const int cutoff)
#define DECODE_MUTE_LEVEL(flags)