remove THREAD_SAFE ifdefs. from now on, pthreads are required.
additionally we have some explicit init and deinit routines for core.c now, so that we dont need to share variables with libproxychains.c.pull/18/head
parent
bd07ca49b9
commit
03ee84060e
2
Makefile
2
Makefile
|
@ -17,7 +17,7 @@ SRCS = $(sort $(wildcard src/*.c))
|
|||
OBJS = $(SRCS:.c=.o)
|
||||
LOBJS = src/core.o src/common.o src/libproxychains.o src/shm.o src/allocator_thread.o src/ip_type.o
|
||||
|
||||
CFLAGS += -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE
|
||||
CFLAGS += -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe
|
||||
LDFLAGS = -shared -fPIC -Wl,--no-as-needed -ldl -lpthread
|
||||
INC =
|
||||
PIC = -fPIC
|
||||
|
|
12
src/core.c
12
src/core.c
|
@ -34,10 +34,8 @@
|
|||
#include <sys/time.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
#ifdef THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "mutex.h"
|
||||
pthread_mutex_t hostdb_lock;
|
||||
#endif
|
||||
|
||||
#include "core.h"
|
||||
#include "common.h"
|
||||
|
@ -692,6 +690,14 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||
return -1;
|
||||
}
|
||||
|
||||
void core_initialize(void) {
|
||||
MUTEX_INIT(&hostdb_lock);
|
||||
}
|
||||
|
||||
void core_unload(void) {
|
||||
MUTEX_DESTROY(&hostdb_lock);
|
||||
}
|
||||
|
||||
static void gethostbyname_data_setstring(struct gethostbyname_data* data, char* name) {
|
||||
snprintf(data->addr_name, sizeof(data->addr_name), "%s", name);
|
||||
data->hostent_space.h_name = data->addr_name;
|
||||
|
|
|
@ -28,11 +28,6 @@
|
|||
|
||||
#include "ip_type.h"
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
#include "mutex.h"
|
||||
extern pthread_mutex_t hostdb_lock;
|
||||
#endif
|
||||
|
||||
/*error codes*/
|
||||
typedef enum {
|
||||
SUCCESS=0,
|
||||
|
@ -121,6 +116,9 @@ void proxy_freeaddrinfo(struct addrinfo *res);
|
|||
|
||||
void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes);
|
||||
|
||||
void core_initialize(void);
|
||||
void core_unload(void);
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
#include "core.h"
|
||||
|
@ -64,9 +65,8 @@ localaddr_arg localnet_addr[MAX_LOCALNET];
|
|||
size_t num_localnet_addr = 0;
|
||||
unsigned int remote_dns_subnet = 224;
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
pthread_once_t init_once = PTHREAD_ONCE_INIT;
|
||||
#endif
|
||||
|
||||
static int init_l = 0;
|
||||
|
||||
static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
|
||||
|
@ -97,7 +97,7 @@ static void* load_sym(char* symname, void* proxyfunc) {
|
|||
|
||||
static void do_init(void) {
|
||||
srand(time(NULL));
|
||||
MUTEX_INIT(&hostdb_lock);
|
||||
core_initialize();
|
||||
at_init();
|
||||
|
||||
/* read the config file */
|
||||
|
@ -115,18 +115,23 @@ static void do_init(void) {
|
|||
init_l = 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* FIXME this is currently unused.
|
||||
* it is not strictly needed.
|
||||
* maybe let it be called by a gcc destructor, if that doesnt
|
||||
* have negative consequences (e.g. when a child calles exit) */
|
||||
static void unload(void) {
|
||||
at_close();
|
||||
core_unload();
|
||||
}
|
||||
#endif
|
||||
|
||||
static void init_lib_wrapper(const char* caller) {
|
||||
#ifndef DEBUG
|
||||
(void) caller;
|
||||
#endif
|
||||
#ifndef THREAD_SAFE
|
||||
if(init_l) return;
|
||||
PDEBUG("%s called from %s\n", __FUNCTION__, caller);
|
||||
do_init();
|
||||
#else
|
||||
if(!init_l) PDEBUG("%s called from %s\n", __FUNCTION__, caller);
|
||||
pthread_once(&init_once, do_init);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* if we use gcc >= 3, we can instruct the dynamic loader
|
||||
|
|
Loading…
Reference in New Issue