Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/close.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ LIBC_CLOSE_RET_TYPE tsocks_close(LIBC_CLOSE_SIG)
LIBC_CLOSE_DECL
{
if (!tsocks_libc_close) {
tsocks_initialize();
tsocks_initialize_libc_symbols();
}
return tsocks_close(LIBC_CLOSE_ARGS);
}
13 changes: 12 additions & 1 deletion src/lib/torsocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ struct configuration tsocks_config;
*/
struct onion_pool tsocks_onion_pool;

/* Indicate if libc symbols were initialized previously. */
static TSOCKS_INIT_ONCE(init_libc_symbols_once);

/* Indicate if the library was initialized previously. */
static TSOCKS_INIT_ONCE(init_once);

Expand Down Expand Up @@ -321,7 +324,7 @@ static void tsocks_init(void)
* We need to save libc symbols *before* we override them so torsocks can
* use the original libc calls.
*/
init_libc_symbols();
tsocks_once(&init_libc_symbols_once, &init_libc_symbols);

/*
* Read configuration file and set the global config.
Expand Down Expand Up @@ -695,6 +698,14 @@ void *tsocks_find_libc_symbol(const char *symbol,
return fct_ptr;
}

/*
* Initialize libc symbols.
*/
void __attribute__((constructor)) tsocks_initialize_libc_symbols(void)
{
tsocks_once(&init_libc_symbols_once, &init_libc_symbols);
}

/*
* Initialize torsocks library.
*/
Expand Down