Go to the documentation of this file.
47 #define LOG_OPENVPN LOG_DAEMON
85 static char *pgmname_syslog;
107 const int ceiling = 15;
109 if (level >= 0 && level <= ceiling)
173 #ifdef OPENVPN_DEBUG_COMMAND_LINE
208 #define SWAP { tmp = m1; m1 = m2; m2 = tmp; }
213 x_msg(
const unsigned int flags,
const char *format, ...)
216 va_start(arglist, format);
230 return strerror(err);
234 x_msg_va(
const unsigned int flags,
const char *format, va_list arglist)
237 #if SYSLOG_CAPABILITY
245 const char *prefix_sep;
255 bool crt_error =
false;
288 #if SYSLOG_CAPABILITY
315 prefix_sep = prefix =
"";
336 #if SYSLOG_CAPABILITY
337 syslog(level,
"%s%s%s",
351 gettimeofday(&tv, NULL);
353 fprintf(fp,
"%" PRIi64
".%06ld %x %s%s%s%s",
365 fprintf(fp,
"%s%s%s%s",
369 (flags&
M_NOLF) ?
"" :
"\n");
373 fprintf(fp,
"%s %s%s%s%s",
378 (flags&
M_NOLF) ?
"" :
"\n");
387 msg(
M_INFO,
"Exiting due to fatal error");
430 "%d variation(s) on previous %d message(s) suppressed by --mute",
446 msg(
M_FATAL,
"Assertion failed at %s:%d (%s)", filename, line, condition);
450 msg(
M_FATAL,
"Assertion failed at %s:%d", filename, line);
469 #if SYSLOG_CAPABILITY
475 openlog(pgmname_syslog, LOG_PID, LOG_OPENVPN);
486 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");
493 #if SYSLOG_CAPABILITY
498 free(pgmname_syslog);
499 pgmname_syslog = NULL;
524 SECURITY_ATTRIBUTES saAttr;
525 saAttr.nLength =
sizeof(SECURITY_ATTRIBUTES);
526 saAttr.bInheritHandle = TRUE;
527 saAttr.lpSecurityDescriptor = NULL;
533 append ? OPEN_ALWAYS : CREATE_ALWAYS,
534 FILE_ATTRIBUTE_NORMAL,
539 if (log_handle == INVALID_HANDLE_VALUE)
548 if (SetFilePointer(log_handle, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
550 msg(
M_ERR,
"Error: cannot seek to end of --log file: %s", file);
558 msg(
M_WARN |
M_ERRNO,
"Warning: cannot duplicate stderr, password prompts will appear in log file instead of console.");
563 log_fd = _open_osfhandle((intptr_t)log_handle, _O_TEXT);
566 msg(
M_ERR,
"Error: --log redirect failed due to _open_osfhandle failure");
571 msgfp = _fdopen(log_fd,
"wt");
574 msg(
M_ERR,
"Error: --log redirect failed due to _fdopen");
578 if (_dup2(log_fd, 1) == -1 || _dup2(log_fd, 2) == -1)
580 msg(
M_WARN,
"Error: --log redirect of stdout/stderr failed");
585 #elif defined(HAVE_DUP2)
589 O_CREAT | O_WRONLY | (append ? O_APPEND : O_TRUNC),
594 msg(
M_WARN|
M_ERRNO,
"Warning: Error redirecting stdout/stderr to --log file: %s", file);
598 if (dup2(out, 1) == -1)
600 msg(
M_ERR,
"--log file redirection error on stdout");
602 if (dup2(out, 2) == -1)
604 msg(
M_ERR,
"--log file redirection error on stderr");
616 msg(
M_WARN,
"WARNING: The --log option is not supported on this OS because it lacks the dup2 function");
653 const char *description,
657 const char *extended_msg = NULL;
659 bool crt_error =
false;
670 #if EXTENDED_SOCKET_ERROR_CAPABILITY
675 extended_msg = format_extended_socket_error(sock->
sd, &mtu, &gc);
676 if (mtu > 0 && sock->
mtu != mtu)
699 sock ? sock->
sd : -1, my_errno);
706 sock ? sock->
sd : -1, my_errno);
755 port_share_abort(port_share);
759 #ifdef ENABLE_MEMSTATS
763 #ifdef ABORT_ON_ERROR
826 case ERROR_GEN_FAILURE:
827 return "General failure (ERROR_GEN_FAILURE)";
829 case ERROR_IO_PENDING:
830 return "I/O Operation in progress (ERROR_IO_PENDING)";
832 case WSA_IO_INCOMPLETE:
833 return "I/O Operation in progress (WSA_IO_INCOMPLETE)";
836 return "Interrupted system call (WSAEINTR)";
839 return "Bad file number (WSAEBADF)";
842 return "Permission denied (WSAEACCES)";
845 return "Bad address (WSAEFAULT)";
848 return "Invalid argument (WSAEINVAL)";
851 return "Too many open files (WSAEMFILE)";
854 return "Operation would block (WSAEWOULDBLOCK)";
857 return "Operation now in progress (WSAEINPROGRESS)";
860 return "Operation already in progress (WSAEALREADY)";
862 case WSAEDESTADDRREQ:
863 return "Destination address required (WSAEDESTADDRREQ)";
866 return "Message too long (WSAEMSGSIZE)";
869 return "Protocol wrong type for socket (WSAEPROTOTYPE)";
872 return "Bad protocol option (WSAENOPROTOOPT)";
874 case WSAEPROTONOSUPPORT:
875 return "Protocol not supported (WSAEPROTONOSUPPORT)";
877 case WSAESOCKTNOSUPPORT:
878 return "Socket type not supported (WSAESOCKTNOSUPPORT)";
881 return "Operation not supported on socket (WSAEOPNOTSUPP)";
883 case WSAEPFNOSUPPORT:
884 return "Protocol family not supported (WSAEPFNOSUPPORT)";
886 case WSAEAFNOSUPPORT:
887 return "Address family not supported by protocol family (WSAEAFNOSUPPORT)";
890 return "Address already in use (WSAEADDRINUSE)";
893 return "Network is down (WSAENETDOWN)";
896 return "Network is unreachable (WSAENETUNREACH)";
899 return "Net dropped connection or reset (WSAENETRESET)";
901 case WSAECONNABORTED:
902 return "Software caused connection abort (WSAECONNABORTED)";
905 return "Connection reset by peer (WSAECONNRESET)";
908 return "No buffer space available (WSAENOBUFS)";
911 return "Socket is already connected (WSAEISCONN)";
914 return "Socket is not connected (WSAENOTCONN)";
917 return "Connection timed out (WSAETIMEDOUT)";
919 case WSAECONNREFUSED:
920 return "Connection refused (WSAECONNREFUSED)";
923 return "Too many levels of symbolic links (WSAELOOP)";
925 case WSAENAMETOOLONG:
926 return "File name too long (WSAENAMETOOLONG)";
929 return "Host is down (WSAEHOSTDOWN)";
931 case WSAEHOSTUNREACH:
932 return "No Route to Host (WSAEHOSTUNREACH)";
935 return "Directory not empty (WSAENOTEMPTY)";
938 return "Too many processes (WSAEPROCLIM)";
941 return "Too many users (WSAEUSERS)";
944 return "Disc Quota Exceeded (WSAEDQUOT)";
947 return "Stale NFS file handle (WSAESTALE)";
950 return "Network SubSystem is unavailable (WSASYSNOTREADY)";
952 case WSAVERNOTSUPPORTED:
953 return "WINSOCK DLL Version out of range (WSAVERNOTSUPPORTED)";
955 case WSANOTINITIALISED:
956 return "Successful WSASTARTUP not yet performed (WSANOTINITIALISED)";
959 return "Too many levels of remote in path (WSAEREMOTE)";
961 case WSAHOST_NOT_FOUND:
962 return "Host not found (WSAHOST_NOT_FOUND)";
971 wchar_t wmessage[256];
972 char *message = NULL;
974 const DWORD
status = FormatMessageW(
975 FORMAT_MESSAGE_IGNORE_INSERTS
976 | FORMAT_MESSAGE_FROM_SYSTEM
977 | FORMAT_MESSAGE_ARGUMENT_ARRAY,
995 for (cp = message; *cp !=
'\0'; ++cp)
997 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)
static SERVICE_STATUS status
static void gc_free(struct gc_arena *a)
char * utf16to8(const wchar_t *utf16, struct gc_arena *gc)
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,...)