Keep the clock, timetoexit and needreload out of conf

They are the state of the process, not configuration: conf.time (now
curtime), timetoexit and needreload are globals of their own. Plugins
reach needreload through a pointer added at the end of struct
pluginlink; LdapPlugin uses it. The extern for a paused global, never
defined, goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladimir Dubrovin 2026-10-13 16:05:33 +03:00
parent 3b2d664563
commit a2592f4038
15 changed files with 61 additions and 58 deletions

View File

@ -72,7 +72,7 @@ void __stdcall CommandHandler( DWORD dwCommand )
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
SetStatus( SERVICE_STOP_PENDING, 0, 1 );
conf.timetoexit = 1;
timetoexit = 1;
conf.paused++;
/* ServiceMain() reports the service stopped once cyclestep() has
seen this and the services are done */
@ -84,7 +84,7 @@ void __stdcall CommandHandler( DWORD dwCommand )
break;
case SERVICE_CONTROL_CONTINUE:
SetStatus( SERVICE_CONTINUE_PENDING, 0, 1 );
conf.needreload = 1;
needreload = 1;
SetStatus( SERVICE_RUNNING, 0, 0 );
break;
default: ;
@ -115,7 +115,7 @@ void __stdcall ServiceMain(int argc, unsigned char* argv[] )
void mysigusr1 (int sig){
conf.needreload = 1;
needreload = 1;
}
int even = 0;
@ -125,13 +125,13 @@ void mysigpause (int sig){
conf.paused++;
even = !even;
if(!even){
conf.needreload = 1;
needreload = 1;
}
}
void mysigterm (int sig){
conf.paused++;
conf.timetoexit = 1;
timetoexit = 1;
}
#endif
@ -183,10 +183,10 @@ void doschedule(void){
struct schedule *sched, *prevsched = NULL, *nextsched;
int res;
conf.time = time(0);
curtime = time(0);
for(sched=schedule; sched; sched=sched->next){
if(conf.needreload || conf.timetoexit || (conf.time > sched->start_time && timechanged(sched->start_time, conf.time, sched->type))){
sched->start_time = conf.time;
if(needreload || timetoexit || (curtime > sched->start_time && timechanged(sched->start_time, curtime, sched->type))){
sched->start_time = curtime;
nextsched = sched->next;
res = (*sched->function)(sched->data);
switch(res){
@ -206,8 +206,8 @@ void dumpcounters(struct trafcount *tlin, int counterd){
struct trafcount *tl;
if(counterd >= 0 && tlin) {
conf.time = time(0);
if(cheader.updated && conf.countertype && timechanged(cheader.updated, conf.time, conf.countertype)){
curtime = time(0);
if(cheader.updated && conf.countertype && timechanged(cheader.updated, curtime, conf.countertype)){
FILE * cfp;
cfp = fopen((char *)dologname(tmpbuf, (unsigned char *)conf.counterfile, NULL, conf.countertype, cheader.updated), "w");
@ -221,7 +221,7 @@ void dumpcounters(struct trafcount *tlin, int counterd){
}
cheader.updated = conf.time;
cheader.updated = curtime;
if(lseek(counterd, 0, SEEK_SET) >= 0 && write(counterd, &cheader, sizeof(struct counter_header))){}
for(tl=tlin; tl; tl = tl->next){
if(tl->number){
@ -234,8 +234,8 @@ void dumpcounters(struct trafcount *tlin, int counterd){
if(write(counterd, &crecord, sizeof(struct counter_record))){}
}
}
if(tl->type!=NEVER && timechanged(tl->cleared, conf.time, tl->type)){
tl->cleared = conf.time;
if(tl->type!=NEVER && timechanged(tl->cleared, curtime, tl->type)){
tl->cleared = curtime;
tl->traf64 = 0;
}
}
@ -284,15 +284,15 @@ void cyclestep(void){
for(;;){
usleep(SLEEPTIME*999);
conf.time = time(0);
if(conf.needreload) {
curtime = time(0);
if(needreload) {
doschedule();
reload();
conf.needreload = 0;
needreload = 0;
}
doschedule();
if(conf.stdlog)fflush(conf.stdlog);
if(timechanged(minutecounter, conf.time, MINUTELY)) {
if(timechanged(minutecounter, curtime, MINUTELY)) {
struct filemon *fm;
struct stat sb;
@ -300,14 +300,14 @@ void cyclestep(void){
if(!stat(fm->path, &sb)){
if(fm->sb.st_mtime != sb.st_mtime || fm->sb.st_size != sb.st_size){
stat(fm->path, &fm->sb);
conf.needreload = 1;
needreload = 1;
}
}
}
}
if(timechanged(basetime, conf.time, DAILY)) {
tm = localtime(&conf.time);
if(timechanged(basetime, curtime, DAILY)) {
tm = localtime(&curtime);
if(tm){
wday = (1 << tm->tm_wday);
tm->tm_hour = tm->tm_min = tm->tm_sec = 0;
@ -315,10 +315,10 @@ void cyclestep(void){
}
}
if(conf.logname) {
if(timechanged(conf.logtime, conf.time, conf.logtype)) {
if(conf.stdlog) conf.stdlog = freopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.time), "a", conf.stdlog);
else conf.stdlog = fopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.time), "a");
conf.logtime = conf.time;
if(timechanged(conf.logtime, curtime, conf.logtype)) {
if(conf.stdlog) conf.stdlog = freopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, curtime), "a", conf.stdlog);
else conf.stdlog = fopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, curtime), "a");
conf.logtime = curtime;
if(conf.logtype != NONE && conf.rotate) {
int t;
t = 1;
@ -364,11 +364,11 @@ void cyclestep(void){
}
}
if(conf.counterd >= 0 && conf.trafcounter) {
if(timechanged(cheader.updated, conf.time, MINUTELY)){
if(timechanged(cheader.updated, curtime, MINUTELY)){
dumpcounters(conf.trafcounter, conf.counterd);
}
}
if(conf.timetoexit){
if(timetoexit){
conf.paused++;
doschedule();
waitservices();

View File

@ -144,7 +144,7 @@ int doauth(struct clientparam * param){
ac.sinsl_family = *SAFAMILY(&param->sinsl);
memcpy(ac.sinsl_addr, SAADDR(&param->sinsl), SAADDRLEN(&param->sinsl));
}
hashadd(&auth_table, param, &ac, conf.time + param->srv->authcachetime);
hashadd(&auth_table, param, &ac, curtime + param->srv->authcachetime);
}
break;
}

View File

@ -200,6 +200,10 @@ char *rotations[] = {
};
/* State of the process, not configuration. */
time_t curtime;
int timetoexit = 0, needreload = 0;
int timeouts[12] = {
1, /* SINGLEBYTE_S */
5, /* SINGLEBYTE_L */
@ -250,8 +254,6 @@ struct extparam conf = {
.demon = 0,
.maxchild = DEFAULT_MAXCHILD,
.backlog = 0,
.needreload = 0,
.timetoexit = 0,
.version = 0,
.noforce = 0,
.bandlimver = 0,
@ -290,7 +292,6 @@ struct extparam conf = {
.stdlog = NULL,
.stringtable = NULL,
.logtime = (time_t)0,
.time = (time_t)0,
.logdumpsrv = 0,
.logdumpcli = 0,
.delimchar = '@',

View File

@ -2397,7 +2397,7 @@ void freeconf(struct extparam *confp){
confp->logformat = NULL;
confp->rotate = 0;
confp->logtype = NONE;
confp->logtime = confp->time = 0;
confp->logtime = curtime = 0;
confp->poolmax = -1;
confp->pooltimeout = 60;

View File

@ -100,10 +100,10 @@ static void hashcompact(struct hashtable *ht){
int i;
uint32_t he, *hep;
if((conf.time - ht->compacted) < 300 || !ht->tablesize || !ht->poolsize || ht->ihashempty) return;
if((curtime - ht->compacted) < 300 || !ht->tablesize || !ht->poolsize || ht->ihashempty) return;
for(i = 0; i < ht->tablesize; i++){
for(hep = ht->ihashtable + i; (he = *hep) != 0; ){
if(hvalue(ht,he)->expires < conf.time ) {
if(hvalue(ht,he)->expires < curtime ) {
(*hep) = hvalue(ht,he)->inext;
hvalue(ht,he)->expires = 0;
hvalue(ht,he)->inext = ht->ihashempty;
@ -112,7 +112,7 @@ static void hashcompact(struct hashtable *ht){
else hep=&(hvalue(ht,he)->inext);
}
}
ht->compacted = conf.time;
ht->compacted = curtime;
if(ht->ihashempty) return;
}
@ -180,7 +180,7 @@ void hashadd(struct hashtable *ht, void* name, void* value, time_t expires){
index = hashindex(ht, ht->tablesize, hash);
for(hep = ht->ihashtable + index; (he = *hep)!=0; ){
if(hvalue(ht,he)->expires < conf.time || !memcmp(hash, hhash(ht,he), ht->hash_size)) {
if(hvalue(ht,he)->expires < curtime || !memcmp(hash, hhash(ht,he), ht->hash_size)) {
(*hep) = hvalue(ht,he)->inext;
hvalue(ht,he)->expires = 0;
hvalue(ht,he)->inext = ht->ihashempty;
@ -228,14 +228,14 @@ int hashresolv(struct hashtable *ht, void* name, void* value, uint32_t *ttl){
_3proxy_mutex_lock(&ht->hash_mutex);
index = hashindex(ht, ht->tablesize, hash);
for(hep = ht->ihashtable + index; (he = *hep)!=0; ){
if(hvalue(ht, he)->expires < conf.time) {
if(hvalue(ht, he)->expires < curtime) {
(*hep) = hvalue(ht,he)->inext;
hvalue(ht,he)->expires = 0;
hvalue(ht,he)->inext = ht->ihashempty;
ht->ihashempty = he;
}
else if(!memcmp(hash, hhash(ht,he), ht->hash_size)){
if(ttl) *ttl = (uint32_t)(hvalue(ht,he)->expires - conf.time);
if(ttl) *ttl = (uint32_t)(hvalue(ht,he)->expires - curtime);
memcpy(value, hvalue(ht,he)->value, ht->recsize);
_3proxy_mutex_unlock(&ht->hash_mutex);
return 1;
@ -259,7 +259,7 @@ void hashdelete(struct hashtable *ht, void *name){
_3proxy_mutex_lock(&ht->hash_mutex);
index = hashindex(ht, ht->tablesize, hash);
for(hep = ht->ihashtable + index; (he = *hep) != 0; ){
if((hvalue(ht, he)->expires && hvalue(ht, he)->expires < conf.time) || !memcmp(hash, hhash(ht, he), ht->hash_size)) {
if((hvalue(ht, he)->expires && hvalue(ht, he)->expires < curtime) || !memcmp(hash, hhash(ht, he), ht->hash_size)) {
(*hep) = hvalue(ht, he)->inext;
hvalue(ht, he)->expires = 0;
hvalue(ht, he)->inext = ht->ihashempty;

View File

@ -27,9 +27,9 @@ int startconnlims (struct clientparam *param){
ce->rating++;
continue;
}
delta = conf.time - ce->basetime;
if(ce->period <= delta || ce->basetime > conf.time){
ce->basetime = conf.time;
delta = curtime - ce->basetime;
if(ce->period <= delta || ce->basetime > curtime){
ce->basetime = curtime;
ce->rating = 0x100000;
continue;
}
@ -39,7 +39,7 @@ int startconnlims (struct clientparam *param){
break;
}
ce->rating = rating;
ce->basetime = conf.time;
ce->basetime = curtime;
}
}
if(ret) {
@ -185,7 +185,7 @@ void trafcountfunc(struct clientparam *param){
continue;
}
tc->traf64 += param->statssrv64;
tc->updated = conf.time;
tc->updated = curtime;
}
}
if(countout) for(tc = conf.trafcounter; tc; tc = tc->next) {
@ -195,7 +195,7 @@ void trafcountfunc(struct clientparam *param){
continue;
}
tc->traf64 += param->statscli64;
tc->updated = conf.time;
tc->updated = curtime;
}
}

View File

@ -134,6 +134,7 @@ struct pluginlink pluginlink = {
parseusername,
parseconnusername,
&so,
dologname
dologname,
&needreload
};

View File

@ -131,7 +131,7 @@ int savecounters(void *v)
/*return 1 delete job , return 0 no delete job*/
if (mypluginlink->conf->needreload !=0 )
if ((*mypluginlink->needreload) !=0 )
{
return (0);
}

View File

@ -222,7 +222,8 @@ extern RESOLVFUNC resolvfunc;
extern int wday;
extern time_t basetime;
extern int timetoexit;
extern int timetoexit, needreload;
extern time_t curtime; /* the clock, kept by the main thread */
extern struct extparam conf;
@ -315,7 +316,6 @@ int socks5_udp_build_hdr(unsigned char *buf, PROXYSOCKADDRTYPE *addr);
extern struct auth authfuncs[];
int reload (void);
extern int paused;
extern int demon;
unsigned char * mycrypt(const unsigned char *key, const unsigned char *salt, unsigned char *buf);

View File

@ -165,7 +165,7 @@ static int poolpark(struct clientparam *param){
int timeout;
_3proxy_mutex_lock(&tpool.mutex);
if(conf.timetoexit || nsbroken() || tpool.nidle >= poollimit()){
if(timetoexit || nsbroken() || tpool.nidle >= poollimit()){
_3proxy_mutex_unlock(&tpool.mutex);
return 0;
}

View File

@ -183,7 +183,7 @@ uint32_t udpresolve(int af, unsigned char * name, unsigned char * value, uint32_
memcpy(value, buf + k + 12, af == AF_INET6? 16:4);
if(ttl < 0 || ttl > (3600*12)) ttl = 3600*12;
if(!ttl) ttl = 1;
hashadd(af == AF_INET6?&dns6_table:&dns_table, name, value, conf.time+ttl);
hashadd(af == AF_INET6?&dns6_table:&dns_table, name, value, curtime+ttl);
if(retttl) *retttl = ttl;
return 1;
}

View File

@ -15,7 +15,7 @@ int socksend(struct clientparam *param, SOCKET sock, unsigned char * buf, int bu
fds.fd = sock;
fds.events = POLLOUT;
do {
if(conf.timetoexit) return 0;
if(timetoexit) return 0;
/* try to send first; poll only when the socket would block */
res = param?param->srv->so._send(param->sostate, sock, (char *)buf + sent, bufsize - sent, 0) : so._send(so.state, sock, (char *)buf + sent, bufsize - sent, 0);
if(res > 0) {
@ -38,7 +38,7 @@ int socksendto(struct clientparam *param, SOCKET sock, struct sockaddr * sin, un
fds.fd = sock;
do {
if(conf.timetoexit) return 0;
if(timetoexit) return 0;
fds.events = POLLOUT;
res = param?param->srv->so._poll(param->sostate, &fds, 1, to):so._poll(so.state, &fds, 1, to);
if(res < 0 && (errno == EAGAIN || errno == EINTR)) continue;
@ -60,7 +60,7 @@ int sockrecvfrom(struct clientparam *param, SOCKET sock, struct sockaddr * sin,
fds.fd = sock;
fds.events = POLLIN;
if(conf.timetoexit) return EOF;
if(timetoexit) return EOF;
res = param?param->srv->so._poll(param->sostate, &fds, 1, to):so._poll(so.state, &fds, 1, to);
if (res<1) return 0;
sasize = sizeof(PROXYSOCKADDRTYPE);

View File

@ -225,8 +225,8 @@ log(logbuf);
#endif
if(needaction && param->srv->gracedelay && !sleeptime){
if(gracetime != conf.time){
gracetime = conf.time;
if(gracetime != curtime){
gracetime = curtime;
graceclinum=gracesrvnum=graceclitraf=gracesrvtraf=0;
}
else {

View File

@ -863,7 +863,7 @@ struct extparam {
struct srvparam *services;
int stacksize,
counterd, haveerror, rotate, paused, archiverc,
demon, maxchild, backlog, needreload, timetoexit, version, noforce, bandlimver, parentretries;
demon, maxchild, backlog, version, noforce, bandlimver, parentretries;
unsigned authcachetype, authcachetime;
int filtermaxsize;
int poolmax, pooltimeout; /* threadpool: idle workers kept, -1 automatic */
@ -889,7 +889,7 @@ struct extparam {
struct auth *authfuncs;
FILE *stdlog;
unsigned char **stringtable;
time_t logtime, time;
time_t logtime;
unsigned logdumpsrv, logdumpcli;
char delimchar;
struct nserver nservers[MAXNSERVERS], authnserver;
@ -1025,6 +1025,7 @@ struct pluginlink {
int (*parseconnusername)(char *username, struct clientparam *param, int extpasswd, uint16_t port);
struct sockfuncs *so;
unsigned char * (*dologname) (unsigned char *buf, unsigned char *name, const unsigned char *ext, ROTATION lt, time_t t);
int *needreload; /* state of the process rather than configuration */
};
struct counter_header {

View File

@ -491,7 +491,7 @@ int op_admin_reload(struct httpreq *r, const unsigned char *params)
if(r->param->srv->s_option) printstr(&pp, (char *)conf.stringtable[WEBBANNERS]);
else {
conf.needreload = 1;
needreload = 1;
printstr(&pp, "<h3>Reload scheduled</h3>");
}