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 493 free(pgmname_syslog);
494 pgmname_syslog = NULL;
513 return GetStdHandle(STD_ERROR_HANDLE);
529 SECURITY_ATTRIBUTES saAttr;
530 saAttr.nLength =
sizeof(SECURITY_ATTRIBUTES);
531 saAttr.bInheritHandle = TRUE;
532 saAttr.lpSecurityDescriptor = NULL;
538 append ? OPEN_ALWAYS : CREATE_ALWAYS,
539 FILE_ATTRIBUTE_NORMAL,
544 if (log_handle == INVALID_HANDLE_VALUE)
553 if (SetFilePointer(log_handle, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
555 msg(
M_ERR,
"Error: cannot seek to end of --log file: %s", file);
564 if (!SetStdHandle(STD_OUTPUT_HANDLE, log_handle)
565 || !SetStdHandle(STD_ERROR_HANDLE, log_handle))
567 msg(
M_ERR,
"Error: cannot redirect stdout/stderr to --log file: %s", file);
572 log_fd = _open_osfhandle((intptr_t)log_handle, _O_TEXT);
575 msg(
M_ERR,
"Error: --log redirect failed due to _open_osfhandle failure");
580 msgfp = _fdopen(log_fd,
"wt");
583 msg(
M_ERR,
"Error: --log redirect failed due to _fdopen");
587 if (_dup2(log_fd, 1) == -1 || _dup2(log_fd, 2) == -1)
589 msg(
M_WARN,
"Error: --log redirect of stdout/stderr failed");
594 #elif defined(HAVE_DUP2) 598 O_CREAT | O_WRONLY | (append ? O_APPEND : O_TRUNC),
603 msg(
M_WARN|
M_ERRNO,
"Warning: Error redirecting stdout/stderr to --log file: %s", file);
607 if (dup2(out, 1) == -1)
609 msg(
M_ERR,
"--log file redirection error on stdout");
611 if (dup2(out, 2) == -1)
613 msg(
M_ERR,
"--log file redirection error on stderr");
625 msg(
M_WARN,
"WARNING: The --log option is not supported on this OS because it lacks the dup2 function");
662 const char *description,
667 const char *extended_msg = NULL;
677 #if EXTENDED_SOCKET_ERROR_CAPABILITY 682 extended_msg = format_extended_socket_error(sock->
sd, &mtu, &gc);
683 if (mtu > 0 && sock->
mtu != mtu)
689 #elif defined(_WIN32) 699 extended_msg, strerror(my_errno), my_errno);
705 strerror(my_errno), my_errno);
753 port_share_abort(port_share);
757 #ifdef ENABLE_MEMSTATS 761 #ifdef ABORT_ON_ERROR 833 case ERROR_GEN_FAILURE:
834 return "General failure (ERROR_GEN_FAILURE)";
836 case ERROR_IO_PENDING:
837 return "I/O Operation in progress (ERROR_IO_PENDING)";
839 case WSA_IO_INCOMPLETE:
840 return "I/O Operation in progress (WSA_IO_INCOMPLETE)";
843 return "Interrupted system call (WSAEINTR)";
846 return "Bad file number (WSAEBADF)";
849 return "Permission denied (WSAEACCES)";
852 return "Bad address (WSAEFAULT)";
855 return "Invalid argument (WSAEINVAL)";
858 return "Too many open files (WSAEMFILE)";
861 return "Operation would block (WSAEWOULDBLOCK)";
864 return "Operation now in progress (WSAEINPROGRESS)";
867 return "Operation already in progress (WSAEALREADY)";
869 case WSAEDESTADDRREQ:
870 return "Destination address required (WSAEDESTADDRREQ)";
873 return "Message too long (WSAEMSGSIZE)";
876 return "Protocol wrong type for socket (WSAEPROTOTYPE)";
879 return "Bad protocol option (WSAENOPROTOOPT)";
881 case WSAEPROTONOSUPPORT:
882 return "Protocol not supported (WSAEPROTONOSUPPORT)";
884 case WSAESOCKTNOSUPPORT:
885 return "Socket type not supported (WSAESOCKTNOSUPPORT)";
888 return "Operation not supported on socket (WSAEOPNOTSUPP)";
890 case WSAEPFNOSUPPORT:
891 return "Protocol family not supported (WSAEPFNOSUPPORT)";
893 case WSAEAFNOSUPPORT:
894 return "Address family not supported by protocol family (WSAEAFNOSUPPORT)";
897 return "Address already in use (WSAEADDRINUSE)";
900 return "Network is down (WSAENETDOWN)";
903 return "Network is unreachable (WSAENETUNREACH)";
906 return "Net dropped connection or reset (WSAENETRESET)";
908 case WSAECONNABORTED:
909 return "Software caused connection abort (WSAECONNABORTED)";
912 return "Connection reset by peer (WSAECONNRESET)";
915 return "No buffer space available (WSAENOBUFS)";
918 return "Socket is already connected (WSAEISCONN)";
921 return "Socket is not connected (WSAENOTCONN)";
924 return "Connection timed out (WSAETIMEDOUT)";
926 case WSAECONNREFUSED:
927 return "Connection refused (WSAECONNREFUSED)";
930 return "Too many levels of symbolic links (WSAELOOP)";
932 case WSAENAMETOOLONG:
933 return "File name too long (WSAENAMETOOLONG)";
936 return "Host is down (WSAEHOSTDOWN)";
938 case WSAEHOSTUNREACH:
939 return "No Route to Host (WSAEHOSTUNREACH)";
942 return "Directory not empty (WSAENOTEMPTY)";
945 return "Too many processes (WSAEPROCLIM)";
948 return "Too many users (WSAEUSERS)";
951 return "Disc Quota Exceeded (WSAEDQUOT)";
954 return "Stale NFS file handle (WSAESTALE)";
957 return "Network SubSystem is unavailable (WSASYSNOTREADY)";
959 case WSAVERNOTSUPPORTED:
960 return "WINSOCK DLL Version out of range (WSAVERNOTSUPPORTED)";
962 case WSANOTINITIALISED:
963 return "Successful WSASTARTUP not yet performed (WSANOTINITIALISED)";
966 return "Too many levels of remote in path (WSAEREMOTE)";
968 case WSAHOST_NOT_FOUND:
969 return "Host not found (WSAHOST_NOT_FOUND)";
980 const int status = FormatMessage(
981 FORMAT_MESSAGE_IGNORE_INSERTS
982 | FORMAT_MESSAGE_FROM_SYSTEM
983 | FORMAT_MESSAGE_ARGUMENT_ARRAY,
997 for (cp = message; *cp !=
'\0'; ++cp)
999 if (*cp ==
'\n' || *cp ==
'\r')
void set_machine_readable_output(bool parsable)
static bool msg_test(unsigned int flags)
Return true if flags represent an enabled, not muted log level.
WCHAR * wide_string(const char *utf8, struct gc_arena *gc)
void set_std_files_to_null(bool stdin_only)
static void virtual_output_print(const struct virtual_output *vo, const unsigned int flags, const char *str)
void x_msg_va(const unsigned int flags, const char *format, va_list arglist)
char * string_alloc(const char *str, struct gc_arena *gc)
const char * strerror_win32(DWORD errnum, struct gc_arena *gc)
#define OPENVPN_EXIT_STATUS_GOOD
const char * x_msg_prefix
static void gc_free(struct gc_arena *a)
const char * msg_flags_string(const unsigned int flags, struct gc_arena *gc)
void openvpn_exit(const int status)
static bool check_debug_level(unsigned int level)
void x_check_status(int status, const char *description, struct link_socket *sock, struct tuntap *tt)
bool buf_printf(struct buffer *buf, const char *format,...)
static const char * msg_get_prefix(void)
static bool machine_readable_output
struct link_socket_info info
const char * tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
unsigned int x_cs_info_level
void assert_failed(const char *filename, int line, const char *condition)
bool openvpn_snprintf(char *str, size_t size, const char *format,...)
int get_debug_level(void)
static HANDLE orig_stderr
static void perf_output_results(void)
static struct gc_arena gc_new(void)
void redirect_stdout_stderr(const char *file, bool append)
static bool ignore_sys_error(const int err)
void set_check_status(unsigned int info_level, unsigned int verbose_level)
static void gc_init(struct gc_arena *a)
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
void errors_to_stderr(void)
static FILE * default_out
static const struct virtual_output * msg_get_virtual_output(void)
bool set_mute_cutoff(const int cutoff)
const char * time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc)
#define DECODE_MUTE_LEVEL(flags)
static SERVICE_STATUS status
HANDLE get_orig_stderr(void)
#define DEBUG_LEVEL_USEC_TIME
#define OPENVPN_DEBUG_FILE
int get_mute_cutoff(void)
void x_msg(const unsigned int flags, const char *format,...)
void open_syslog(const char *pgmname, bool stdio_to_null)
#define OPENVPN_EXIT_STATUS_ERROR
FILE * msg_fp(const unsigned int flags)
bool dont_mute(unsigned int flags)
Check muting filter.
Wrapper structure for dynamically allocated memory.
void set_suppress_timestamps(bool suppressed)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
static int constrain_int(int x, int min, int max)
static bool suppress_timestamps
bool set_debug_level(const int level, const unsigned int flags)
Garbage collection arena used to keep track of dynamically allocated memory.
unsigned int x_debug_level
#define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE
const char * proto2ascii(int proto, sa_family_t af, bool display_form)
void reset_check_status(void)
static FILE * default_err
const struct virtual_output * x_msg_virtual_output
unsigned int x_cs_err_delay_ms
unsigned int x_cs_verbose_level