Macros | Functions
torerr.h File Reference
#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_sigsafe_err_set_granularity (int ms)
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); \
abort(); \
} \

Definition at line 20 of file torerr.h.

◆ raw_assert_unreached_msg

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

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.

Referenced by tor_log_set_sigsafe_err_fds(), and tor_log_update_sigsafe_err_fds().

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 245 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, format_helper_exit_status() will still need to emit any require '-' on its own.

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 238 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.

References format_dec_number_sigsafe(), log_granularity, and tor_log_err_sigsafe_write().

Referenced by tor_raw_assertion_failed_msg_().

◆ 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.

References n_sigsafe_log_fds, and sigsafe_log_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 129 of file torerr.c.

References tor_log_set_sigsafe_err_fds().

◆ 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.

Definition at line 115 of file torerr.c.

References n_sigsafe_log_fds, sigsafe_log_fds, and TOR_SIGSAFE_LOG_MAX_FDS.

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 140 of file torerr.c.

References log_granularity.

Referenced by set_log_time_granularity().

◆ 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 152 of file torerr.c.

References format_dec_number_sigsafe(), tor_log_err_sigsafe(), and tor_log_err_sigsafe_write().