VOIDSIG signal_rehash(int signum) { #ifdef POSIX_SIGNALS struct sigaction act; #endif #ifdef SIGHUP if (signum == SIGHUP) { #endif Dadmin *a; int i; alog(LOG_NORMAL, "Received SIGHUP: Saving Databases & Rehash Configuration"); if (initconf(denora->config, 1, mainconf) == -1) { denora->qmsg = calloc(50, 1); if (!denora->qmsg) { denora->qmsg = sstrdup(langstr(ALOG_ERR_REHASH_NO_MEM)); } else { ircsnprintf(denora->qmsg, sizeof(denora->qmsg), "%s", langstr(ALOG_ERR_REHASH)); } denora->quitting = 1; send_event(EVENT_SIGNAL, 2, "SIGHUP", denora->qmsg); } else { /* Remove all config file admins from admin struct before re-reading config file */ for (i = 0; i < 1024; i++) { for (a = adminlists[i]; a; a = a->next) { if (a->configfile) { free_admin(a); } break; } } merge_confs(); } /* Reload GeoIP db files */ if (gi) { GeoIP_delete(gi); } if (gi_v6) { GeoIP_delete(gi_v6); } gi = GeoIP_new(GEOIP_STANDARD); gi_v6 = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD); #ifdef POSIX_SIGNALS act.sa_handler = signal_rehash; act.sa_flags = 0; (void) sigemptyset(&act.sa_mask); (void) sigaddset(&act.sa_mask, SIGHUP); (void) sigaction(SIGHUP, &act, NULL); #else # ifndef _WIN32 (void) signal(SIGHUP, signal_rehash); /* sysV -argv */ # endif #endif #ifdef SIGHUP } #endif }
int initconf(char *filename) { int lnum = 0, blnum = 0, clear = 0; char line[LINE_MAX]; char *cur = NULL; char *tok; tConf *block = NULL; FILE *file; int including = 0; current_file = filename; if(!(file = fopen(filename, "r"))) { if(forked) sendto_realops("Unable to open config file %s", filename); else printf("Unable to open config file %s\n", filename); return -1; } while(!BadPtr(cur) || ((fgets(line, LINE_MAX, file) != NULL) && ++lnum && (cur = line))) { cur = check_quote(cur); if(BadPtr(cur)) continue; if (including) { if (including == 1) { jmp_including: if (*cur == '"' || *cur == '<') cur++; tok = cur; while (*cur && *cur != ' ' && *cur != '\t' && *cur != '"' && *cur != '>' && *cur != ';' && *cur != '\n') cur++; if (*cur == ';') including = 0; else including++; *cur++ = 0; if (!*tok) { confparse_error("Bad include filename", lnum); fclose(file); return -1; } /* parse new file */ if(initconf(tok) == -1) { current_file = filename; confparse_error("while processing include directive",lnum); fclose(file); return -1; } /* reset */ current_file = filename; cur = check_quote(cur); if (BadPtr(cur)) continue; } if (including == 2) { if (*cur != ';') { confparse_error("Missing semicolon", lnum); fclose(file); return -1; } including = 0; cur++; cur = check_quote(cur); if (BadPtr(cur)) continue; } } /* now, we should be ok to get that token.. */ if(!block) { tok = cur; while((*cur != ' ') && (*cur != '\n') && (*cur != '{')) cur++; /* find the whitespace following the token */ if(*cur == '{') clear = 1; *cur = '\0'; cur++; if (!mycmp("INCLUDE", tok)) { if(clear) { confparse_error("Unexpected opening bracket", lnum); fclose(file); return -1; } including++; cur = check_quote(cur); if (BadPtr(cur)) continue; goto jmp_including; /* XXX */ } for(block = tconftab; block->tok; block++) if(!mycmp(block->tok, tok)) break; if(!block->tok) { confparse_error("Unknown block type", lnum); fclose(file); return -1; } blnum = lnum; } cur = check_quote(cur); if(BadPtr(cur)) continue; if((*cur == '{') || clear) cur++; else { confparse_error("Junk after block name", lnum); fclose(file); return -1; } if((cur = parse_block(block, cur, file, &lnum)) == NULL) { fclose(file); return -1; } clear = 0; block = NULL; continue; } if(clear) { confparse_error("Unexpected EOF: Syntax error", blnum); fclose(file); return -1; } fclose(file); return 1; }
int main(){ int ieq,imeas,iskp; int i,j,readval,parity,val; double norm; extern void neighbours(); extern void neighchk(); extern double ran(); extern void clusteven(); extern void clustodd(); extern void chkconf(); extern void measureMAB(); extern void measureflux(int); extern void constflux(); extern void initconf(); extern double **allocatedouble2d(int,int); extern void deallocatedouble2d(double**,int,int); extern int **allocate2d(int,int); extern void deallocate2d(int**,int,int); FILE *fptr; char st[20]; /* read file */ fptr=fopen("QUEUE","r"); if(fptr == NULL) {printf("QUEUE error.\n"); exit(1);} readval = fscanf(fptr,"%s %d\n",st,&LX); if(readval == -1) printf("Error\n"); readval = fscanf(fptr,"%s %d\n",st,&LY); if(readval == -1) printf("Error\n"); readval = fscanf(fptr,"%s %d\n",st,<2); if(readval == -1) printf("Error\n"); readval = fscanf(fptr,"%s %d\n",st,&SEED); if(readval == -1) printf("Error\n"); readval = fscanf(fptr,"%s %d\n",st,&ieq); if(readval == -1) printf("Error\n"); readval = fscanf(fptr,"%s %d\n",st,&imeas); if(readval == -1) printf("Error\n"); readval = fscanf(fptr,"%s %lf\n",st,&beta); if(readval == -1) printf("Error\n"); readval = fscanf(fptr,"%s %lf\n",st,&J); if(readval == -1) printf("Error\n"); readval = fscanf(fptr,"%s %lf\n",st,&lam); if(readval == -1) printf("Error\n"); fclose(fptr); printf("Multi-Cluster Algorithm for the U(1) quantum link model\n"); printf("Nx=%d, Ny=%d, Nt=%d\n",LX,LY,LT2); printf("beta=%2.4f; J=%2.3f; lam=%2.3f\n",beta,J,lam); printf("Starting seed=%d\n",SEED); LT = 2*LT2; /* the dof are spread over twice actual length */ VOL = LX*LY*LT; SVOL= LX*LY/2; SPV = 2*SVOL; SIZE= 2*SVOL+1; VOL2= VOL/2; VOL4= VOL/4; minMA = minMB = -LX*LY/2; maxMA = maxMB = LX*LY/2; /* allocate memory */ ixc = (int *)malloc(VOL*sizeof(int)); iyc = (int *)malloc(VOL*sizeof(int)); itc = (int *)malloc(VOL*sizeof(int)); ising = (int *)malloc(VOL*sizeof(int)); list = (int *)malloc(VOL*sizeof(int)); avflx1= (double *)malloc(SPV*sizeof(double)); avfly1= (double *)malloc(SPV*sizeof(double)); avflx2= (double *)malloc(SPV*sizeof(double)); avfly2= (double *)malloc(SPV*sizeof(double)); chptr = (int *)malloc(VOL2*sizeof(double)); backt = (int *)malloc(LT*sizeof(double)); /* MA and MB will be measured for each of the LT/2 timeslices and avg-d */ MA = (int *)malloc((LT2)*sizeof(int)); MB = (int *)malloc((LT2)*sizeof(int)); pMAB = allocatedouble2d(SIZE,SIZE); refC = allocate2d(LX,LY); fx = allocate2d(LT,SPV); fy = allocate2d(LT,SPV); for(i=0;i<NNBR;i++) neigh[i] = (int *)malloc(VOL*sizeof(int)); for(i=0;i<2*DIM+1;i++) next[i] = (int *)malloc(VOL*sizeof(int)); /* Set parameters */ eps=1.0*beta/((double)LT); iskp=1; /* Initialize ranlux */ rlxd_init(1,SEED); /* initialize neighbours */ neighbours(); //neighchk(); /* Define the probabilities */ double x,coshx,sinhx; x = eps*J; coshx = (exp(x)+exp(-x))/2.0; sinhx = (exp(x)-exp(-x))/2.0; p1 = exp(-x)/coshx; p2 = 1.0 - exp(eps*lam)/coshx; printf("eps = %f\n",eps); printf("Prob p1: %f; Prob p2: %f\n",p1,p2); initconf(); chkconf(); /* initialize back-t pointers */ for(i=0;i<LT;i++) backt[i]=(i-1+LT)%LT; /* initialize the reference configuration */ for(i=0;i<LX;i++) for(j=0;j<LY;j++){ parity=(i+j)%2; val=(i-j)%4; if(parity==0){ /* for the even-time slices */ if(val==0) refC[i][j]=1; else refC[i][j]=-1; } else{ /* for the odd-time slices */ if((val==-1)||(val==3)) refC[i][j]=-1; else refC[i][j]=1; } } /* initialize average flux variable */ for(i=0;i<SPV;i++) avflx1[i]=avfly1[i]=avflx2[i]=avflx2[i]=0.0; /* update */ thermflag=1; for(i=0;i<ieq;i++){ nclusevn = 0; nclusevsq=0; mA=0; nclusodd = 0; nclusodsq=0; mB=0; clusteven(); clustodd(); chkconf(); } thermflag=0; /* measure */ flxcnt1=flxcnt2=0; for(i=0;i<SIZE;i++) for(j=0;j<SIZE;j++) pMAB[i][j]=0.0; fptr=fopen("multi.dat","w"); for(i=0;i<imeas;i++){ nclusevn = 0; nclusevsq=0; mA=0; nclusodd = 0; nclusodsq=0; mB=0; clusteven(); nclusevsq = nclusevsq/VOL4; clustodd(); nclusodsq = nclusodsq/VOL4; nclus = nclusevn + nclusodd; measureMAB(); //measureflux(); constflux(); chkconf(); fprintf(fptr,"%d %d %d %lf %lf %d %d\n",nclusevn,nclusodd,nclus,nclusevsq,nclusodsq,mA,mB); //fprintf(fptr,"%e %e %e %e %d %d\n",(double)mA,(double)mB,flx,fly,flt1,flt2); } fclose(fptr); /* normalize and print histogram */ norm=0.0; for(i=0;i<SIZE;i++) for(j=0;j<SIZE;j++) norm += pMAB[i][j]; fptr=fopen("magdist.dat","w"); for(i=0;i<SIZE;i++){ for(j=0;j<SIZE;j++){ pMAB[i][j] /= norm; fprintf(fptr,"%d %d %le\n",i,j,pMAB[i][j]);} fprintf(fptr,"\n");} fclose(fptr); /* average and normalize the flux profile and print it */ fptr=fopen("fprof.dat","w"); printf("# meas: %d + %d = %d\n",flxcnt1,flxcnt2,flxcnt1+flxcnt2); for(i=0;i<SPV;i++){ avflx1[i] /= (2.0*LT2*flxcnt1); avfly1[i] /= (2.0*LT2*flxcnt1); avflx2[i] /= (2.0*LT2*flxcnt2); avfly2[i] /= (2.0*LT2*flxcnt2); fprintf(fptr,"%d %.5f %.5f %.5f %.5f\n",i,avflx1[i],avfly1[i],avflx2[i],avfly2[i]); } fclose(fptr); /* free memory */ free(ixc); free(iyc); free(itc); free(MA); free(MB); free(avflx1); free(avfly1); free(avflx2); free(avfly2); free(chptr); free(backt); for(i=0;i<NNBR;i++) free(neigh[i]); for(i=0;i<2*DIM+1;i++) free(next[i]); deallocatedouble2d(pMAB,SIZE,SIZE); deallocate2d(refC,LX,LY); deallocate2d(fx,LT,SPV); deallocate2d(fy,LT,SPV); return 0; }
int main(int argc, char *argv[]) { uid_t uid, euid; int portarg = 0, fd; #ifdef SAVE_MAXCLIENT_STATS FILE *mcsfp; #endif memset(&me, 0, sizeof(aClient)); if ((timeofday = time(NULL)) == -1) { (void) fprintf(stderr, "ERROR: Clock Failure (%d)\n", errno); exit(errno); } build_version(); Count.server = 1; /* us */ Count.oper = 0; Count.chan = 0; Count.local = 0; Count.total = 0; Count.invisi = 0; Count.unknown = 0; Count.max_loc = 0; Count.max_tot = 0; Count.today = 0; Count.weekly = 0; Count.monthly = 0; Count.yearly = 0; Count.start = NOW; Count.day = NOW; Count.week = NOW; Count.month = NOW; Count.year = NOW; #ifdef SAVE_MAXCLIENT_STATS mcsfp=fopen(DPATH "/.maxclients", "r"); if(mcsfp!=NULL) { fscanf(mcsfp, "%d %d %li %li %li %ld %ld %ld %ld", &Count.max_loc, &Count.max_tot, &Count.weekly, &Count.monthly, &Count.yearly, &Count.start, &Count.week, &Count.month, &Count.year); fclose(mcsfp); } #endif /* * this code by [email protected] * it is intended to keep the ircd from being swapped out. BSD * swapping criteria do not match the requirements of ircd */ #ifdef INITIAL_DBUFS dbuf_init(); /* set up some dbuf stuff to control paging */ #endif sbrk0 = (char *) sbrk((size_t) 0); uid = getuid(); euid = geteuid(); #ifdef PROFIL (void) monstartup(0, etext); (void) moncontrol(1); (void) signal(SIGUSR1, s_monitor); #endif myargv = argv; (void) umask(077); /* better safe than sorry --SRB */ memset((char *) &me, '\0', sizeof(me)); setup_signals(); /* * * All command line parameters have the syntax "-fstring" or "-f * string" (e.g. the space is optional). String may be empty. Flag * characters cannot be concatenated (like "-fxyz"), it would * conflict with the form "-fstring". */ while (--argc > 0 && (*++argv)[0] == '-') { char *p = argv[0] + 1; int flag = *p++; if (flag == '\0' || *p == '\0') { if (argc > 1 && argv[1][0] != '-') { p = *++argv; argc -= 1; } else p = ""; } switch (flag) { case 'a': bootopt |= BOOT_AUTODIE; break; case 'c': bootopt |= BOOT_CONSOLE; break; case 'q': bootopt |= BOOT_QUICK; break; case 'd': (void) setuid((uid_t) uid); dpath = p; break; case 'o': /* Per user local daemon... */ (void) setuid((uid_t) uid); bootopt |= BOOT_OPER; break; #ifdef CMDLINE_CONFIG case 'f': (void) setuid((uid_t) uid); configfile = p; break; # ifdef KPATH case 'k': (void) setuid((uid_t) uid); klinefile = p; break; # endif #endif case 'h': strncpyzt(me.name, p, sizeof(me.name)); break; case 'i': bootopt |= BOOT_INETD | BOOT_AUTODIE; break; case 'p': if ((portarg = atoi(p)) > 0) portnum = portarg; break; case 's': bootopt |= BOOT_STDERR; break; case 't': (void) setuid((uid_t) uid); bootopt |= BOOT_TTY; break; case 'v': (void) printf("ircd %s\n", version); exit(0); case 'x': #ifdef DEBUGMODE (void) setuid((uid_t) uid); debuglevel = atoi(p); debugmode = *p ? p : "0"; bootopt |= BOOT_DEBUG; break; #else (void) fprintf(stderr, "%s: DEBUGMODE must be defined for -x y\n", myargv[0]); exit(0); #endif default: bad_command(); break; } } if (chdir(dpath)) { perror("chdir"); exit(-1); } if ((uid != euid) && !euid) { (void) fprintf(stderr, "ERROR: do not run ircd setuid root. Make it setuid a normal user.\n"); exit(-1); } if (argc > 0) return bad_command(); /* This should exit out */ initialize_ssl(); motd = (aMotd *) NULL; helpfile = (aMotd *) NULL; motd_tm = NULL; #ifdef SHORT_MOTD shortmotd = NULL; #endif read_motd(MOTD); read_help(HELPFILE); #ifdef SHORT_MOTD read_shortmotd(SHORTMOTD); #endif clear_client_hash_table(); clear_channel_hash_table(); clear_scache_hash_table(); /* server cache name table */ clear_ip_hash_table(); /* client host ip hash table */ initlists(); initclass(); initwhowas(); initstats(); init_tree_parse(msgtab); init_send(); NOW = time(NULL); open_debugfile(); NOW = time(NULL); init_fdlist(&serv_fdlist); init_fdlist(&oper_fdlist); init_fdlist(&listen_fdlist); #ifndef NO_PRIORITY init_fdlist(&busycli_fdlist); #endif init_fdlist(&default_fdlist); { int i; for (i = MAXCONNECTIONS + 1; i > 0; i--) { default_fdlist.entry[i] = i - 1; } } if ((timeofday = time(NULL)) == -1) { #ifdef USE_SYSLOG syslog(LOG_WARNING, "Clock Failure (%d), TS can be corrupted", errno); #endif sendto_ops("Clock Failure (%d), TS can be corrupted", errno); } #ifdef WINGATE_NOTICE strcpy(ProxyMonURL, "http://"); strncpyzt((ProxyMonURL + 7), DEFAULT_PROXY_INFO_URL, (TOPICLEN + 1) - 7); strncpyzt(ProxyMonHost, MONITOR_HOST, (HOSTLEN + 1)); #endif if (portnum < 0) portnum = PORTNUM; me.port = portnum; (void) init_sys(); me.flags = FLAGS_LISTEN; #ifndef _WIN32 if (bootopt & BOOT_INETD) { me.fd = 0; local[0] = &me; me.flags = FLAGS_LISTEN; } else #endif me.fd = -1; #ifdef USE_SYSLOG # define SYSLOG_ME "ircd" openlog(SYSLOG_ME, LOG_PID | LOG_NDELAY, LOG_FACILITY); #endif if ((fd = openconf(configfile)) == -1) { Debug((DEBUG_FATAL, "Failed in reading configuration file %s", configfile)); (void) printf("Couldn't open configuration file %s\n", configfile); exit(-1); } (void) initconf(bootopt, fd); /* comstuds SEPARATE_QUOTE_KLINES_BY_DATE code */ #ifdef SEPARATE_QUOTE_KLINES_BY_DATE { struct tm *tmptr; char timebuffer[20], filename[200]; tmptr = localtime(&NOW); (void) strftime(timebuffer, 20, "%y%m%d", tmptr); ircsprintf(filename, "%s.%s", klinefile, timebuffer); if ((fd = openconf(filename)) == -1) { Debug((DEBUG_ERROR, "Failed reading kline file %s", filename)); (void) printf("Couldn't open kline file %s\n", filename); } else (void) initconf(0, fd); } #else # ifdef KPATH if ((fd = openconf(klinefile)) == -1) { Debug((DEBUG_ERROR, "Failed reading kline file %s", klinefile)); (void) printf("Couldn't open kline file %s\n", klinefile); } else (void) initconf(0, fd); # endif #endif if (!(bootopt & BOOT_INETD)) { static char star[] = "*"; aConfItem *aconf; u_long vaddr; if ((aconf = find_me()) && portarg <= 0 && aconf->port > 0) portnum = aconf->port; Debug((DEBUG_ERROR, "Port = %d", portnum)); if ((aconf->passwd[0] != '\0') && (aconf->passwd[0] != '*')) vaddr = inet_addr(aconf->passwd); else vaddr = (u_long) NULL; if (inetport(&me, star, portnum, vaddr)) { if (bootopt & BOOT_STDERR) fprintf(stderr, "Couldn't bind to primary port %d\n", portnum); #ifdef USE_SYSLOG (void) syslog(LOG_CRIT, "Couldn't bind to primary port %d\n", portnum); #endif exit(1); } } else if (inetport(&me, "*", 0, 0)) { if (bootopt & BOOT_STDERR) fprintf(stderr, "Couldn't bind to port passed from inetd\n"); #ifdef USE_SYSLOG (void) syslog(LOG_CRIT, "Couldn't bind to port passed from inetd\n"); #endif exit(1); } (void) get_my_name(&me, me.sockhost, sizeof(me.sockhost) - 1); if (me.name[0] == '\0') strncpyzt(me.name, me.sockhost, sizeof(me.name)); me.hopcount = 0; me.authfd = -1; me.confs = NULL; me.next = NULL; me.user = NULL; me.from = &me; SetMe(&me); make_server(&me); me.serv->up = me.name; me.lasttime = me.since = me.firsttime = NOW; (void) add_to_client_hash_table(me.name, &me); /* We don't want to calculate these every time they are used :) */ sprintf(REPORT_DO_DNS, REPORT_DO_DNS_, me.name); sprintf(REPORT_FIN_DNS, REPORT_FIN_DNS_, me.name); sprintf(REPORT_FIN_DNSC, REPORT_FIN_DNSC_, me.name); sprintf(REPORT_FAIL_DNS, REPORT_FAIL_DNS_, me.name); sprintf(REPORT_DO_ID, REPORT_DO_ID_, me.name); sprintf(REPORT_FIN_ID, REPORT_FIN_ID_, me.name); sprintf(REPORT_FAIL_ID, REPORT_FAIL_ID_, me.name); R_do_dns = strlen(REPORT_DO_DNS); R_fin_dns = strlen(REPORT_FIN_DNS); R_fin_dnsc = strlen(REPORT_FIN_DNSC); R_fail_dns = strlen(REPORT_FAIL_DNS); R_do_id = strlen(REPORT_DO_ID); R_fin_id = strlen(REPORT_FIN_ID); R_fail_id = strlen(REPORT_FAIL_ID); check_class(); if (bootopt & BOOT_OPER) { aClient *tmp = add_connection(&me, 0); if (!tmp) exit(1); SetMaster(tmp); } else write_pidfile(); Debug((DEBUG_NOTICE, "Server ready...")); #ifdef USE_SYSLOG syslog(LOG_NOTICE, "Server Ready"); #endif NOW = time(NULL); #ifndef NO_PRIORITY check_fdlists(); #endif if ((timeofday = time(NULL)) == -1) { #ifdef USE_SYSLOG syslog(LOG_WARNING, "Clock Failure (%d), TS can be corrupted", errno); #endif sendto_ops("Clock Failure (%d), TS can be corrupted", errno); } #ifdef DUMP_DEBUG dumpfp=fopen("dump.log", "w"); #endif io_loop(); return 0; }