Avoid sleep on service thread sync
Some checks failed
C/C++ CI / ${{ matrix.target }} (macos-15) (push) Has been cancelled
C/C++ CI / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Has been cancelled
C/C++ CI / ${{ matrix.target }} (ubuntu-latest) (push) Has been cancelled
C/C++ CI / ${{ matrix.target }} (windows-2022) (push) Has been cancelled

This commit is contained in:
Vladimir Dubrovin 2025-04-16 21:29:48 +03:00
parent 7320094c11
commit 57841074b9
5 changed files with 37 additions and 7 deletions

View File

@ -521,6 +521,14 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
#ifndef NORADIUS
pthread_mutex_init(&rad_mutex, NULL);
#endif
#ifdef _WIN32
if(!CreatePipe(&conf.threadinit[0], &conf.threadinit[1], NULL, 1)){
#else
if(pipe(conf.threadinit)) {
#endif
fprintf(stderr, "CreatePipe failed\n");
return 1;
};
freeconf(&conf);
res = readconfig(fp);

View File

@ -93,6 +93,7 @@ char *rotations[] = {
struct extparam conf = {
{0, 0},
{1, 5, 30, 60, 180, 1800, 15, 60, 15, 5, 0, 0},
NULL,
NULL,
@ -101,7 +102,7 @@ struct extparam conf = {
NULL,
NULL,
0,
0, -1, 0, 0, 0, 0,
-1, 0, 0, 0, 0,
0, 500, 0, 0, 0, 0, 0, 0, 2,
0, 0, 0,
6, 600,

View File

@ -150,8 +150,8 @@ int start_proxy_thread(struct child * chp){
#ifdef _WIN32
HANDLE h;
#endif
char r[1];
conf.threadinit = 1;
#ifdef _WIN32
#ifndef _WINCE
h = (HANDLE)_beginthreadex((LPSECURITY_ATTRIBUTES )NULL, 16384+conf.stacksize, (void *)startsrv, (void *) chp, (DWORD)0, &thread);
@ -166,7 +166,14 @@ int start_proxy_thread(struct child * chp){
pthread_create(&thread, &pa, startsrv, (void *)chp);
pthread_attr_destroy(&pa);
#endif
while(conf.threadinit)usleep(SLEEPTIME);
#ifdef _WIN32
ReadFile(conf.threadinit[0], r, 1, NULL, NULL);
#else
while(read(conf.threadinit[0], r, 1) !=1) if(errno != EINTR) {
fprintf(stderr, "pipe failed\n");
return 40;
}
#endif
if(haveerror) {
fprintf(stderr, "Service not started on line: %d%s\n", linenum, haveerror == 2? ": insufficient memory":"");
return(40);

View File

@ -115,6 +115,15 @@ void * threadfunc (void *p) {
}
#undef param
int pushthreadinit(){
return
#ifdef _WIN32
WriteFile(conf.threadinit[1], "1", 1, NULL, NULL);
#else
write(conf.threadinit[1], "1", 1);
#endif
}
struct socketoptions sockopts[] = {
#ifdef TCP_NODELAY
@ -526,7 +535,7 @@ int MODULEMAINFUNC (int argc, char** argv){
if (error || i!=argc) {
#ifndef STDMAIN
haveerror = 1;
conf.threadinit = 0;
pushthreadinit();
#endif
fprintf(stderr, "%s of %s\n"
"Usage: %s options\n"
@ -558,7 +567,7 @@ int MODULEMAINFUNC (int argc, char** argv){
if (error || argc != i+3 || *argv[i]=='-'|| (*SAPORT(&srv.intsa) = htons((unsigned short)atoi(argv[i])))==0 || (srv.targetport = htons((unsigned short)atoi(argv[i+2])))==0) {
#ifndef STDMAIN
haveerror = 1;
conf.threadinit = 0;
pushthreadinit();
#endif
fprintf(stderr, "%s of %s\n"
"Usage: %s options"
@ -624,7 +633,7 @@ int MODULEMAINFUNC (int argc, char** argv){
#ifndef STDMAIN
copyfilter(conf.filters, &srv);
conf.threadinit = 0;
pushthreadinit();
#endif

View File

@ -632,6 +632,11 @@ struct filemon {
struct extparam {
#ifdef _WIN32
HANDLE threadinit[2];
#else
int threadinit[2];
#endif
int timeouts[12];
struct ace * acl;
char * conffile;
@ -640,7 +645,7 @@ struct extparam {
struct trafcount * trafcounter;
struct srvparam *services;
int stacksize,
threadinit, counterd, haveerror, rotate, paused, archiverc,
counterd, haveerror, rotate, paused, archiverc,
demon, maxchild, backlog, needreload, timetoexit, version, noforce, bandlimver, parentretries;
int authcachetype, authcachetime;
int filtermaxsize;