Macros | Functions
torerr.h File Reference

Headers for torerr.c. More...

#include "lib/cc/compat_compiler.h"

Go to the source code of this file.


#define raw_assert(expr)
#define raw_assert_unreached(expr)   raw_assert(0)
#define raw_assert_unreached_msg(msg)


void tor_raw_assertion_failed_msg_ (const char *file, int line, const char *expr, const char *msg)
void tor_log_err_sigsafe (const char *m,...)
int tor_log_get_sigsafe_err_fds (const int **out)
void tor_log_set_sigsafe_err_fds (const int *fds, int n)
void tor_log_reset_sigsafe_err_fds (void)
void tor_log_flush_sigsafe_err_fds (void)
void tor_log_sigsafe_err_set_granularity (int ms)
void tor_raw_abort_ (void) ATTR_NORETURN
int format_hex_number_sigsafe (unsigned long x, char *buf, int max_len)
int format_dec_number_sigsafe (unsigned long x, char *buf, int max_len)

Detailed Description

Headers for torerr.c.

Definition in file torerr.h.

Macro Definition Documentation

◆ raw_assert

#define raw_assert (   expr)
if (!(expr)) { \
tor_raw_assertion_failed_msg_(__FILE__, __LINE__, #expr, NULL); \
tor_raw_abort_(); \
} \

Definition at line 20 of file torerr.h.

◆ raw_assert_unreached

#define raw_assert_unreached (   expr)    raw_assert(0)

Definition at line 26 of file torerr.h.

◆ raw_assert_unreached_msg

#define raw_assert_unreached_msg (   msg)
tor_raw_assertion_failed_msg_(__FILE__, __LINE__, "0", (msg)); \
tor_raw_abort_(); \
void tor_raw_assertion_failed_msg_(const char *file, int line, const char *expr, const char *msg)
Definition: torerr.c:194

Definition at line 27 of file torerr.h.



Maximum number of fds that will get notifications if we crash

Definition at line 37 of file torerr.h.

Function Documentation

◆ format_dec_number_sigsafe()

int format_dec_number_sigsafe ( unsigned long  x,
char *  buf,
int  buf_len 

As format_hex_number_sigsafe, but format the number in base 10.

Definition at line 305 of file torerr.c.

Referenced by tor_log_err_sigsafe(), and tor_raw_assertion_failed_msg_().

◆ format_hex_number_sigsafe()

int format_hex_number_sigsafe ( unsigned long  x,
char *  buf,
int  buf_len 

Helper function to output hex numbers from within a signal handler.

Writes the nul-terminated hexadecimal digits of x into a buffer buf of size buf_len, and return the actual number of digits written, not counting the terminal NUL.

If there is insufficient space, write nothing and return 0.

This accepts an unsigned int because format_helper_exit_status() needs to call it with a signed int and an unsigned char, and since the C standard does not guarantee that an int is wider than a char (an int must be at least 16 bits but it is permitted for a char to be that wide as well), we can't assume a signed int is sufficient to accommodate an unsigned char. Thus, callers will still need to add any required '-' to the final string.

For most purposes, you'd want to use tor_snprintf("%x") instead of this function; it's designed to be used in code paths where you can't call arbitrary C functions.

Definition at line 298 of file torerr.c.

◆ tor_log_err_sigsafe()

void tor_log_err_sigsafe ( const char *  m,

Given a list of string arguments ending with a NULL, writes them to our logs and to stderr (if possible). This function is safe to call from within a signal handler.

Definition at line 70 of file torerr.c.

Referenced by nodump_mem(), noinherit_mem(), string_is_utf8(), and tor_raw_assertion_failed_msg_().

◆ tor_log_flush_sigsafe_err_fds()

void tor_log_flush_sigsafe_err_fds ( void  )

Flush the list of fds that get errors from inside a signal handler or other emergency condition. These fds are shared with the logging code: flushing them also flushes the log buffers.

This function is safe to call during signal handlers.

Definition at line 161 of file torerr.c.

Referenced by tor_raw_abort_().

◆ tor_log_get_sigsafe_err_fds()

int tor_log_get_sigsafe_err_fds ( const int **  out)

Set *out to a pointer to an array of the fds to log errors to from inside a signal handler or other emergency condition. Return the number of elements in the array.

Definition at line 103 of file torerr.c.

Referenced by tor_log_flush_sigsafe_err_fds().

◆ tor_log_reset_sigsafe_err_fds()

void tor_log_reset_sigsafe_err_fds ( void  )

Reset the list of emergency error fds to its default.

Definition at line 147 of file torerr.c.

◆ tor_log_set_sigsafe_err_fds()

void tor_log_set_sigsafe_err_fds ( const int *  fds,
int  n 

Update the list of fds that get errors from inside a signal handler or other emergency condition. Ignore any beyond the first TOR_SIGSAFE_LOG_MAX_FDS.

These fds must remain open even after the log module has shut down. (And they should remain open even while logs are being reconfigured.) Therefore, any fds closed by the log module should be dup()ed, and the duplicate fd should be given to the err module in fds. In particular, the log module closes the file log fds, but does not close the stdio log fds.

If fds is NULL or n is 0, clears the list of error fds.

Definition at line 123 of file torerr.c.

Referenced by tor_log_reset_sigsafe_err_fds().

◆ tor_log_sigsafe_err_set_granularity()

void tor_log_sigsafe_err_set_granularity ( int  ms)

Set the granularity (in ms) to use when reporting fatal errors outside the logging system.

Definition at line 182 of file torerr.c.

Referenced by set_log_time_granularity().

◆ tor_raw_abort_()

void tor_raw_abort_ ( void  )

Call the abort() function to kill the current process with a fatal error. But first, flush the raw error file descriptors, so error messages are written before process termination.

Definition at line 222 of file torerr.c.

Referenced by tor_abort_().

◆ tor_raw_assertion_failed_msg_()

void tor_raw_assertion_failed_msg_ ( const char *  file,
int  line,
const char *  expr,
const char *  msg 

Log an emergency assertion failure message.

This kind of message is safe to send from within a log handler, a signal handler, or other emergency situation.

Definition at line 194 of file torerr.c.