mirror of
https://github.com/rofl0r/proxychains-ng.git
synced 2024-12-22 12:18:47 +00:00
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.
This commit is contained in:
parent
bd07ca49b9
commit
03ee84060e
2
Makefile
2
Makefile
@ -17,7 +17,7 @@ SRCS = $(sort $(wildcard src/*.c))
|
|||||||
OBJS = $(SRCS:.c=.o)
|
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
|
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
|
LDFLAGS = -shared -fPIC -Wl,--no-as-needed -ldl -lpthread
|
||||||
INC =
|
INC =
|
||||||
PIC = -fPIC
|
PIC = -fPIC
|
||||||
|
12
src/core.c
12
src/core.c
@ -34,10 +34,8 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#ifdef THREAD_SAFE
|
#include "mutex.h"
|
||||||
#include <pthread.h>
|
|
||||||
pthread_mutex_t hostdb_lock;
|
pthread_mutex_t hostdb_lock;
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -692,6 +690,14 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
return -1;
|
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) {
|
static void gethostbyname_data_setstring(struct gethostbyname_data* data, char* name) {
|
||||||
snprintf(data->addr_name, sizeof(data->addr_name), "%s", name);
|
snprintf(data->addr_name, sizeof(data->addr_name), "%s", name);
|
||||||
data->hostent_space.h_name = data->addr_name;
|
data->hostent_space.h_name = data->addr_name;
|
||||||
|
@ -28,11 +28,6 @@
|
|||||||
|
|
||||||
#include "ip_type.h"
|
#include "ip_type.h"
|
||||||
|
|
||||||
#ifdef THREAD_SAFE
|
|
||||||
#include "mutex.h"
|
|
||||||
extern pthread_mutex_t hostdb_lock;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*error codes*/
|
/*error codes*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SUCCESS=0,
|
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 pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes);
|
||||||
|
|
||||||
|
void core_initialize(void);
|
||||||
|
void core_unload(void);
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
@ -64,9 +65,8 @@ localaddr_arg localnet_addr[MAX_LOCALNET];
|
|||||||
size_t num_localnet_addr = 0;
|
size_t num_localnet_addr = 0;
|
||||||
unsigned int remote_dns_subnet = 224;
|
unsigned int remote_dns_subnet = 224;
|
||||||
|
|
||||||
#ifdef THREAD_SAFE
|
|
||||||
pthread_once_t init_once = PTHREAD_ONCE_INIT;
|
pthread_once_t init_once = PTHREAD_ONCE_INIT;
|
||||||
#endif
|
|
||||||
static int init_l = 0;
|
static int init_l = 0;
|
||||||
|
|
||||||
static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
|
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) {
|
static void do_init(void) {
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
MUTEX_INIT(&hostdb_lock);
|
core_initialize();
|
||||||
at_init();
|
at_init();
|
||||||
|
|
||||||
/* read the config file */
|
/* read the config file */
|
||||||
@ -115,18 +115,23 @@ static void do_init(void) {
|
|||||||
init_l = 1;
|
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) {
|
static void init_lib_wrapper(const char* caller) {
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
(void) caller;
|
(void) caller;
|
||||||
#endif
|
#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);
|
if(!init_l) PDEBUG("%s called from %s\n", __FUNCTION__, caller);
|
||||||
pthread_once(&init_once, do_init);
|
pthread_once(&init_once, do_init);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we use gcc >= 3, we can instruct the dynamic loader
|
/* if we use gcc >= 3, we can instruct the dynamic loader
|
||||||
|
Loading…
Reference in New Issue
Block a user