mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
Reorganize service config parsing / main loop
This commit is contained in:
1 parent
eb11c617b7
commit
95fd3be6fa
6 files changed
+1040
-931
No files matched your search
+27
-24
@@ -42,13 +42,14 @@ int runningservices = 0;
|
||||
_3proxy_mutex_t runningservices_mutex;
|
||||
_3proxy_sem_t serviceexited;
|
||||
|
||||
int haveerror = 0;
|
||||
int linenum = 0;
|
||||
|
||||
struct counter_header cheader = {"3CF", (time_t)0};
|
||||
struct counter_record crecord;
|
||||
|
||||
int mainfunc (int argc, char** argv);
|
||||
int mainprepare(int argc, char** argv, void **service);
|
||||
int mainrun(void *service);
|
||||
void maindrop(void *service);
|
||||
|
||||
struct proxydef childdef = {NULL, 0, 0, S_NOSERVICE, ""};
|
||||
|
||||
@@ -78,15 +79,8 @@ DWORD WINAPI startsrv(LPVOID data) {
|
||||
#else
|
||||
void * startsrv(void * data) {
|
||||
#endif
|
||||
struct child *d = (struct child *)data;
|
||||
|
||||
/* counted here rather than where the service is listed, so every way
|
||||
out of it is counted too; start_proxy_thread() waits for the service
|
||||
to start, so it is counted by the time that returns */
|
||||
_3proxy_mutex_lock(&runningservices_mutex);
|
||||
runningservices++;
|
||||
_3proxy_mutex_unlock(&runningservices_mutex);
|
||||
mainfunc(d->argc, (char **)d->argv);
|
||||
/* counted by start_proxy_thread() before the thread is created */
|
||||
mainrun(data);
|
||||
_3proxy_mutex_lock(&runningservices_mutex);
|
||||
runningservices--;
|
||||
_3proxy_mutex_unlock(&runningservices_mutex);
|
||||
@@ -156,36 +150,45 @@ unsigned char * dologname (unsigned char *buf, unsigned char *name, const unsign
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* The service is set up here, in the thread reading the configuration, so
|
||||
an error in its options stops the configuration; its own thread then
|
||||
listens and serves. */
|
||||
int start_proxy_thread(struct child * chp){
|
||||
pthread_t thread;
|
||||
void *service;
|
||||
int res;
|
||||
#ifdef _WIN32
|
||||
HANDLE h;
|
||||
#endif
|
||||
|
||||
_3proxy_sem_lock(conf.threadinit);
|
||||
if((res = mainprepare(chp->argc, (char **)chp->argv, &service))) {
|
||||
fprintf(stderr, "Service not started on line: %d%s\n", linenum, res == 2? ": insufficient memory":"");
|
||||
return(40);
|
||||
}
|
||||
_3proxy_mutex_lock(&runningservices_mutex);
|
||||
runningservices++;
|
||||
_3proxy_mutex_unlock(&runningservices_mutex);
|
||||
#ifdef _WIN32
|
||||
#ifndef _WINCE
|
||||
h = (HANDLE)_beginthreadex((LPSECURITY_ATTRIBUTES )NULL, 16384+conf.stacksize, (void *)startsrv, (void *) chp, (DWORD)0, &thread);
|
||||
h = (HANDLE)_beginthreadex((LPSECURITY_ATTRIBUTES )NULL, 16384+conf.stacksize, (void *)startsrv, service, (DWORD)0, &thread);
|
||||
#else
|
||||
h = (HANDLE)CreateThread((LPSECURITY_ATTRIBUTES )NULL, 16384+conf.stacksize, (void *)startsrv, (void *) chp, (DWORD)0, &thread);
|
||||
h = (HANDLE)CreateThread((LPSECURITY_ATTRIBUTES )NULL, 16384+conf.stacksize, (void *)startsrv, service, (DWORD)0, &thread);
|
||||
#endif
|
||||
if(h)CloseHandle(h);
|
||||
else {
|
||||
#else
|
||||
pthread_attr_init(&pa);
|
||||
pthread_attr_setstacksize(&pa,threadstacksize(conf.stacksize));
|
||||
pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED);
|
||||
if(pthread_create(&thread, &pa, startsrv, (void *)chp)){
|
||||
pthread_attr_destroy(&pa);
|
||||
fprintf(stderr, "Failed to create service thread on line %d, try to set larger stacksize\n", linenum);
|
||||
_3proxy_sem_unlock(conf.threadinit);
|
||||
return(40);
|
||||
}
|
||||
res = pthread_create(&thread, &pa, startsrv, service);
|
||||
pthread_attr_destroy(&pa);
|
||||
if(res){
|
||||
#endif
|
||||
_3proxy_sem_lock(conf.threadinit);
|
||||
_3proxy_sem_unlock(conf.threadinit);
|
||||
if(haveerror) {
|
||||
fprintf(stderr, "Service not started on line: %d%s\n", linenum, haveerror == 2? ": insufficient memory":"");
|
||||
_3proxy_mutex_lock(&runningservices_mutex);
|
||||
runningservices--;
|
||||
_3proxy_mutex_unlock(&runningservices_mutex);
|
||||
maindrop(service);
|
||||
fprintf(stderr, "Failed to create service thread on line %d, try to set larger stacksize\n", linenum);
|
||||
return(40);
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user