Go to the documentation of this file.
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; }
215 x_msg(
const unsigned int flags,
const char *format, ...)
218 va_start(arglist, format);
232 return strerror(err);
236 x_msg_va(
const unsigned int flags,
const char *format, va_list arglist)
239 #if SYSLOG_CAPABILITY
247 const char *prefix_sep;
257 bool crt_error =
false;
290 #if SYSLOG_CAPABILITY
317 prefix_sep = prefix =
"";
338 #if SYSLOG_CAPABILITY
339 syslog(level,
"%s%s%s",
353 gettimeofday(&tv, NULL);
355 fprintf(fp,
"%" PRIi64
".%06ld %x %s%s%s%s",
367 fprintf(fp,
"%s%s%s%s",
371 (flags&
M_NOLF) ?
"" :
"\n");
375 fprintf(fp,
"%s %s%s%s%s",
380 (flags&
M_NOLF) ?
"" :
"\n");
389 msg(
M_INFO,
"Exiting due to fatal error");
432 "%d variation(s) on previous %d message(s) suppressed by --mute",
448 msg(
M_FATAL,
"Assertion failed at %s:%d (%s)", filename, line, condition);
452 msg(
M_FATAL,
"Assertion failed at %s:%d", filename, line);
471 #if SYSLOG_CAPABILITY
477 openlog(pgmname_syslog, LOG_PID, LOG_OPENVPN);
488 msg(
M_WARN,
"Warning on use of --daemon: this operating system lacks daemon logging features, therefore when I become a daemon, I won't be able to log status or error messages");
495 #if SYSLOG_CAPABILITY
500 free(pgmname_syslog);
501 pgmname_syslog = NULL;
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);
560 msg(
M_WARN |
M_ERRNO,
"Warning: cannot duplicate stderr, password prompts will appear in log file instead of console.");
565 log_fd = _open_osfhandle((intptr_t)log_handle, _O_TEXT);
568 msg(
M_ERR,
"Error: --log redirect failed due to _open_osfhandle failure");
573 msgfp = _fdopen(log_fd,
"wt");
576 msg(
M_ERR,
"Error: --log redirect failed due to _fdopen");
580 if (_dup2(log_fd, 1) == -1 || _dup2(log_fd, 2) == -1)
582 msg(
M_WARN,
"Error: --log redirect of stdout/stderr failed");
587 #elif defined(HAVE_DUP2)
591 O_CREAT | O_WRONLY | (append ? O_APPEND : O_TRUNC),
596 msg(
M_WARN|
M_ERRNO,
"Warning: Error redirecting stdout/stderr to --log file: %s", file);
600 if (dup2(out, 1) == -1)
602 msg(
M_ERR,
"--log file redirection error on stdout");
604 if (dup2(out, 2) == -1)
606 msg(
M_ERR,
"--log file redirection error on stderr");
618 msg(
M_WARN,
"WARNING: The --log option is not supported on this OS because it lacks the dup2 function");
655 const char *description,
659 const char *extended_msg = NULL;
661 bool crt_error =
false;
672 #if EXTENDED_SOCKET_ERROR_CAPABILITY
677 extended_msg = format_extended_socket_error(sock->
sd, &mtu, &gc);
678 if (mtu > 0 && sock->
mtu != mtu)
701 sock ? sock->
sd : -1, my_errno);
708 sock ? sock->
sd : -1, my_errno);
757 port_share_abort(port_share);
761 #ifdef ENABLE_MEMSTATS
765 #ifdef ABORT_ON_ERROR
828 case ERROR_GEN_FAILURE:
829 return "General failure (ERROR_GEN_FAILURE)";
831 case ERROR_IO_PENDING:
832 return "I/O Operation in progress (ERROR_IO_PENDING)";
834 case WSA_IO_INCOMPLETE:
835 return "I/O Operation in progress (WSA_IO_INCOMPLETE)";
838 return "Interrupted system call (WSAEINTR)";
841 return "Bad file number (WSAEBADF)";
844 return "Permission denied (WSAEACCES)";
847 return "Bad address (WSAEFAULT)";
850 return "Invalid argument (WSAEINVAL)";
853 return "Too many open files (WSAEMFILE)";
856 return "Operation would block (WSAEWOULDBLOCK)";
859 return "Operation now in progress (WSAEINPROGRESS)";
862 return "Operation already in progress (WSAEALREADY)";
864 case WSAEDESTADDRREQ:
865 return "Destination address required (WSAEDESTADDRREQ)";
868 return "Message too long (WSAEMSGSIZE)";
871 return "Protocol wrong type for socket (WSAEPROTOTYPE)";
874 return "Bad protocol option (WSAENOPROTOOPT)";
876 case WSAEPROTONOSUPPORT:
877 return "Protocol not supported (WSAEPROTONOSUPPORT)";
879 case WSAESOCKTNOSUPPORT:
880 return "Socket type not supported (WSAESOCKTNOSUPPORT)";
883 return "Operation not supported on socket (WSAEOPNOTSUPP)";
885 case WSAEPFNOSUPPORT:
886 return "Protocol family not supported (WSAEPFNOSUPPORT)";
888 case WSAEAFNOSUPPORT:
889 return "Address family not supported by protocol family (WSAEAFNOSUPPORT)";
892 return "Address already in use (WSAEADDRINUSE)";
895 return "Network is down (WSAENETDOWN)";
898 return "Network is unreachable (WSAENETUNREACH)";
901 return "Net dropped connection or reset (WSAENETRESET)";
903 case WSAECONNABORTED:
904 return "Software caused connection abort (WSAECONNABORTED)";
907 return "Connection reset by peer (WSAECONNRESET)";
910 return "No buffer space available (WSAENOBUFS)";
913 return "Socket is already connected (WSAEISCONN)";
916 return "Socket is not connected (WSAENOTCONN)";
919 return "Connection timed out (WSAETIMEDOUT)";
921 case WSAECONNREFUSED:
922 return "Connection refused (WSAECONNREFUSED)";
925 return "Too many levels of symbolic links (WSAELOOP)";
927 case WSAENAMETOOLONG:
928 return "File name too long (WSAENAMETOOLONG)";
931 return "Host is down (WSAEHOSTDOWN)";
933 case WSAEHOSTUNREACH:
934 return "No Route to Host (WSAEHOSTUNREACH)";
937 return "Directory not empty (WSAENOTEMPTY)";
940 return "Too many processes (WSAEPROCLIM)";
943 return "Too many users (WSAEUSERS)";
946 return "Disc Quota Exceeded (WSAEDQUOT)";
949 return "Stale NFS file handle (WSAESTALE)";
952 return "Network SubSystem is unavailable (WSASYSNOTREADY)";
954 case WSAVERNOTSUPPORTED:
955 return "WINSOCK DLL Version out of range (WSAVERNOTSUPPORTED)";
957 case WSANOTINITIALISED:
958 return "Successful WSASTARTUP not yet performed (WSANOTINITIALISED)";
961 return "Too many levels of remote in path (WSAEREMOTE)";
963 case WSAHOST_NOT_FOUND:
964 return "Host not found (WSAHOST_NOT_FOUND)";
975 const int status = FormatMessage(
976 FORMAT_MESSAGE_IGNORE_INSERTS
977 | FORMAT_MESSAGE_FROM_SYSTEM
978 | FORMAT_MESSAGE_ARGUMENT_ARRAY,
992 for (cp = message; *cp !=
'\0'; ++cp)
994 if (*cp ==
'\n' || *cp ==
'\r')
void x_msg(const unsigned int flags, const char *format,...)
static bool msg_test(unsigned int flags)
Return true if flags represent an enabled, not muted log level.
static struct gc_arena gc_new(void)
const char * strerror_win32(DWORD errnum, struct gc_arena *gc)
#define DEBUG_LEVEL_USEC_TIME
const struct virtual_output * x_msg_virtual_output
void x_msg_va(const unsigned int flags, const char *format, va_list arglist)
const char * proto2ascii(int proto, sa_family_t af, bool display_form)
#define OPENVPN_EXIT_STATUS_GOOD
bool dont_mute(unsigned int flags)
Check muting filter.
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
static void perf_output_results(void)
bool set_debug_level(const int level, const unsigned int flags)
const char * x_msg_prefix
#define OPENVPN_DEBUG_FILE
void set_check_status(unsigned int info_level, unsigned int verbose_level)
unsigned int x_debug_level
const char * tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
static FILE * default_out
unsigned int x_cs_err_delay_ms
void reset_check_status(void)
static bool tuntap_defined(const struct tuntap *tt)
char * string_alloc(const char *str, struct gc_arena *gc)
unsigned int x_cs_info_level
void set_machine_readable_output(bool parsable)
void set_suppress_timestamps(bool suppressed)
static bool ignore_sys_error(const int err, bool crt_error)
int get_mute_cutoff(void)
#define DECODE_MUTE_LEVEL(flags)
static void virtual_output_print(const struct virtual_output *vo, const unsigned int flags, const char *str)
int get_debug_level(void)
WCHAR * wide_string(const char *utf8, struct gc_arena *gc)
FILE * msg_fp(const unsigned int flags)
static const char * msg_get_prefix(void)
unsigned int x_cs_verbose_level
void open_syslog(const char *pgmname, bool stdio_to_null)
Wrapper structure for dynamically allocated memory.
void errors_to_stderr(void)
#define OPENVPN_EXIT_STATUS_ERROR
void openvpn_exit(const int status)
bool set_mute_cutoff(const int cutoff)
struct link_socket_info info
static bool suppress_timestamps
void assert_failed(const char *filename, int line, const char *condition)
Garbage collection arena used to keep track of dynamically allocated memory.
void x_check_status(int status, const char *description, struct link_socket *sock, struct tuntap *tt)
static int openvpn_errno_maybe_crt(bool *crt_error)
const char * msg_flags_string(const unsigned int flags, struct gc_arena *gc)
static bool check_debug_level(unsigned int level)
static bool machine_readable_output
static const struct virtual_output * msg_get_virtual_output(void)
void redirect_stdout_stderr(const char *file, bool append)
void set_std_files_to_null(bool stdin_only)
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
bool openvpn_snprintf(char *str, size_t size, const char *format,...)
static SERVICE_STATUS status
static void gc_free(struct gc_arena *a)
static const char * openvpn_strerror(int err, bool crt_error, struct gc_arena *gc)
const char * time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc)
static void gc_init(struct gc_arena *a)
static FILE * default_err
#define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE
static int constrain_int(int x, int min, int max)
void remove_pid_file(void)
bool buf_printf(struct buffer *buf, const char *format,...)